Skip to content
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
11 changes: 10 additions & 1 deletion classes/submission/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,16 @@ protected function getPropertyStages(?Enumerable $stageAssignments, Submission $

$userGroup = $stageAssignment->userGroup; /** @var UserGroup $userGroup */

foreach ($userGroup->userGroupStages as $groupStage) { /** @var UserGroupStage $groupStage */
$userGroupStages = $userGroup->userGroupStages;
// Enforce ROLE_ID_MANAGER being assigned to all stages
if($userGroup->roleId === Role::ROLE_ID_MANAGER) {
$workflowStages = Application::getApplicationStages();
$userGroupStages = array_map(function($stageId) {
return (object)['stageId' => $stageId];
}, $workflowStages);

}
foreach ($userGroupStages as $groupStage) { /** @var UserGroupStage $groupStage */
// Identify the first user with the editor
if (
!$stages[$groupStage->stageId]['editorAssigned'] &&
Expand Down
18 changes: 14 additions & 4 deletions classes/user/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ public function getAccessibleWorkflowStages(int $userId, int $contextId, Submiss
->withUserId($userId)
->get();

$workflowStages = Application::getApplicationStages();


foreach ($stageAssignments as $stageAssignment) {
$userGroup = $stageAssignment->userGroup;
$roleId = $userGroup->roleId;
Expand All @@ -243,15 +246,22 @@ public function getAccessibleWorkflowStages(int $userId, int $contextId, Submiss
continue;
}

$stageAssignment->userGroupStages->each(function ($userGroupStage) use (&$accessibleWorkflowStages, $roleId) {
$accessibleWorkflowStages[$userGroupStage->stageId][] = $roleId;
});

// for ROLE_ID_MANAGER always give access to all stages and ignore assignments from database
if ($roleId === Role::ROLE_ID_MANAGER) {
foreach ($workflowStages as $stageId) {
$accessibleWorkflowStages[$stageId][] = $roleId;
}
} else {
$stageAssignment->userGroupStages->each(function ($userGroupStage) use (&$accessibleWorkflowStages, $roleId) {
$accessibleWorkflowStages[$userGroupStage->stageId][] = $roleId;
});
}
}

// Managers and admin have access if not assigned to the submission or are assigned in a revoked role
$managerRoles = array_intersect($userRoleIds, [Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_MANAGER]);
if (empty($accessibleWorkflowStages) && !empty($managerRoles)) {
$workflowStages = Application::getApplicationStages();
foreach ($workflowStages as $stageId) {
$accessibleWorkflowStages[$stageId] = $managerRoles;
}
Expand Down