/**
  * Add new CategoryEntry
  * 
  * @action add
  * @param KalturaCategoryEntry $categoryEntry
  * @throws KalturaErrors::INVALID_ENTRY_ID
  * @throws KalturaErrors::CATEGORY_NOT_FOUND
  * @throws KalturaErrors::CANNOT_ASSIGN_ENTRY_TO_CATEGORY
  * @throws KalturaErrors::CATEGORY_ENTRY_ALREADY_EXISTS
  * @return KalturaCategoryEntry
  */
 function addAction(KalturaCategoryEntry $categoryEntry)
 {
     $categoryEntry->validateForInsert();
     $entry = entryPeer::retrieveByPK($categoryEntry->entryId);
     if (!$entry) {
         throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_ID, $categoryEntry->entryId);
     }
     $category = categoryPeer::retrieveByPK($categoryEntry->categoryId);
     if (!$category) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $categoryEntry->categoryId);
     }
     $categoryEntries = categoryEntryPeer::retrieveActiveAndPendingByEntryId($categoryEntry->entryId);
     if (count($categoryEntries) >= entry::MAX_CATEGORIES_PER_ENTRY) {
         throw new KalturaAPIException(KalturaErrors::MAX_CATEGORIES_FOR_ENTRY_REACHED, entry::MAX_CATEGORIES_PER_ENTRY);
     }
     //validate user is entiteld to assign entry to this category
     if (kEntitlementUtils::getEntitlementEnforcement() && $category->getContributionPolicy() != ContributionPolicyType::ALL) {
         $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndActiveKuserId($categoryEntry->categoryId, kCurrentContext::$ks_kuser_id);
         if (!$categoryKuser || $categoryKuser->getPermissionLevel() == CategoryKuserPermissionLevel::MEMBER) {
             throw new KalturaAPIException(KalturaErrors::CANNOT_ASSIGN_ENTRY_TO_CATEGORY);
         }
         if ($categoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MANAGER && $entry->getKuserId() != kCurrentContext::$ks_kuser_id && $entry->getCreatorKuserId() != kCurrentContext::$ks_kuser_id) {
             throw new KalturaAPIException(KalturaErrors::CANNOT_ASSIGN_ENTRY_TO_CATEGORY);
         }
     }
     $categoryEntryExists = categoryEntryPeer::retrieveByCategoryIdAndEntryId($categoryEntry->categoryId, $categoryEntry->entryId);
     if ($categoryEntryExists && $categoryEntryExists->getStatus() == CategoryEntryStatus::ACTIVE) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_ENTRY_ALREADY_EXISTS);
     }
     if (!$categoryEntryExists) {
         $dbCategoryEntry = new categoryEntry();
     } else {
         $dbCategoryEntry = $categoryEntryExists;
     }
     $categoryEntry->toInsertableObject($dbCategoryEntry);
     $dbCategoryEntry->setStatus(CategoryEntryStatus::ACTIVE);
     if (kEntitlementUtils::getEntitlementEnforcement() && $category->getModeration()) {
         $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndActiveKuserId($categoryEntry->categoryId, kCurrentContext::$ks_kuser_id);
         if (!$categoryKuser || $categoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MANAGER && $categoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MODERATOR) {
             $dbCategoryEntry->setStatus(CategoryEntryStatus::PENDING);
         }
     }
     $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
     $dbCategoryEntry->setPartnerId($partnerId);
     $dbCategoryEntry->save();
     //need to select the entry again - after update
     $entry = entryPeer::retrieveByPK($categoryEntry->entryId);
     myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_UPDATE, $entry);
     $categoryEntry = new KalturaCategoryEntry();
     $categoryEntry->fromObject($dbCategoryEntry);
     return $categoryEntry;
 }
Пример #2
0
 public function getAllCategoriesIds($includePending = false)
 {
     if (!$includePending) {
         $categoriesEntry = categoryEntryPeer::retrieveActiveByEntryId($this->getId());
     } else {
         $categoriesEntry = categoryEntryPeer::retrieveActiveAndPendingByEntryId($this->getId());
     }
     $categoriesIds = array();
     foreach ($categoriesEntry as $categoryEntry) {
         $categoriesIds[] = $categoryEntry->getCategoryId();
     }
     return $categoriesIds;
 }
