New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No Plat: Correctly validate objectId is filtered when calling metadata list #6269

Merged
merged 6 commits into from Nov 2, 2017
Next

No Plat: Correctly validate objectId is filtered when callign metadat…

…a list
  • Loading branch information...
yossipapi committed Nov 1, 2017
commit 299575af596678c69133ab9128c53f6dfab871d7
@@ -35,78 +35,14 @@ protected function getCoreFilter()
return new MetadataFilter();
}
/* (non-PHPdoc)
* @see KalturaObject::toObject()
*/
public function toObject($object_to_fill = null, $props_to_skip = array())
{
if($this->metadataObjectTypeEqual == KalturaMetadataObjectType::USER)
{
if ($this->objectIdEqual)
{
$kuser = kuserPeer::getKuserByPartnerAndUid(kCurrentContext::getCurrentPartnerId(), $this->objectIdEqual);
if($kuser)
$this->objectIdEqual = $kuser->getId();
}
if ($this->objectIdIn)
{
$kusers = kuserPeer::getKuserByPartnerAndUids(kCurrentContext::getCurrentPartnerId(), explode(',', $this->objectIdIn));
$kusersIds = array();
foreach($kusers as $kuser)
$kusersIds[] = $kuser->getId();
$this->objectIdIn = implode(',', $kusersIds);
}
}
return parent::toObject($object_to_fill, $props_to_skip);
}
/* (non-PHPdoc)
* @see KalturaRelatedFilter::getListResponse()
*/
public function getListResponse(KalturaFilterPager $pager, KalturaDetachedResponseProfile $responseProfile = null)
{
if (kEntitlementUtils::getEntitlementEnforcement() && (is_null($this->objectIdIn) && is_null($this->objectIdEqual))&& kConf::hasParam('metadata_list_without_object_filtering_partners') &&
!in_array(kCurrentContext::getCurrentPartnerId(), kConf::get('metadata_list_without_object_filtering_partners')))
throw new KalturaAPIException(MetadataErrors::MUST_FILTER_ON_OBJECT_ID);
if (!$this->metadataObjectTypeEqual)
throw new KalturaAPIException(MetadataErrors::MUST_FILTER_ON_OBJECT_TYPE);
if ($this->metadataObjectTypeEqual == MetadataObjectType::CATEGORY)
{
if ($this->objectIdEqual)
{
$categoryIds = array($this->objectIdEqual);
}
else if ($this->objectIdIn)
{
$categoryIds = explode(',', $this->objectIdIn);
}
if($categoryIds)
{
$categories = categoryPeer::retrieveByPKs($categoryIds);
if(!count($categories))
{
$response = new KalturaMetadataListResponse();
$response->objects = new KalturaMetadataArray();
$response->totalCount = 0;
return $response;
}
$categoryIds = array();
foreach($categories as $category)
$categoryIds[] = $category->getId();
$this->objectIdEqual = null;
$this->objectIdIn = implode(',', $categoryIds);
}
}
$metadataFilter = $this->toObject();
$c = KalturaCriteria::create(MetadataPeer::OM_CLASS);
@@ -370,49 +370,57 @@ function listAction(KalturaMetadataFilter $filter = null, KalturaFilterPager $pa
if (! $pager)
$pager = new KalturaFilterPager ();
$applyPartnerFilter = true;
if ($filter->metadataObjectTypeEqual == MetadataObjectType::ENTRY)
$objectIds = $this->validateObjectIdFiltered($filter);
if(!count($objectIds))
{
$entryIds = null;
if ($filter->objectIdEqual)
{
$entryIds = array($filter->objectIdEqual);
}
else if ($filter->objectIdIn)
{
$entryIds = explode(',', $filter->objectIdIn);
}
if (!$entryIds && kConf::hasParam('metadata_list_without_object_filtering_partners') &&
!in_array(kCurrentContext::getCurrentPartnerId(), kConf::get('metadata_list_without_object_filtering_partners')) &&
kCurrentContext::$ks_partner_id != Partner::BATCH_PARTNER_ID)
throw new KalturaAPIException(MetadataErrors::MUST_FILTER_ON_OBJECT_ID);
if($entryIds)
{
$entryIds = entryPeer::filterEntriesByPartnerOrKalturaNetwork($entryIds, kCurrentContext::getCurrentPartnerId());
if(!count($entryIds))
{
$response = new KalturaMetadataListResponse();
$response->objects = new KalturaMetadataArray();
$response->totalCount = 0;
return $response;
}
$filter->objectIdEqual = null;
$filter->objectIdIn = implode(',', $entryIds);
$applyPartnerFilter = false;
}
$response = new KalturaMetadataListResponse();
$response->objects = new KalturaMetadataArray();
$response->totalCount = 0;
return $response;
}
if ($applyPartnerFilter)
$this->applyPartnerFilterForClass('Metadata');
$this->objectIdEqual = null;
$this->objectIdIn = implode(',', $objectIds);
return $filter->getListResponse($pager, $this->getResponseProfile());
}
private function validateObjectIdFiltered(KalturaMetadataFilter $filter)
{
$objectIds = null;
if ($this->objectIdEqual)
{
$objectIds = array($this->objectIdEqual);
}
else if ($this->objectIdIn)
{
$objectIds = explode(',', $this->objectIdIn);
}
if(!$objectIds && kConf::hasParam('metadata_list_without_object_filtering_partners') &&
!in_array(kCurrentContext::getCurrentPartnerId(), kConf::get('metadata_list_without_object_filtering_partners')) &&
kCurrentContext::$ks_partner_id != Partner::BATCH_PARTNER_ID)
throw new KalturaAPIException(MetadataErrors::MUST_FILTER_ON_OBJECT_ID);
if ($filter->metadataObjectTypeEqual == MetadataObjectType::ENTRY)
{
$objectIds = entryPeer::filterEntriesByPartnerOrKalturaNetwork($objectIds, kCurrentContext::getCurrentPartnerId());
if(count($objectIds))
$this->applyPartnerFilterForClass('Metadata');
}
elseif($filter->metadataObjectTypeEqual == KalturaMetadataObjectType::USER)
{
$objectIds = kuserPeer::getKuserByPartnerAndUids(kCurrentContext::getCurrentPartnerId(), $objectIds);
}
elseif($this->metadataObjectTypeEqual == MetadataObjectType::CATEGORY)
{
$objectIds = categoryPeer::retrieveByPKs($objectIds);
}
return $objectIds;
}
/**
* @param Metadata $metadata
ProTip! Use n and p to navigate between commits in a pull request.