From da1d95c98aa56be38622789088e8dae5bf9e2f5b Mon Sep 17 00:00:00 2001 From: drorsouhami Date: Mon, 2 Sep 2024 13:27:06 +0300 Subject: [PATCH 1/2] REACH2-1246: Search for partner IDs that a catalog item is configured on --- .../service.reach.partnerCatalogItem.ini | 9 ++ .../2024_03_18_update_room_permissions.php | 2 +- ..._add_partner_catalog_items_permissions.php | 10 ++ ....php => Form_PartnerCatalogItemFilter.php} | 4 +- .../arrays/KalturaPartnerCatalogItemArray.php | 26 ++++ .../KalturaPartnerCatalogItemListResponse.php | 13 ++ .../KalturaPartnerCatalogItem.php | 132 ++++++++++++++++++ .../KalturaPartnerCatalogItemFilter.php | 57 ++++++++ .../KalturaPartnerCatalogItemBaseFilter.php | 111 +++++++++++++++ .../KalturaVendorCatalogItemFilter.php | 2 +- .../filters/PartnerCatalogItemFilter.php | 54 +++++++ .../services/PartnerCatalogItemService.php | 26 +++- 12 files changed, 440 insertions(+), 6 deletions(-) create mode 100644 deployment/updates/scripts/add_permissions/2024_09_10_add_partner_catalog_items_permissions.php rename plugins/reach/admin/forms/{PartnerCatalogItemFilter.php => Form_PartnerCatalogItemFilter.php} (99%) create mode 100644 plugins/reach/lib/api/arrays/KalturaPartnerCatalogItemArray.php create mode 100644 plugins/reach/lib/api/arrays/KalturaPartnerCatalogItemListResponse.php create mode 100644 plugins/reach/lib/api/data/partnerCatalogItem/KalturaPartnerCatalogItem.php create mode 100644 plugins/reach/lib/api/data/partnerCatalogItem/filters/KalturaPartnerCatalogItemFilter.php create mode 100644 plugins/reach/lib/api/data/partnerCatalogItem/filters/base/KalturaPartnerCatalogItemBaseFilter.php create mode 100644 plugins/reach/lib/model/filters/PartnerCatalogItemFilter.php diff --git a/deployment/permissions/service.reach.partnerCatalogItem.ini b/deployment/permissions/service.reach.partnerCatalogItem.ini index 97e5eb78ea6..70353adcab1 100644 --- a/deployment/permissions/service.reach.partnerCatalogItem.ini +++ b/deployment/permissions/service.reach.partnerCatalogItem.ini @@ -16,3 +16,12 @@ permissionItem2.param4 = permissionItem2.param5 = permissionItem2.tags = permissionItem2.permissions = PARTNER_-2_GROUP_*_PERMISSION, -2>PARTNER_-2_GROUP_*_PERMISSION, REACH_ADMIN_PERMISSION + +permissionItem3.service = reach_partnercatalogitem +permissionItem3.action = list +permissionItem3.partnerId = 0 +permissionItem3.param3 = +permissionItem3.param4 = +permissionItem3.param5 = +permissionItem3.tags = +permissionItem3.permissions = PARTNER_-2_GROUP_*_PERMISSION, -2>PARTNER_-2_GROUP_*_PERMISSION, REACH_ADMIN_PERMISSION diff --git a/deployment/updates/scripts/add_permissions/2024_03_18_update_room_permissions.php b/deployment/updates/scripts/add_permissions/2024_03_18_update_room_permissions.php index 35eb76a8c74..393d93de263 100644 --- a/deployment/updates/scripts/add_permissions/2024_03_18_update_room_permissions.php +++ b/deployment/updates/scripts/add_permissions/2024_03_18_update_room_permissions.php @@ -1,7 +1,7 @@ "configureCatalogItems($('#filter_input').val(), $('#filterServiceFeature').val(), $('#filterServiceType').val(), $('#filterTurnAroundTime').val(), $('#filterSourceLanguage').val(), $('#filterTargetLanguage').val(),$('#vendorPartnerId').val())", 'decorators' => array('ViewHelper'), )); - - } -} \ No newline at end of file +} diff --git a/plugins/reach/lib/api/arrays/KalturaPartnerCatalogItemArray.php b/plugins/reach/lib/api/arrays/KalturaPartnerCatalogItemArray.php new file mode 100644 index 00000000000..3691de77004 --- /dev/null +++ b/plugins/reach/lib/api/arrays/KalturaPartnerCatalogItemArray.php @@ -0,0 +1,26 @@ +validate(); + return parent::validateForInsert($propertiesToSkip); + } + + public function validateForUpdate($sourceObject, $propertiesToSkip = array()) + { + $this->validate($sourceObject); + return parent::validateForUpdate($sourceObject, $propertiesToSkip); + } + + private function validate(PartnerCatalogItem $sourceObject = null) + { + if (!$sourceObject) //Source object will be null on insert + { + $this->validatePropertyNotNull(array("partnerId", "catalogItemId")); + } + + $partner = PartnerPeer::retrieveByPK($this->partnerId); + if (!$partner) + { + // Edit error - partner doesnt exist + throw new KalturaAPIException(KalturaReachErrors::VENDOR_PARTNER_ID_NOT_FOUND, $this->partnerId); + } + + $catalogItem = VendorCatalogItemPeer::retrieveByPK($this->catalogItemId); + if (!$catalogItem) + { + throw new KalturaAPIException(KalturaReachErrors::CATALOG_ITEM_NOT_FOUND, $this->catalogItemId); + } + } + + public function getExtraFilters() + { + return array(); + } + + public function getFilterDocs() + { + return array(); + } + + /* (non-PHPdoc) + * @see IApiObjectFactory::getInstance($sourceObject, KalturaDetachedResponseProfile $responseProfile) + */ + public static function getInstance($sourceObject, KalturaDetachedResponseProfile $responseProfile = null) + { + $object = new KalturaPartnerCatalogItem(); + $object->fromObject($sourceObject, $responseProfile); + return $object; + } +} diff --git a/plugins/reach/lib/api/data/partnerCatalogItem/filters/KalturaPartnerCatalogItemFilter.php b/plugins/reach/lib/api/data/partnerCatalogItem/filters/KalturaPartnerCatalogItemFilter.php new file mode 100644 index 00000000000..8939441b301 --- /dev/null +++ b/plugins/reach/lib/api/data/partnerCatalogItem/filters/KalturaPartnerCatalogItemFilter.php @@ -0,0 +1,57 @@ +doGetListResponse($pager, $responseProfile); + } + + public function doGetListResponse(KalturaFilterPager $pager, KalturaDetachedResponseProfile $responseProfile = null) + { + $c = new Criteria(); + + $filter = $this->toObject(); + $filter->attachToCriteria($c); + $pager->attachToCriteria($c); + + $list = PartnerCatalogItemPeer::doSelect($c); + + $resultCount = count($list); + if ($resultCount && $resultCount < $pager->pageSize) + { + $totalCount = ($pager->pageIndex - 1) * $pager->pageSize + $resultCount; + } + else + { + KalturaFilterPager::detachFromCriteria($c); + $totalCount = PartnerCatalogItemPeer::doCount($c); + } + + $response = new KalturaPartnerCatalogItemListResponse(); + $response->objects = KalturaPartnerCatalogItemArray::fromDbArray($list, $responseProfile); + $response->totalCount = $totalCount; + return $response; + } + + /* (non-PHPdoc) + * @see KalturaRelatedFilter::getListResponse() + */ + public function getListResponse(KalturaFilterPager $pager, KalturaDetachedResponseProfile $responseProfile = null) + { + return $this->getTypeListResponse($pager, $responseProfile); + } +} diff --git a/plugins/reach/lib/api/data/partnerCatalogItem/filters/base/KalturaPartnerCatalogItemBaseFilter.php b/plugins/reach/lib/api/data/partnerCatalogItem/filters/base/KalturaPartnerCatalogItemBaseFilter.php new file mode 100644 index 00000000000..d9ec61617ca --- /dev/null +++ b/plugins/reach/lib/api/data/partnerCatalogItem/filters/base/KalturaPartnerCatalogItemBaseFilter.php @@ -0,0 +1,111 @@ + "_eq_id", + "idIn" => "_in_id", + "idNotIn" => "_notin_id", + "partnerIdEqual" => "_eq_partner_id", + "partnerIdIn" => "_in_partner_id", + "createdAtGreaterThanOrEqual" => "_gte_created_at", + "createdAtLessThanOrEqual" => "_lte_created_at", + "updatedAtGreaterThanOrEqual" => "_gte_updated_at", + "updatedAtLessThanOrEqual" => "_lte_updated_at", + "statusEqual" => "_eq_status", + "statusIn" => "_in_status", + "catalogItemIdEqual" => "_eq_catalog_item_id", + "catalogItemIdIn" => "_in_catalog_item_id", + ); + + static private $order_by_map = array + ( + "+id" => "+id", + "-id" => "-id", + "+createdAt" => "+created_at", + "-createdAt" => "-created_at", + "+updatedAt" => "+updated_at", + "-updatedAt" => "-updated_at", + ); + + public function getMapBetweenObjects() + { + return array_merge(parent::getMapBetweenObjects(), self::$map_between_objects); + } + + public function getOrderByMap() + { + return array_merge(parent::getOrderByMap(), self::$order_by_map); + } + + /** + * @var int + */ + public $idEqual; + + /** + * @var string + */ + public $idIn; + + /** + * @var string + */ + public $idNotIn; + + /** + * @var int + */ + public $partnerIdEqual; + + /** + * @var string + */ + public $partnerIdIn; + + /** + * @var time + */ + public $createdAtGreaterThanOrEqual; + + /** + * @var time + */ + public $createdAtLessThanOrEqual; + + /** + * @var time + */ + public $updatedAtGreaterThanOrEqual; + + /** + * @var time + */ + public $updatedAtLessThanOrEqual; + + /** + * @var KalturaVendorCatalogItemStatus + */ + public $statusEqual; + + /** + * @var string + */ + public $statusIn; + + /** + * @var int + */ + public $catalogItemIdEqual; + + /** + * @var string + */ + public $catalogItemIdIn; +} diff --git a/plugins/reach/lib/api/data/vendorCatalogItem/filters/KalturaVendorCatalogItemFilter.php b/plugins/reach/lib/api/data/vendorCatalogItem/filters/KalturaVendorCatalogItemFilter.php index c218bbaf781..328ce7c3806 100644 --- a/plugins/reach/lib/api/data/vendorCatalogItem/filters/KalturaVendorCatalogItemFilter.php +++ b/plugins/reach/lib/api/data/vendorCatalogItem/filters/KalturaVendorCatalogItemFilter.php @@ -52,7 +52,7 @@ public function doGetListResponse(KalturaFilterPager $pager, KalturaDetachedResp $c->add(PartnerCatalogItemPeer::STATUS, VendorCatalogItemStatus::ACTIVE); $c->addJoin(PartnerCatalogItemPeer::CATALOG_ITEM_ID, VendorCatalogItemPeer::ID, Criteria::INNER_JOIN); } - + $list = VendorCatalogItemPeer::doSelect($c); $resultCount = count($list); diff --git a/plugins/reach/lib/model/filters/PartnerCatalogItemFilter.php b/plugins/reach/lib/model/filters/PartnerCatalogItemFilter.php new file mode 100644 index 00000000000..d4a082cd017 --- /dev/null +++ b/plugins/reach/lib/model/filters/PartnerCatalogItemFilter.php @@ -0,0 +1,54 @@ +fields = kArray::makeAssociativeDefaultValue ( array ( + "_eq_id", + "_in_id", + "_notin_id", + "_eq_partner_id", + "_in_partner_id", + "_gte_created_at", + "_lte_created_at", + "_gte_updated_at", + "_lte_updated_at", + "_eq_status", + "_in_status", + "_eq_catalog_item_id", + "_in_catalog_item_id", + ) , NULL ); + + $this->allowed_order_fields = array ( + "id", + "created_at", + "updated_at", + ); + + $this->aliases = array ( + ); + } + + public function describe() + { + return + array ( + "display_name" => "PartnerCatalogItem", + "desc" => "" + ); + } + + public function getFieldNameFromPeer($field_name) + { + return PartnerCatalogItemPeer::translateFieldName($field_name, $this->field_name_translation_type, BasePeer::TYPE_COLNAME); + } + + public function getIdFromPeer() + { + return PartnerCatalogItemPeer::ID; + } +} diff --git a/plugins/reach/services/PartnerCatalogItemService.php b/plugins/reach/services/PartnerCatalogItemService.php index 9fb06499fbe..8e98616fb6a 100644 --- a/plugins/reach/services/PartnerCatalogItemService.php +++ b/plugins/reach/services/PartnerCatalogItemService.php @@ -15,6 +15,7 @@ public function initService($serviceId, $serviceName, $actionName) { parent::initService($serviceId, $serviceName, $actionName); + KalturaLog::debug("I am partner {$this->getPartnerId()}"); if (!ReachPlugin::isAllowedPartner($this->getPartnerId())) throw new KalturaAPIException(KalturaErrors::FEATURE_FORBIDDEN, ReachPlugin::PLUGIN_NAME); @@ -83,4 +84,27 @@ public function deleteAction($id) $dbPartnerCatalogItem->setStatus(VendorCatalogItemStatus::DELETED); $dbPartnerCatalogItem->save(); } -} \ No newline at end of file + + /** + * List KalturaPartnerCatalogItem objects + * + * @action list + * @param KalturaPartnerCatalogItemFilter $filter + * @param KalturaFilterPager $pager + * @return KalturaPartnerCatalogItemListResponse + */ + public function listAction(KalturaPartnerCatalogItemFilter $filter = null, KalturaFilterPager $pager = null) + { + if (!$filter) + { + $filter = new KalturaPartnerCatalogItemFilter(); + } + + if (!$pager) + { + $pager = new KalturaFilterPager(); + } + + return $filter->getTypeListResponse($pager, $this->getResponseProfile()); + } +} From cb326a9f18ea8a62faa5e47cbb3a08230f252d60 Mon Sep 17 00:00:00 2001 From: drorsouhami Date: Sun, 15 Sep 2024 08:53:59 +0300 Subject: [PATCH 2/2] REACH2-1246: Add admin console page --- plugins/reach/ReachPlugin.php | 1 + .../admin/PartnersByCatalogItemAction.php | 82 ++++++++++++ .../Form_PartnersByCatalogItemFilter.php | 24 ++++ .../partners-by-catalog-item-action.phtml | 118 ++++++++++++++++++ .../KalturaPartnerCatalogItemFilter.php | 5 - 5 files changed, 225 insertions(+), 5 deletions(-) create mode 100644 plugins/reach/admin/PartnersByCatalogItemAction.php create mode 100644 plugins/reach/admin/forms/Form_PartnersByCatalogItemFilter.php create mode 100644 plugins/reach/admin/scripts/plugin/partners-by-catalog-item-action.phtml diff --git a/plugins/reach/ReachPlugin.php b/plugins/reach/ReachPlugin.php index 29e4e7af39d..462867eb978 100644 --- a/plugins/reach/ReachPlugin.php +++ b/plugins/reach/ReachPlugin.php @@ -175,6 +175,7 @@ public static function getApplicationPages() $pages[] = new ReachRequestsListAction(); $pages[] = new ReachRequestsExportAction(); $pages[] = new ReachRequestsAbortAction(); + $pages[] = new PartnersByCatalogItemAction(); return $pages; } diff --git a/plugins/reach/admin/PartnersByCatalogItemAction.php b/plugins/reach/admin/PartnersByCatalogItemAction.php new file mode 100644 index 00000000000..5c4675f0c26 --- /dev/null +++ b/plugins/reach/admin/PartnersByCatalogItemAction.php @@ -0,0 +1,82 @@ +action = 'PartnersByCatalogItemAction'; + $this->label = "Find Partners By Catalog Item"; + $this->rootLabel = "Reach"; + } + + /** + * @return string - absolute file path of the phtml template + */ + public function getTemplatePath() + { + return realpath(dirname(__FILE__)); + } + + public function doAction(Zend_Controller_Action $action) + { + $request = $action->getRequest(); + + $partnerCatalogItemFilter = new Kaltura_Client_Reach_Type_PartnerCatalogItemFilter; + $partnerCatalogItemFilter->catalogItemIdEqual = $request->getParam('filter_input') ?? null; + + $action->view->allowed = $this->isAllowedForPartner(null); + + $client = Infra_ClientHelper::getClient(); + $reachPluginClient = Kaltura_Client_Reach_Plugin::get($client); + + $paginatorAdapter = new Infra_FilterPaginator($reachPluginClient->PartnerCatalogItem, "listAction", null, $partnerCatalogItemFilter); + $paginator = new Infra_Paginator($paginatorAdapter, $request); + $page = $this->_getParam('page', 1); + $pageSize = $this->_getParam('pageSize', 10); + $paginator->setCurrentPageNumber($page); + $paginator->setItemCountPerPage($pageSize); + + // set view + $partnersByCatalogItemFilterForm = new Form_PartnersByCatalogItemFilter(); + $partnersByCatalogItemFilterForm->populate($request->getParams()); + $partnersByCatalogItemFilterFormAction = $action->view->url(array('controller' => $request->getParam('controller'), 'action' => $request->getParam('action')), null, true); + $partnersByCatalogItemFilterForm->setAction($partnersByCatalogItemFilterFormAction); + + $action->view->filterForm = $partnersByCatalogItemFilterForm; + $action->view->paginator = $paginator; + } + + public function getInstance($interface) + { + if ($this instanceof $interface) + return $this; + + return null; + } + + public function isAllowedForPartner($partnerId) + { + $client = Infra_ClientHelper::getClient(); + $client->setPartnerId($partnerId); + $filter = new Kaltura_Client_Type_PermissionFilter(); + $filter->nameEqual = Kaltura_Client_Enum_PermissionName::REACH_PLUGIN_PERMISSION; + $filter->partnerIdEqual = $partnerId; + try + { + $result = $client->permission->listAction($filter, null); + } catch (Exception $e) + { + $client->setPartnerId(self::ADMIN_CONSOLE_PARTNER); + return false; + } + $client->setPartnerId(self::ADMIN_CONSOLE_PARTNER); + + $isAllowed = ($result->totalCount > 0) && ($result->objects[0]->status == Kaltura_Client_Enum_PermissionStatus::ACTIVE); + return $isAllowed; + } +} diff --git a/plugins/reach/admin/forms/Form_PartnersByCatalogItemFilter.php b/plugins/reach/admin/forms/Form_PartnersByCatalogItemFilter.php new file mode 100644 index 00000000000..5e98626d1c2 --- /dev/null +++ b/plugins/reach/admin/forms/Form_PartnersByCatalogItemFilter.php @@ -0,0 +1,24 @@ +removeElement("cmdSubmit"); + $filterType = $this->getElement('filter_type'); + $filterType->setMultiOptions(array( + 'catalogItemIdEqual' => 'Catalog Item ID', + )); + + $this->addElement('button', 'cmdSubmit', array( + 'type' => 'submit', + 'label' => 'Search', + 'decorators' => array('ViewHelper'), + )); + } +} diff --git a/plugins/reach/admin/scripts/plugin/partners-by-catalog-item-action.phtml b/plugins/reach/admin/scripts/plugin/partners-by-catalog-item-action.phtml new file mode 100644 index 00000000000..422eb7c95af --- /dev/null +++ b/plugins/reach/admin/scripts/plugin/partners-by-catalog-item-action.phtml @@ -0,0 +1,118 @@ +allowed) {echo $this->translate('This partner is not allowed to use Reach'); return;} ?> +

translate('Here you can view all partners using a specific Catalog Item'); ?>

+filterForm; ?> + +
+ + + + + + + + + + + + + + + + + paginator) + foreach($this->paginator as /* Kaltura_Client_Reach_Type_VendorCatalogItem */$partnerCatalogItem): ?> + + + + + + + + + +
Selecttranslate('ID'); ?>translate('Catalog Item ID'); ?>translate('Partner ID'); ?>translate('Action'); ?>
+ paginator; ?> +
id; ?>catalogItemId; ?>partnerId ?? ' '; ?> + +
+
+ + diff --git a/plugins/reach/lib/api/data/partnerCatalogItem/filters/KalturaPartnerCatalogItemFilter.php b/plugins/reach/lib/api/data/partnerCatalogItem/filters/KalturaPartnerCatalogItemFilter.php index 8939441b301..1c3a95ec911 100644 --- a/plugins/reach/lib/api/data/partnerCatalogItem/filters/KalturaPartnerCatalogItemFilter.php +++ b/plugins/reach/lib/api/data/partnerCatalogItem/filters/KalturaPartnerCatalogItemFilter.php @@ -5,11 +5,6 @@ */ class KalturaPartnerCatalogItemFilter extends KalturaPartnerCatalogItemBaseFilter { - /** - * @var int - */ - public $partnerIdEqual; - protected function getCoreFilter() { return new PartnerCatalogItemFilter();