Пример #3
0
 /**
  * Add new CategoryEntry
  * 
  * @action add
  * @param KalturaCategoryEntry $categoryEntry
  * @throws KalturaErrors::INVALID_ENTRY_ID
  * @throws KalturaErrors::CATEGORY_NOT_FOUND
  * @throws KalturaErrors::CANNOT_ASSIGN_ENTRY_TO_CATEGORY
  * @throws KalturaErrors::CATEGORY_ENTRY_ALREADY_EXISTS
  * @return KalturaCategoryEntry
  */
 function addAction(KalturaCategoryEntry $categoryEntry)
 {
     $categoryEntry->validateForInsert();
     $entry = entryPeer::retrieveByPK($categoryEntry->entryId);
     if (!$entry) {
         throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_ID, $categoryEntry->entryId);
     }
     $category = categoryPeer::retrieveByPK($categoryEntry->categoryId);
     if (!$category) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $categoryEntry->categoryId);
     }
     $categoryEntries = categoryEntryPeer::retrieveActiveAndPendingByEntryId($categoryEntry->entryId);
     $maxCategoriesPerEntry = $entry->getMaxCategoriesPerEntry();
     if (count($categoryEntries) >= $maxCategoriesPerEntry) {
         throw new KalturaAPIException(KalturaErrors::MAX_CATEGORIES_FOR_ENTRY_REACHED, $maxCategoriesPerEntry);
     }
     //validate user is entiteld to assign entry to this category
     if (kEntitlementUtils::getEntitlementEnforcement() && $category->getContributionPolicy() != ContributionPolicyType::ALL) {
         $categoryKuser = categoryKuserPeer::retrievePermittedKuserInCategory($categoryEntry->categoryId, kCurrentContext::getCurrentKsKuserId());
         if (!$categoryKuser) {
             KalturaLog::err("User [" . kCurrentContext::getCurrentKsKuserId() . "] is not a member of the category [{$categoryEntry->categoryId}]");
             throw new KalturaAPIException(KalturaErrors::CANNOT_ASSIGN_ENTRY_TO_CATEGORY);
         }
         if ($categoryKuser->getPermissionLevel() == CategoryKuserPermissionLevel::MEMBER) {
             KalturaLog::err("User [" . kCurrentContext::getCurrentKsKuserId() . "] permission level [" . $categoryKuser->getPermissionLevel() . "] on category [{$categoryEntry->categoryId}] is not member [" . CategoryKuserPermissionLevel::MEMBER . "]");
             throw new KalturaAPIException(KalturaErrors::CANNOT_ASSIGN_ENTRY_TO_CATEGORY);
         }
         if (!$categoryKuser->hasPermission(PermissionName::CATEGORY_EDIT) && !$categoryKuser->hasPermission(PermissionName::CATEGORY_CONTRIBUTE) && $entry->getKuserId() != kCurrentContext::getCurrentKsKuserId() && $entry->getCreatorKuserId() != kCurrentContext::getCurrentKsKuserId()) {
             throw new KalturaAPIException(KalturaErrors::CANNOT_ASSIGN_ENTRY_TO_CATEGORY);
         }
     }
     $categoryEntryExists = categoryEntryPeer::retrieveByCategoryIdAndEntryId($categoryEntry->categoryId, $categoryEntry->entryId);
     if ($categoryEntryExists && $categoryEntryExists->getStatus() == CategoryEntryStatus::ACTIVE) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_ENTRY_ALREADY_EXISTS);
     }
     if (!$categoryEntryExists) {
         $dbCategoryEntry = new categoryEntry();
     } else {
         $dbCategoryEntry = $categoryEntryExists;
     }
     $categoryEntry->toInsertableObject($dbCategoryEntry);
     $dbCategoryEntry->setStatus(CategoryEntryStatus::ACTIVE);
     if (kEntitlementUtils::getEntitlementEnforcement() && $category->getModeration()) {
         $categoryKuser = categoryKuserPeer::retrievePermittedKuserInCategory($categoryEntry->categoryId, kCurrentContext::getCurrentKsKuserId());
         if (!$categoryKuser || $categoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MANAGER && $categoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MODERATOR) {
             $dbCategoryEntry->setStatus(CategoryEntryStatus::PENDING);
         }
     }
     if (kEntitlementUtils::getCategoryModeration() && $category->getModeration()) {
         $dbCategoryEntry->setStatus(CategoryEntryStatus::PENDING);
     }
     $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
     $dbCategoryEntry->setPartnerId($partnerId);
     $dbCategoryEntry->save();
     //need to select the entry again - after update
     $entry = entryPeer::retrieveByPK($categoryEntry->entryId);
     myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_UPDATE, $entry);
     $categoryEntry = new KalturaCategoryEntry();
     $categoryEntry->fromObject($dbCategoryEntry, $this->getResponseProfile());
     return $categoryEntry;
 }
 /**
  * Returns true if kuser or current kuser is entitled to entryId
  * @param entry $entry
  * @param int $kuser
  * @return bool
  */
 public static function isEntryEntitled(entry $entry, $kuserId = null)
 {
     $ks = ks::fromSecureString(kCurrentContext::$ks);
     // entry is entitled when entitlement is disable
     // for actions with no ks - need to check if partner have default entitlement feature enable.
     if (!self::getEntitlementEnforcement() && $ks) {
         KalturaLog::debug('Entry entitled: entitlement disabled');
         return true;
     }
     $partner = $entry->getPartner();
     if (!$ks && !$partner->getDefaultEntitlementEnforcement()) {
         KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: no ks and default is with no enforcement');
         return true;
     }
     if ($ks && $ks->isWidgetSession() && $ks->getDisableEntitlementForEntry() == $entry->getId()) {
         KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: widget session that disble entitlement for this entry');
         return true;
     }
     $allCategoriesEntry = categoryEntryPeer::retrieveActiveAndPendingByEntryId($entry->getId());
     $categories = array();
     foreach ($allCategoriesEntry as $categoryEntry) {
         $categories[] = $categoryEntry->getCategoryId();
     }
     //if entry doesn't belong to any category.
     $categories[] = category::CATEGORY_ID_THAT_DOES_NOT_EXIST;
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $c->add(categoryPeer::ID, $categories, Criteria::IN);
     $privacy = array(PrivacyType::ALL);
     if ($ks && !$ks->isWidgetSession()) {
         $privacy[] = PrivacyType::AUTHENTICATED_USERS;
     }
     $crit = $c->getNewCriterion(categoryPeer::PRIVACY, $privacy, Criteria::IN);
     $ksPrivacyContexts = null;
     // entry that doesn't belong to any category is public
     //when ks is not provided - the entry is still public (for example - download action)
     $categoryEntries = categoryEntryPeer::retrieveActiveByEntryId($entry->getId());
     if (!count($categoryEntries) && !$ks) {
         KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: entry does not belong to any category');
         return true;
     }
     if ($ks) {
         $ksPrivacyContexts = $ks->getPrivacyContext();
         if (!$ksPrivacyContexts || trim($ksPrivacyContexts) == '') {
             $ksPrivacyContexts = self::DEFAULT_CONTEXT . $partner->getId();
             if (!count($allCategoriesEntry)) {
                 // entry that doesn't belong to any category is public
                 KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: entry does not belong to any category and privacy context on the ks is not set');
                 return true;
             }
         }
         $c->add(categoryPeer::PRIVACY_CONTEXTS, $ksPrivacyContexts, KalturaCriteria::IN_LIKE);
         if (!$kuserId) {
             $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
             $kuser = kuserPeer::getKuserByPartnerAndUid($partnerId, kCurrentContext::$ks_uid, true);
             if ($kuser) {
                 $kuserId = $kuser->getId();
             }
         }
         if ($kuserId) {
             // kuser is set on the entry as creator or uploader
             if ($kuserId != '' && $entry->getKuserId() == $kuserId) {
                 KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: ks user is the same as entry->kuserId or entry->creatorKuserId [' . $kuserId . ']');
                 return true;
             }
             // kuser is set on the entry entitled users edit or publish
             $entitledKusers = array_merge(explode(',', $entry->getEntitledKusersEdit()), explode(',', $entry->getEntitledKusersPublish()));
             if (in_array($kuserId, $entitledKusers)) {
                 KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: ks user is the same as entry->entitledKusersEdit or entry->entitledKusersPublish');
                 return true;
             }
         }
         // kuser is set on the category as member
         // this ugly code is temporery - since we have a bug in sphinxCriteria::getAllCriterionFields
         if ($kuserId) {
             $membersCrit = $c->getNewCriterion(categoryPeer::MEMBERS, $kuserId, Criteria::LIKE);
             $membersCrit->addOr($crit);
             $crit = $membersCrit;
         }
     } else {
         //no ks = set privacy context to default.
         $c->add(categoryPeer::PRIVACY_CONTEXTS, array(self::DEFAULT_CONTEXT . $partner->getId()), KalturaCriteria::IN_LIKE);
     }
     $c->addAnd($crit);
     //remove default FORCED criteria since categories that has display in search = public - doesn't mean that all of their entries are public
     KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     $category = categoryPeer::doSelectOne($c);
     KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     if ($category) {
         KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: ks user is a member of this category or category privacy is set to public of authenticated');
         return true;
     }
     KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] not entitled');
     return false;
 }
