Skip to content

Commit

Permalink
#10076 using currentUserAssignedRoles and array_intersect()
Browse files Browse the repository at this point in the history
  • Loading branch information
Hafsa-Naeem committed Feb 24, 2025
1 parent 45697e1 commit 3ae8f0e
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions classes/submission/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ protected function mapByProperties(array $props, Submission $submission, bool|Co
$output[$prop] = $currentReviewRound ? $this->areRecommendationsIn($currentReviewRound, $this->stageAssignments) : null;
break;
case 'reviewAssignments':
$output[$prop] = $this->getPropertyReviewAssignments($this->reviewAssignments, $anonymizeReviews);
$output[$prop] = $this->getPropertyReviewAssignments($this->reviewAssignments, $anonymizeReviews, $submission);
break;
case 'participants':
$output[$prop] = $this->getPropertyParticipants($submission);
Expand Down Expand Up @@ -526,27 +526,24 @@ protected function canChangeMetadata(Enumerable $stageAssignments, Submission $s
/**
* Get details about the review assignments for a submission
*/
protected function getPropertyReviewAssignments(Enumerable $reviewAssignments, bool|Collection $anonymizeReviews = false): array
protected function getPropertyReviewAssignments(Enumerable $reviewAssignments, bool|Collection $anonymizeReviews = false, Submission $submission): array
{
$request = Application::get()->getRequest();
$currentUser = $request->getUser();
$currentUserRoleIds = array_map(
function (Role $role) {
return $role->getId();
},
$currentUser->getRoles($this->context->getId())
);

// is the user a manager, sub-editor, or site admin?
$canSeeAllReviewAssignments = (
in_array(Role::ROLE_ID_MANAGER, $currentUserRoleIds) ||
in_array(Role::ROLE_ID_SUB_EDITOR, $currentUserRoleIds) ||
in_array(Role::ROLE_ID_SITE_ADMIN, $currentUserRoleIds)
);
$reviews = [];
$request = Application::get()->getRequest();
$currentUser = $request->getUser();
// current user's assigned roles from the submission's stages
$currentUserAssignedRoles = [];
foreach ($this->getPropertyStages($this->stageAssignments, $submission, $this->decisions ?? null, null) as $stage) {
if (isset($stage['currentUserAssignedRoles'])) {
$currentUserAssignedRoles = array_merge($currentUserAssignedRoles, $stage['currentUserAssignedRoles']);
}
}
$currentUserAssignedRoles = array_unique($currentUserAssignedRoles);

// define the roles that can see declined or cancelled review assignments
$allowedRoles = [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR, Role::ROLE_ID_SITE_ADMIN];
$canSeeAllReviewAssignments = !empty(array_intersect($currentUserAssignedRoles, $allowedRoles));
$reviews = [];
foreach ($reviewAssignments as $reviewAssignment) {
// declined or cancelled are only show to editors, sub-editors and site admin
if (
Expand Down Expand Up @@ -580,7 +577,7 @@ function (Role $role) {

$reviews[] = [
'id' => (int) $reviewAssignment->getId(),
'isCurrentUserAssigned' => $currentUser->getId() === (int) $reviewAssignment->getReviewerId(),
'isCurrentUserAssigned' => $currentUser->getId() == (int) $reviewAssignment->getReviewerId(),
'statusId' => (int) $reviewAssignment->getStatus(),
'status' => __($reviewAssignment->getStatusKey()),
'dateDue' => $dateDue,
Expand Down

0 comments on commit 3ae8f0e

Please sign in to comment.