Open Journal Systems  3.3.0
StageRolePolicy.inc.php
1 <?php
17 import('lib.pkp.classes.security.authorization.AuthorizationPolicy');
18 
21  private $_roleIds;
22 
24  private $_stageId;
25 
27  private $_allowRecommendOnly;
28 
38  function __construct($roleIds, $stageId = null, $allowRecommendOnly = true) {
39  AppLocale::requireComponents(LOCALE_COMPONENT_PKP_USER);
40  parent::__construct('user.authorization.accessibleWorkflowStage');
41  $this->_roleIds = $roleIds;
42  $this->_stageId = $stageId;
43  $this->_allowRecommendOnly = $allowRecommendOnly;
44  }
45 
46  //
47  // Implement template methods from AuthorizationPolicy
48  //
52  function effect() {
53 
54  // Use the submission's current stage id if none is specified in policy
55  if (!$this->_stageId) {
56  $this->_stageId = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION)->getData('stageId');
57  }
58 
59  // Check whether the user has one of the allowed roles assigned in the correct stage
60  $userAccessibleStages = (array) $this->getAuthorizedContextObject(ASSOC_TYPE_ACCESSIBLE_WORKFLOW_STAGES);
61 
62  if (array_key_exists($this->_stageId, $userAccessibleStages) && array_intersect($this->_roleIds, $userAccessibleStages[$this->_stageId])) {
63  if ($this->_allowRecommendOnly) {
64  return AUTHORIZATION_PERMIT;
65  }
66  $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /* @var $stageAssignmentDao StageAssignmentDAO */
67  $result = $stageAssignmentDao->getBySubmissionAndUserIdAndStageId(
68  $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION)->getId(),
69  Application::get()->getRequest()->getUser()->getId(),
70  $this->_stageId
71  );
72  while (!$result->eof()) {
73  $stageAssignment = $result->next();
74  $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
75  $userGroup = $userGroupDao->getById($stageAssignment->getUserGroupId());
76  if (in_array($userGroup->getRoleId(), $this->_roleIds) && !$stageAssignment->getRecommendOnly()) {
77  return AUTHORIZATION_PERMIT;
78  }
79  }
80  }
81 
82  // A manager is granted access when they are not assigned in any other role
83  if (empty($userAccessibleStages) && in_array(ROLE_ID_MANAGER, $this->getAuthorizedContextObject(ASSOC_TYPE_USER_ROLES))) {
84  if ($this->_allowRecommendOnly) {
85  return AUTHORIZATION_PERMIT;
86  }
87  // Managers may have a stage assignment but no $userAccessibleStages, so they will
88  // not be caught by the earlier code that checks stage assignments.
89  $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /* @var $stageAssignmentDao StageAssignmentDAO */
90  $result = $stageAssignmentDao->getBySubmissionAndUserIdAndStageId(
91  $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION)->getId(),
92  Application::get()->getRequest()->getUser()->getId(),
93  $this->_stageId
94  );
95  if ($result->wasEmpty()) {
96  return AUTHORIZATION_PERMIT;
97  }
98  while (!$result->eof()) {
99  $stageAssignment = $result->next();
100  $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
101  $userGroup = $userGroupDao->getById($stageAssignment->getUserGroupId());
102  if ($userGroup->getRoleId() == ROLE_ID_MANAGER && !$stageAssignment->getRecommendOnly()) {
103  return AUTHORIZATION_PERMIT;
104  }
105  }
106  }
107 
108  return AUTHORIZATION_DENY;
109  }
110 }
111 
112 
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
Http\Client\Exception\getRequest
getRequest()
Definition: RequestAwareTrait.php:25
StageRolePolicy\effect
effect()
Definition: StageRolePolicy.inc.php:61
AuthorizationPolicy\getAuthorizedContextObject
& getAuthorizedContextObject($assocType)
Definition: AuthorizationPolicy.inc.php:117
StageRolePolicy\__construct
__construct($roleIds, $stageId=null, $allowRecommendOnly=true)
Definition: StageRolePolicy.inc.php:47
StageRolePolicy
Class to check if the user has an assigned role on a specific submission stage. Optionally deny autho...
Definition: StageRolePolicy.inc.php:19
AuthorizationPolicy
Class to represent an authorization policy.
Definition: AuthorizationPolicy.inc.php:31
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235