Пример #5
0
 /**
  * Returns true if kuser or current kuser is entitled to entryId
  * @param entry $entry
  * @param int $kuser
  * @return bool
  */
 public static function isEntryEntitled(entry $entry, $kuserId = null)
 {
     if ($entry->getParentEntryId()) {
         $entry = $entry->getParentEntry();
         if (!$entry) {
             KalturaLog::debug('Parent entry not found, cannot validate entitlement');
             return false;
         }
     }
     $ks = ks::fromSecureString(kCurrentContext::$ks);
     if (self::$entitlementForced === false) {
         KalturaLog::debug('Entitlement forced to be disabled');
         return true;
     }
     // entry is entitled when entitlement is disable
     // for actions with no ks - need to check if partner have default entitlement feature enable.
     if (!self::getEntitlementEnforcement() && $ks) {
         KalturaLog::debug('Entry entitled: entitlement disabled');
         return true;
     }
     $partner = $entry->getPartner();
     if (!$ks && !$partner->getDefaultEntitlementEnforcement()) {
         KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: no ks and default is with no enforcement');
         return true;
     }
     if ($ks && in_array($entry->getId(), $ks->getDisableEntitlementForEntry())) {
         KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: ks disble entitlement for this entry');
         return true;
     }
     $kuserId = self::getKuserIdForEntitlement($kuserId, $ks);
     if ($ks && $kuserId) {
         // kuser is set on the entry as creator or uploader
         if ($kuserId != '' && $entry->getKuserId() == $kuserId) {
             KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: ks user is the same as entry->kuserId or entry->creatorKuserId [' . $kuserId . ']');
             return true;
         }
         // kuser is set on the entry entitled users edit or publish
         $entitledKusers = array_merge(explode(',', $entry->getEntitledKusersEdit()), explode(',', $entry->getEntitledKusersPublish()));
         if (in_array($kuserId, $entitledKusers)) {
             KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: ks user is the same as entry->entitledKusersEdit or entry->entitledKusersPublish');
             return true;
         }
     }
     if (!$ks) {
         // entry that doesn't belong to any category is public
         //when ks is not provided - the entry is still public (for example - download action)
         $categoryEntry = categoryEntryPeer::retrieveOneActiveByEntryId($entry->getId());
         if (!$categoryEntry) {
             KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: entry does not belong to any category');
             return true;
         }
     }
     $ksPrivacyContexts = null;
     if ($ks) {
         $ksPrivacyContexts = $ks->getPrivacyContext();
     }
     $allCategoriesEntry = array();
     if (PermissionPeer::isValidForPartner(PermissionName::FEATURE_DISABLE_CATEGORY_LIMIT, $partner->getId())) {
         if (!$ksPrivacyContexts || trim($ksPrivacyContexts) == '') {
             $categoryEntry = categoryEntryPeer::retrieveOneByEntryIdStatusPrivacyContextExistance($entry->getId(), array(CategoryEntryStatus::PENDING, CategoryEntryStatus::ACTIVE));
             if ($categoryEntry) {
                 KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: entry belongs to public category and privacy context on the ks is not set');
                 return true;
             }
         } else {
             $allCategoriesEntry = categoryEntryPeer::retrieveActiveAndPendingByEntryIdAndPrivacyContext($entry->getId(), $ksPrivacyContexts);
         }
     } else {
         $allCategoriesEntry = categoryEntryPeer::retrieveActiveAndPendingByEntryId($entry->getId());
         if ($ks && (!$ksPrivacyContexts || trim($ksPrivacyContexts) == '') && !count($allCategoriesEntry)) {
             // entry that doesn't belong to any category is public
             KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: entry does not belong to any category and privacy context on the ks is not set');
             return true;
         }
     }
     return self::isMemberOfCategory($allCategoriesEntry, $entry, $partner, $kuserId, $ks, $ksPrivacyContexts);
 }