Skip to content
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

REACH2-1246: Search for partner IDs that a catalog item is configured on #12900

Open
wants to merge 2 commits into
base: Tucana-20.20.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions deployment/permissions/service.reach.partnerCatalogItem.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @package deployment
* @subpackage scorpius.roles_and_permissions
* @subpackage tucana.roles_and_permissions
*/

$script = realpath(dirname(__FILE__) . '/../../../../') . '/alpha/scripts/utils/permissions/addPermissionsAndItems.php';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
/**
* @package deployment
* @subpackage tucana.roles_and_permissions
*/

$script = realpath(dirname(__FILE__) . '/../../../../') . '/alpha/scripts/utils/permissions/addPermissionsAndItems.php';

$config = realpath(dirname(__FILE__)) . '/../../../permissions/service.reach.partnerCatalogItem.ini';
passthru("php $script $config");
1 change: 1 addition & 0 deletions plugins/reach/ReachPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public static function getApplicationPages()
$pages[] = new ReachRequestsListAction();
$pages[] = new ReachRequestsExportAction();
$pages[] = new ReachRequestsAbortAction();
$pages[] = new PartnersByCatalogItemAction();

return $pages;
}
Expand Down
82 changes: 82 additions & 0 deletions plugins/reach/admin/PartnersByCatalogItemAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/**
* @package plugins.reach
* @subpackage Admin
*/
class PartnersByCatalogItemAction extends KalturaApplicationPlugin
{
const ADMIN_CONSOLE_PARTNER = "-2";

public function __construct()
{
$this->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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,5 @@ public function init()
'onclick' => "configureCatalogItems($('#filter_input').val(), $('#filterServiceFeature').val(), $('#filterServiceType').val(), $('#filterTurnAroundTime').val(), $('#filterSourceLanguage').val(), $('#filterTargetLanguage').val(),$('#vendorPartnerId').val())",
'decorators' => array('ViewHelper'),
));


}
}
}
24 changes: 24 additions & 0 deletions plugins/reach/admin/forms/Form_PartnersByCatalogItemFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* @package plugins.reach
* @subpackage Admin
*/
class Form_PartnersByCatalogItemFilter extends Form_PartnerIdFilter
{
public function init()
{
parent::init();

$this->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'),
));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php if (!$this->allowed) {echo $this->translate('This partner is not allowed to use Reach'); return;} ?>
<p><?php echo $this->translate('Here you can view all partners using a specific Catalog Item'); ?></p>
<?php echo $this->filterForm; ?>

<div id="partners-by-catalog_item_list_div" class="clear">
<table>
<thead>
<tr>
<th>Select</th>
<th><?php echo $this->translate('ID'); ?></th>
<th><?php echo $this->translate('Catalog Item ID'); ?></th>
<th><?php echo $this->translate('Partner ID'); ?></th>
<th><?php echo $this->translate('Action'); ?></th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="17">
<?php echo $this->paginator; ?>
</td>
</tr>
</tfoot>
<tbody>
<?php if ($this->paginator)
foreach($this->paginator as /* Kaltura_Client_Reach_Type_VendorCatalogItem */$partnerCatalogItem): ?>
<tr class="<?php echo $this->cycle(array('odd', 'even'))->next(); ?>">
<td><input type="checkbox" name="catalogItemsCheckBoxItems[]" id="$catalogItemsCheckBox-<?php echo $partnerCatalogItem->id; ?>" value="<?php echo $partnerCatalogItem->id; ?>" /></td>
<td><?php echo $partnerCatalogItem->id; ?></td>
<td><?php echo $partnerCatalogItem->catalogItemId; ?></td>
<td><?php echo $partnerCatalogItem->partnerId ?? ' '; ?></td>
<td>
<select class="options" onchange="doAction(this.value, <?php echo $this->filterForm->getElement('filter_input')->getValue(); ?>, <?php echo $partnerCatalogItem->partnerId;?>)">
<option value=""><?php echo $this->translate('Select Action'); ?></option>
<option value="remove" ><?php echo $this->translate('Remove'); ?></option>
</select>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>

<script type="text/javascript">

$(function () {
updateFiltersView();
});

jQuery('#filter_type').change(function() {
if(this.value == "none") {
$("#filter_text").css("display","none");
}
else {
$("#filter_text").css("display","inline");
$("#filter_text input").focus();
if(this.value == "free")
$("div.help").show();
else
$("div.help").hide();
}
});

jQuery('#filter_type').change();

function doAction(action, folderId) {
if (action && eval('typeof ' + action) == 'function')
{
f = eval(action);
Array.prototype.shift.apply(arguments);
f.apply(this, arguments);
}
jQuery('select.options').val('');
}

function remove(catalogItemId,partnerId)
{
var ok = confirm('<?php echo $this->translate('Are you sure you want to remove Catalog Item from partner ?'); ?>');
if (ok)
{
changeStatus(
catalogItemId,
<?php echo Kaltura_Client_Reach_Enum_VendorCatalogItemStatus::DELETED; ?>,
partnerId,
function() {
alert('<?php echo $this->translate('Partner catalog Item removed');?>');
}
);
}
}

function changeStatus(catalogItemIds, status, partnerId, callback)
{
var url = '<?php echo $this->url(array('controller' => 'plugin', 'action' => 'PartnerCatalogItemSetStatusAction', 'catalogItemIds' => 'CATALOGITEMIDS','partnerId' => 'PARTNERID', 'catalogItemStatus' => 'STATUS')); ?>';
url = url.replace('STATUS', status);
url = url.replace('CATALOGITEMIDS', catalogItemIds);
url = url.replace('PARTNERID', partnerId);
jQuery.ajax({
url: url,
dataType: 'json',
success: function(result) {
if (result != 'ok')
this.error(result);
else
{
if (callback && (typeof callback == 'function'))
{
callback.apply(this);
}
}
jQuery('#frmPaginator1').submit();
},
error: function(result) {
alert(JSON.stringify(result));
}
});
}

</script>
26 changes: 26 additions & 0 deletions plugins/reach/lib/api/arrays/KalturaPartnerCatalogItemArray.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* @package plugins.reach
* @subpackage api.objects
*/
class KalturaPartnerCatalogItemArray extends KalturaTypedArray
{
public static function fromDbArray($arr, KalturaDetachedResponseProfile $responseProfile = null)
{
$newArr = new KalturaPartnerCatalogItemArray();
if ($arr == null)
return $newArr;

foreach ($arr as $obj)
{
$newArr[] = KalturaPartnerCatalogItem::getInstance($obj, $responseProfile);
}

return $newArr;
}

public function __construct()
{
parent::__construct("KalturaPartnerCatalogItem");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* @package plugins.reach
* @subpackage api.objects
*/
class KalturaPartnerCatalogItemListResponse extends KalturaListResponse
{
/**
* @var KalturaPartnerCatalogItemArray
* @readonly
*/
public $objects;
}
Loading