first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-06-08 17:09:23 -04:00
commit df3a033196
17887 changed files with 8637778 additions and 0 deletions
@@ -0,0 +1,49 @@
<?php
/**
* @file controllers/grid/admin/context/ContextGridCellProvider.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ContextGridCellProvider
*
* @ingroup controllers_grid_admin_context
*
* @brief Subclass for a context grid column's cell provider
*/
namespace PKP\controllers\grid\admin\context;
use PKP\controllers\grid\GridCellProvider;
use PKP\controllers\grid\GridColumn;
class ContextGridCellProvider extends GridCellProvider
{
/**
* Extracts variables for a given column from a data element
* so that they may be assigned to template before rendering.
*
* @param \PKP\controllers\grid\GridRow $row
* @param GridColumn $column
*
* @return array
*/
public function getTemplateVarsFromRowColumn($row, $column)
{
$element = $row->getData();
$columnId = $column->getId();
assert($element instanceof \PKP\context\Context && !empty($columnId));
switch ($columnId) {
case 'name':
$label = $element->getLocalizedName() != '' ? $element->getLocalizedName() : __('common.untitled');
return ['label' => $label];
case 'urlPath':
$label = $element->getPath();
return ['label' => $label];
default:
break;
}
}
}
@@ -0,0 +1,309 @@
<?php
/**
* @file controllers/grid/admin/context/ContextGridHandler.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ContextGridHandler
*
* @ingroup controllers_grid_admin_context
*
* @brief Handle context grid requests.
*/
namespace PKP\controllers\grid\admin\context;
use APP\core\Application;
use APP\core\Request;
use APP\core\Services;
use APP\template\TemplateManager;
use PKP\controllers\grid\feature\OrderGridItemsFeature;
use PKP\controllers\grid\GridColumn;
use PKP\controllers\grid\GridHandler;
use PKP\core\JSONMessage;
use PKP\core\PKPApplication;
use PKP\linkAction\LinkAction;
use PKP\linkAction\request\AjaxModal;
use PKP\security\authorization\PolicySet;
use PKP\security\authorization\RoleBasedHandlerOperationPolicy;
use PKP\security\Role;
class ContextGridHandler extends GridHandler
{
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
$this->addRoleAssignment(
[
Role::ROLE_ID_SITE_ADMIN],
['fetchGrid', 'fetchRow', 'createContext', 'editContext', 'updateContext', 'users',
'deleteContext', 'saveSequence']
);
}
//
// Implement template methods from PKPHandler.
//
/**
* @copydoc PKPHandler::authorize()
*/
public function authorize($request, &$args, $roleAssignments)
{
$rolePolicy = new PolicySet(PolicySet::COMBINING_PERMIT_OVERRIDES);
foreach ($roleAssignments as $role => $operations) {
$rolePolicy->addPolicy(new RoleBasedHandlerOperationPolicy($request, $role, $operations));
}
$this->addPolicy($rolePolicy);
return parent::authorize($request, $args, $roleAssignments);
}
/**
* @copydoc GridHandler::initialize()
*
* @param null|mixed $args
*/
public function initialize($request, $args = null)
{
parent::initialize($request, $args);
$this->setTitle('context.contexts');
// Grid actions.
$router = $request->getRouter();
$this->addAction(
new LinkAction(
'createContext',
new AjaxModal(
$router->url($request, null, null, 'createContext', null, null),
__('admin.contexts.create'),
'modal_add_item',
true,
'context',
['editContext']
),
__('admin.contexts.create'),
'add_item'
)
);
//
// Grid columns.
//
$contextGridCellProvider = new ContextGridCellProvider();
// Context name.
$this->addColumn(
new GridColumn(
'name',
'common.name',
null,
null,
$contextGridCellProvider
)
);
// Context path.
$this->addColumn(
new GridColumn(
'urlPath',
'context.path',
null,
null,
$contextGridCellProvider
)
);
}
//
// Implement methods from GridHandler.
//
/**
* @copydoc GridHandler::getRowInstance()
*
* @return ContextGridRow
*/
protected function getRowInstance()
{
return new ContextGridRow();
}
/**
* @copydoc GridHandler::loadData()
*
* @param null|mixed $filter
*/
protected function loadData($request, $filter = null)
{
// Get all contexts.
$contextDao = Application::getContextDAO();
$contexts = $contextDao->getAll();
return $contexts->toAssociativeArray();
}
/**
* @copydoc GridHandler::setDataElementSequence()
*/
public function setDataElementSequence($request, $rowId, $gridDataElement, $newSequence)
{
$contextDao = Application::getContextDAO();
$gridDataElement->setSequence($newSequence);
$contextDao->updateObject($gridDataElement);
}
/**
* @copydoc GridHandler::getDataElementSequence()
*/
public function getDataElementSequence($gridDataElement)
{
return $gridDataElement->getSequence();
}
/**
* @copydoc GridHandler::addFeatures()
*/
public function initFeatures($request, $args)
{
return [new OrderGridItemsFeature()];
}
/**
* Get the list of "publish data changed" events.
* Used to update the site context switcher upon create/delete.
*
* @return array
*/
public function getPublishChangeEvents()
{
return ['updateHeader'];
}
//
// Public grid actions.
//
/**
* Add a new context.
*
* @param array $args
* @param Request $request
*/
public function createContext($args, $request)
{
// Calling editContext with an empty row id will add a new context.
return $this->editContext($args, $request);
}
/**
* Edit an existing context.
*
* @param array $args
* @param Request $request
*
* @return JSONMessage JSON object
*/
public function editContext($args, $request)
{
$contextService = Services::get('context');
$context = null;
if ($request->getUserVar('rowId')) {
$context = $contextService->get((int) $request->getUserVar('rowId'));
if (!$context) {
return new JSONMessage(false);
}
}
$dispatcher = $request->getDispatcher();
if ($context) {
$apiUrl = $dispatcher->url($request, PKPApplication::ROUTE_API, $context->getPath(), 'contexts/' . $context->getId());
$locales = $context->getSupportedFormLocaleNames();
} else {
$apiUrl = $dispatcher->url($request, PKPApplication::ROUTE_API, Application::CONTEXT_ID_ALL, 'contexts');
$locales = $request->getSite()->getSupportedLocaleNames();
}
$locales = array_map(fn (string $locale, string $name) => ['key' => $locale, 'label' => $name], array_keys($locales), $locales);
$contextForm = new \APP\components\forms\context\ContextForm($apiUrl, $locales, $request->getBaseUrl(), $context);
$contextFormConfig = $contextForm->getConfig();
// Pass the URL to the context settings wizard so that the AddContextForm
// component can redirect to it when a new context is added.
if (!$context) {
$contextFormConfig['editContextUrl'] = $request->getDispatcher()->url($request, PKPApplication::ROUTE_PAGE, 'index', 'admin', 'wizard', '__id__');
}
$templateMgr = TemplateManager::getManager($request);
$containerData = [
'components' => [
FORM_CONTEXT => $contextFormConfig,
],
'tinyMCE' => [
'skinUrl' => $templateMgr->getTinyMceSkinUrl($request),
],
];
$templateMgr->assign([
'containerData' => $containerData,
'isAddingNewContext' => !$context,
]);
return new JSONMessage(true, $templateMgr->fetch('admin/editContext.tpl'));
}
/**
* Delete a context.
*
* @param array $args
* @param Request $request
*
* @return JSONMessage JSON object
*/
public function deleteContext($args, $request)
{
if (!$request->checkCSRF()) {
return new JSONMessage(false);
}
$contextService = Services::get('context');
$context = $contextService->get((int) $request->getUserVar('rowId'));
if (!$context) {
return new JSONMessage(false);
}
$contextService->delete($context);
return \PKP\db\DAO::getDataChangedEvent($context->getId());
}
/**
* Display users management grid for the given context.
*
* @param array $args
* @param Request $request
*
* @return JSONMessage JSON object
*/
public function users($args, $request)
{
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign('oldUserId', (int) $request->getUserVar('oldUserId')); // for merging users.
parent::setupTemplate($request);
return $templateMgr->fetchJson('management/accessUsers.tpl');
}
}
@@ -0,0 +1,98 @@
<?php
/**
* @file controllers/grid/admin/context/ContextGridRow.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class ContextGridRow
*
* @ingroup controllers_grid_admin_context
*
* @brief Context grid row definition
*/
namespace PKP\controllers\grid\admin\context;
use PKP\controllers\grid\GridRow;
use PKP\core\PKPApplication;
use PKP\linkAction\LinkAction;
use PKP\linkAction\request\AjaxModal;
use PKP\linkAction\request\RedirectAction;
use PKP\linkAction\request\RemoteActionConfirmationModal;
class ContextGridRow extends GridRow
{
//
// Overridden methods from GridRow
//
/**
* @copydoc GridRow::initialize()
*
* @param null|mixed $template
*/
public function initialize($request, $template = null)
{
parent::initialize($request, $template);
// Is this a new row or an existing row?
$element = $this->getData();
assert($element instanceof \PKP\context\Context);
$rowId = $this->getId();
$router = $request->getRouter();
$this->addAction(
new LinkAction(
'edit',
new AjaxModal(
$router->url($request, null, null, 'editContext', null, ['rowId' => $rowId]),
__('grid.action.edit'),
'modal_edit',
true,
'context',
['editContext']
),
__('grid.action.edit'),
'edit'
)
);
$this->addAction(
new LinkAction(
'delete',
new RemoteActionConfirmationModal(
$request->getSession(),
__('admin.contexts.confirmDelete', ['contextName' => $element->getLocalizedName()]),
null,
$router->url($request, null, null, 'deleteContext', null, ['rowId' => $rowId])
),
__('grid.action.remove'),
'delete'
)
);
$dispatcher = $router->getDispatcher();
$this->addAction(
new LinkAction(
'wizard',
new RedirectAction($dispatcher->url($request, PKPApplication::ROUTE_PAGE, 'index', 'admin', 'wizard', $element->getId())),
__('grid.action.wizard'),
'wrench'
)
);
$this->addAction(
new LinkAction(
'users',
new AjaxModal(
$router->url($request, $element->getPath(), null, 'users', null),
__('manager.users'),
'modal_edit',
true
),
__('manager.users'),
'users'
)
);
}
}
@@ -0,0 +1,467 @@
<?php
/**
* @file controllers/grid/admin/languages/AdminLanguageGridHandler.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class AdminLanguageGridHandler
*
* @ingroup controllers_grid_admin_languages
*
* @brief Handle administrative language grid requests. If in single context (e.g.
* press) installation, this grid can also handle language management requests.
* See _canManage().
*/
namespace PKP\controllers\grid\admin\languages;
use APP\core\Application;
use APP\core\Request;
use APP\core\Services;
use APP\facades\Repo;
use APP\notification\NotificationManager;
use PKP\controllers\grid\GridColumn;
use PKP\controllers\grid\languages\form\InstallLanguageForm;
use PKP\controllers\grid\languages\LanguageGridHandler;
use PKP\core\JSONMessage;
use PKP\core\PKPRequest;
use PKP\db\DAORegistry;
use PKP\facades\Locale;
use PKP\linkAction\LinkAction;
use PKP\linkAction\request\AjaxModal;
use PKP\notification\PKPNotification;
use PKP\security\authorization\PolicySet;
use PKP\security\authorization\RoleBasedHandlerOperationPolicy;
use PKP\security\Role;
use PKP\services\interfaces\EntityWriteInterface;
use PKP\site\Site;
use PKP\site\SiteDAO;
class AdminLanguageGridHandler extends LanguageGridHandler
{
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
$this->addRoleAssignment(
[Role::ROLE_ID_SITE_ADMIN],
[
'fetchGrid', 'fetchRow',
'installLocale', 'saveInstallLocale', 'uninstallLocale',
'disableLocale', 'enableLocale', 'setPrimaryLocale'
]
);
}
//
// Implement template methods from PKPHandler.
//
/**
* @copydoc GridHandler::authorize()
*/
public function authorize($request, &$args, $roleAssignments)
{
$rolePolicy = new PolicySet(PolicySet::COMBINING_PERMIT_OVERRIDES);
foreach ($roleAssignments as $role => $operations) {
$rolePolicy->addPolicy(new RoleBasedHandlerOperationPolicy($request, $role, $operations));
}
$this->addPolicy($rolePolicy);
return parent::authorize($request, $args, $roleAssignments);
}
/**
* @copydoc LanguageGridHandler::initialize()
*
* @param null|mixed $args
*/
public function initialize($request, $args = null)
{
parent::initialize($request, $args);
// Grid actions.
$router = $request->getRouter();
$this->addAction(
new LinkAction(
'installLocale',
new AjaxModal(
$router->url($request, null, null, 'installLocale', null, null),
__('admin.languages.installLocale'),
null,
true
),
__('admin.languages.installLocale'),
'add'
)
);
// Columns.
// Enable locale.
$this->addColumn(
new GridColumn(
'enable',
'common.enable',
null,
'controllers/grid/common/cell/selectStatusCell.tpl',
$this->getCellProvider(),
['width' => 10]
)
);
$this->addNameColumn(); // Locale name.
$this->addLocaleCodeColumn(); // Locale code.
// Primary locale.
if ($this->_canManage($request)) {
$primaryId = 'contextPrimary';
} else {
$primaryId = 'sitePrimary';
}
$this->addPrimaryColumn($primaryId);
if ($this->_canManage($request)) {
$this->addManagementColumns();
}
$this->setFootNote('admin.locale.maybeIncomplete');
}
//
// Implement methods from GridHandler.
//
/**
* @copydoc GridHandler::loadData()
*/
protected function loadData($request, $filter)
{
$site = $request->getSite(); /** @var Site $site */
$data = [];
$installedLocales = $site->getInstalledLocaleNames();
$supportedLocales = $site->getSupportedLocales();
$primaryLocale = $site->getPrimaryLocale();
foreach ($installedLocales as $localeKey => $localeName) {
$data[$localeKey] = [];
$data[$localeKey]['code'] = $localeKey;
$data[$localeKey]['name'] = $localeName;
$data[$localeKey]['incomplete'] = !Locale::getMetadata($localeKey)->isComplete();
$data[$localeKey]['supported'] = in_array($localeKey, $supportedLocales);
if ($this->_canManage($request)) {
$context = $request->getContext();
$primaryLocale = $context->getPrimaryLocale();
}
$data[$localeKey]['primary'] = $localeKey === $primaryLocale;
}
if ($this->_canManage($request)) {
$data = $this->addManagementData($request, $data);
}
return $data;
}
//
// Public grid actions.
//
/**
* Open a form to select locales for installation.
*
* @param array $args
* @param PKPRequest $request
*
* @return JSONMessage JSON object
*/
public function installLocale($args, $request)
{
// Form handling.
$installLanguageForm = new InstallLanguageForm();
$installLanguageForm->initData();
return new JSONMessage(true, $installLanguageForm->fetch($request));
}
/**
* Save the install language form.
*
* @param array $args
* @param PKPRequest $request
*
* @return JSONMessage JSON object
*/
public function saveInstallLocale($args, $request)
{
$installLanguageForm = new InstallLanguageForm();
$installLanguageForm->readInputData();
if ($installLanguageForm->validate()) {
$installLanguageForm->execute();
$this->_updateContextLocaleSettings($request);
$notificationManager = new NotificationManager();
$user = $request->getUser();
$notificationManager->createTrivialNotification(
$user->getId(),
PKPNotification::NOTIFICATION_TYPE_SUCCESS,
['contents' => __('notification.localeInstalled')]
);
}
return \PKP\db\DAO::getDataChangedEvent();
}
/**
* Uninstall a locale.
*
* @param array $args
* @param Request $request
*
* @return JSONMessage JSON object
*/
public function uninstallLocale($args, $request)
{
$site = $request->getSite();
$locale = $request->getUserVar('rowId');
$gridData = $this->getGridDataElements($request);
if ($request->checkCSRF() && array_key_exists($locale, $gridData)) {
$localeData = $gridData[$locale];
if ($localeData['primary']) {
return new JSONMessage(false);
}
$installedLocales = $site->getInstalledLocales();
if (in_array($locale, $installedLocales)) {
$installedLocales = array_diff($installedLocales, [$locale]);
$site->setInstalledLocales($installedLocales);
$supportedLocales = $site->getSupportedLocales();
$supportedLocales = array_diff($supportedLocales, [$locale]);
$site->setSupportedLocales($supportedLocales);
$siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */
$siteDao->updateObject($site);
$this->_updateContextLocaleSettings($request);
Locale::uninstallLocale($locale);
$notificationManager = new NotificationManager();
$user = $request->getUser();
$notificationManager->createTrivialNotification(
$user->getId(),
PKPNotification::NOTIFICATION_TYPE_SUCCESS,
['contents' => __('notification.localeUninstalled', ['locale' => $localeData['name']])]
);
}
return \PKP\db\DAO::getDataChangedEvent($locale);
}
return new JSONMessage(false);
}
/**
* Enable an existing locale.
*
* @param array $args
* @param Request $request
*
* @return JSONMessage JSON object
*/
public function enableLocale($args, $request)
{
$rowId = $request->getUserVar('rowId');
$gridData = $this->getGridDataElements($request);
if (array_key_exists($rowId, $gridData)) {
$this->_updateLocaleSupportState($request, $rowId, true);
$notificationManager = new NotificationManager();
$user = $request->getUser();
$notificationManager->createTrivialNotification(
$user->getId(),
PKPNotification::NOTIFICATION_TYPE_SUCCESS,
['contents' => __('notification.localeEnabled')]
);
}
return \PKP\db\DAO::getDataChangedEvent($rowId);
}
/**
* Disable an existing locale.
*
* @param array $args
* @param Request $request
*
* @return JSONMessage JSON object
*/
public function disableLocale($args, $request)
{
$locale = $request->getUserVar('rowId');
$gridData = $this->getGridDataElements($request);
$notificationManager = new NotificationManager();
$user = $request->getUser();
if ($request->checkCSRF() && array_key_exists($locale, $gridData)) {
// Don't disable primary locales.
if ($gridData[$locale]['primary']) {
$notificationManager->createTrivialNotification(
$user->getId(),
PKPNotification::NOTIFICATION_TYPE_ERROR,
['contents' => __('admin.languages.cantDisable')]
);
} else {
$this->_updateLocaleSupportState($request, $locale, false);
$notificationManager->createTrivialNotification(
$user->getId(),
PKPNotification::NOTIFICATION_TYPE_SUCCESS,
['contents' => __('notification.localeDisabled')]
);
}
return \PKP\db\DAO::getDataChangedEvent($locale);
}
return new JSONMessage(false);
}
/**
* Set primary locale.
*
* @param array $args
* @param Request $request
*
* @return JSONMessage JSON object
*/
public function setPrimaryLocale($args, $request)
{
$rowId = $request->getUserVar('rowId');
$gridData = $this->getGridDataElements($request);
$localeData = $gridData[$rowId];
$notificationManager = new NotificationManager();
$user = $request->getUser();
$site = $request->getSite();
if (array_key_exists($rowId, $gridData)) {
if (Locale::isLocaleValid($rowId)) {
$oldSitePrimaryLocale = $site->getPrimaryLocale();
Repo::user()->dao->changeSitePrimaryLocale($oldSitePrimaryLocale, $rowId);
$site->setPrimaryLocale($rowId);
$siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */
$siteDao->updateObject($site);
$notificationManager->createTrivialNotification(
$user->getId(),
PKPNotification::NOTIFICATION_TYPE_SUCCESS,
['contents' => __('notification.primaryLocaleDefined', ['locale' => $localeData['name']])]
);
}
}
// Need to refresh whole grid to remove the check in others
// primary locale radio buttons.
return \PKP\db\DAO::getDataChangedEvent();
}
//
// Helper methods.
//
/**
* Update the locale support state (enabled or disabled).
*
* @param Request $request
* @param string $rowId The locale row id.
* @param bool $enable Enable locale flag.
*/
protected function _updateLocaleSupportState($request, $rowId, $enable)
{
$newSupportedLocales = [];
$gridData = $this->getGridDataElements($request);
foreach ($gridData as $locale => $data) {
if ($data['supported']) {
array_push($newSupportedLocales, $locale);
}
}
if (Locale::isLocaleValid($rowId)) {
if ($enable) {
array_push($newSupportedLocales, $rowId);
} else {
$key = array_search($rowId, $newSupportedLocales);
if ($key !== false) {
unset($newSupportedLocales[$key]);
}
}
}
$site = $request->getSite();
$site->setSupportedLocales($newSupportedLocales);
$siteDao = DAORegistry::getDAO('SiteDAO'); /** @var SiteDAO $siteDao */
$siteDao->updateObject($site);
$this->_updateContextLocaleSettings($request);
}
/**
* Helper function to update locale settings in all
* installed contexts, based on site locale settings.
*
* @param object $request
*/
protected function _updateContextLocaleSettings($request)
{
$site = $request->getSite();
$siteSupportedLocales = $site->getSupportedLocales();
$contextService = Services::get('context');
$contextDao = Application::getContextDAO();
$contexts = $contextDao->getAll();
while ($context = $contexts->next()) {
$params = [];
$primaryLocale = $context->getPrimaryLocale();
foreach (['supportedLocales', 'supportedFormLocales', 'supportedSubmissionLocales'] as $settingName) {
$localeList = $context->getData($settingName);
if (is_array($localeList)) {
$params[$settingName] = array_intersect($localeList, $siteSupportedLocales);
}
}
if (!in_array($primaryLocale, $siteSupportedLocales)) {
$params['primaryLocale'] = $site->getPrimaryLocale();
$primaryLocale = $params['primaryLocale'];
}
$errors = $contextService->validate(EntityWriteInterface::VALIDATE_ACTION_EDIT, $params, $params['supportedLocales'], $primaryLocale);
// If there are errors, it's too late to do anything about it
assert(empty($errors));
$contextService->edit($context, $params, $request);
}
}
/**
* This grid can also present management functions
* if the conditions above are true.
*
* @param Request $request
*
* @return bool
*/
protected function _canManage($request)
{
$contextDao = Application::getContextDAO();
$contexts = $contextDao->getAll();
$userRoles = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_USER_ROLES);
[$firstContext, $secondContext] = [$contexts->next(), $contexts->next()];
return ($firstContext && !$secondContext && $request->getContext() && in_array(Role::ROLE_ID_MANAGER, $userRoles));
}
}
@@ -0,0 +1,85 @@
<?php
/**
* @file controllers/grid/admin/plugins/AdminPluginGridHandler.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class AdminPluginGridHandler
*
* @ingroup controllers_grid_admin_plugins
*
* @brief Handle site level plugins grid requests.
*/
namespace PKP\controllers\grid\admin\plugins;
use APP\core\Application;
use PKP\controllers\grid\plugins\PluginGridHandler;
use PKP\controllers\grid\plugins\PluginGridRow;
use PKP\core\PKPRequest;
use PKP\security\authorization\PluginAccessPolicy;
use PKP\security\authorization\PolicySet;
use PKP\security\authorization\RoleBasedHandlerOperationPolicy;
use PKP\security\Role;
class AdminPluginGridHandler extends PluginGridHandler
{
/**
* Constructor
*/
public function __construct()
{
$roles = [Role::ROLE_ID_SITE_ADMIN];
$this->addRoleAssignment($roles, ['plugin']);
parent::__construct($roles);
}
//
// Overriden template methods.
//
/**
* @see GridHandler::getRowInstance()
*/
public function getRowInstance()
{
return new PluginGridRow($this->getAuthorizedContextObject(Application::ASSOC_TYPE_USER_ROLES));
}
/**
* @see GridHandler::authorize()
*
* @param PKPRequest $request
* @param array $args
* @param array $roleAssignments
*/
public function authorize($request, &$args, $roleAssignments)
{
$category = $request->getUserVar('category');
$pluginName = $request->getUserVar('plugin');
$verb = $request->getUserVar('verb');
if ($category && $pluginName) {
if ($verb) {
$accessMode = PluginAccessPolicy::ACCESS_MODE_MANAGE;
} else {
$accessMode = PluginAccessPolicy::ACCESS_MODE_ADMIN;
}
$this->addPolicy(new PluginAccessPolicy($request, $args, $roleAssignments, $accessMode));
} else {
$rolePolicy = new PolicySet(PolicySet::COMBINING_PERMIT_OVERRIDES);
foreach ($roleAssignments as $role => $operations) {
$rolePolicy->addPolicy(new RoleBasedHandlerOperationPolicy($request, $role, $operations));
}
$this->addPolicy($rolePolicy);
}
return parent::authorize($request, $args, $roleAssignments);
}
}