Skip to content

Commit

Permalink
#10480 Fix incorrect data in stage property
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy-1 committed Jan 9, 2025
1 parent a4a97de commit 41ed351
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 38 deletions.
96 changes: 58 additions & 38 deletions classes/submission/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function map(
$this->genres = $genres;
$this->userRoles = $userRoles;
$this->reviewAssignments = $reviewAssignments ?? Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany()->remember();
$this->stageAssignments = $stageAssignments ?? $this->getStageAssignmentsBySubmissions(collect([$item]), [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR]);
$this->stageAssignments = $stageAssignments ?? $this->getStageAssignmentsBySubmissions(collect([$item]));
$this->decisions = $decisions ?? Repo::decision()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany()->remember();

return $this->mapByProperties($this->getProps(), $item, $anonymizeReviews);
Expand Down Expand Up @@ -165,7 +165,7 @@ public function summarize(
$this->userGroups = $userGroups;
$this->genres = $genres;
$this->reviewAssignments = $reviewAssignments ?? Repo::reviewAssignment()->getCollector()->filterBySubmissionIds([$item->getId()])->getMany()->remember();
$this->stageAssignments = $stageAssignments ?? $this->getStageAssignmentsBySubmissions(collect([$item]), [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR]);
$this->stageAssignments = $stageAssignments ?? $this->getStageAssignmentsBySubmissions(collect([$item]));

return $this->mapByProperties($this->getSummaryProps(), $item, $anonymizeReviews);
}
Expand Down Expand Up @@ -236,7 +236,7 @@ public function summarizeMany(Enumerable $collection, Enumerable $userGroups, ar
$this->userGroups = $userGroups;
$this->genres = $genres;
$this->reviewAssignments = Repo::reviewAssignment()->getCollector()->filterBySubmissionIds($collection->keys()->toArray())->getMany()->remember();
$this->stageAssignments = $this->getStageAssignmentsBySubmissions($collection, [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR]);
$this->stageAssignments = $this->getStageAssignmentsBySubmissions($collection);

$associatedReviewAssignments = $this->reviewAssignments->groupBy(
fn (ReviewAssignment $reviewAssignment, int $key) =>
Expand Down Expand Up @@ -408,10 +408,17 @@ protected function mapByProperties(array $props, Submission $submission, bool|Co
$output[$prop] = Repo::submission()->getUrlApi($this->context, $submission->getId());
break;
case 'availableEditorialDecisions':
$output[$prop] = collect(Application::get()->getApplicationStages())->mapWithKeys(function (int $stageId) use ($submission) {
$availableEditorialDecisions = $this->getAvailableEditorialDecisions($stageId, $submission);
return [$stageId => array_map(fn (DecisionType $decisionType) => ['id' => $decisionType->getDecision(), 'label' => $decisionType->getLabel()], $availableEditorialDecisions)];
})->values()->all();
$output[$prop] = collect($this->getAvailableEditorialDecisions(
$submission->getData('stageId'),
$submission
))->map(
fn (DecisionType $decisionType) =>
[
'stageId' => $submission->getData('stageId'),
'id' => $decisionType->getDecision(),
'label' => $decisionType->getLabel(),
]
)->toArray();
break;
case 'canCurrentUserChangeMetadata':
// Identify if current user can change metadata. Consider roles in the active stage.
Expand Down Expand Up @@ -594,14 +601,16 @@ protected function getPropertyStages(Enumerable $stageAssignments, Submission $s

// values false by default, to be determined later
'editorAssigned' => false,
'isDecidingEditorAssigned' => false,
'isCurrentUserDecidingEditor' => false,
'currentUserAssignedRoles' => [],
];
}

$recommendations = [];
$isAssignedInAnyRole = false; // Determine if the current user is assigned to the submission in any role
$hasDecidingEditor = false;
$hasRecommendingEditors = false;
$isCurrentUserDecidingEditor = false;

// Determine stage assignment related data
foreach ($stageAssignments as $stageAssignment) {
Expand All @@ -611,40 +620,42 @@ protected function getPropertyStages(Enumerable $stageAssignments, Submission $s
// Identify the first user with the editor
if (
!$stages[$groupStage->stageId]['editorAssigned'] &&
in_array(
$userGroup->roleId,
[Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR]
)
in_array($userGroup->roleId, [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR])
) {
$editorAssigned = $stages[$groupStage->stageId]['editorAssigned'] = true;
$stages[$groupStage->stageId]['editorAssigned'] = true;
}

// Identify the first user with the editor role and without recommend only flag
// Identify the first user with the editor role and with a recommend only flag
if (
!$stages[$groupStage->stageId]['isDecidingEditorAssigned'] &&
isset($editorAssigned) &&
!$hasDecidingEditor &&
in_array($userGroup->roleId, [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR]) &&
!$stageAssignment->recommendOnly
) {
$isDecidingEditorAssigned = $stages[$groupStage->stageId]['isDecidingEditorAssigned'] = true;
$hasDecidingEditor = true;
}

// Record recommendations for review stages
if (
$stageAssignment->recommendOnly &&
isset($currentReviewRound) &&
isset($decisions) && $decisions->isNotEmpty()
) {
foreach ($decisions as $decision) {
if ($currentReviewRound->getId() != $decision->getData('reviewRoundId')) {
continue;
}
if ($stageAssignment->recommendOnly) {
if (!$hasRecommendingEditors) {
$hasRecommendingEditors = true;
}

$decisionType = Repo::decision()->getDecisionType($decision->getData('decision'));
$recommendations[$decision->getId()] = [
'decision' => $decision->getData('decision'),
'label' => $decisionType->getLabel(),
'stageId' => $decision->getData('stageId'),
];
if (
isset($currentReviewRound) &&
isset($decisions) && $decisions->isNotEmpty()
) {
foreach ($decisions as $decision) {
if ($currentReviewRound->getId() != $decision->getData('reviewRoundId')) {
continue;
}

$decisionType = Repo::decision()->getDecisionType($decision->getData('decision'));
$recommendations[] = [
'decision' => $decision->getData('decision'),
'label' => $decisionType->getLabel(),
'stageId' => $decision->getData('stageId'),
];
}
}
}

Expand All @@ -663,14 +674,18 @@ protected function getPropertyStages(Enumerable $stageAssignments, Submission $s
}
}

if (isset($isDecidingEditorAssigned)) {
$stages[$groupStage->stageId]['isCurrentUserDecidingEditor'] = true;
// Identify data associated with editorial roles
if (!in_array($userGroup->roleId, [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR])) {
continue;
}

if (!$stageAssignment->recommendOnly) {
$isCurrentUserDecidingEditor = $stages[$groupStage->stageId]['isCurrentUserDecidingEditor'] = true;
}

// Identify if the current user gave recommendation
if (
in_array($userGroup->roleId, [Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR]) && // this user is assigned as an editor
!isset($isDecidingEditorAssigned) && // this user only can give recommendations, isn't a deciding editor
$stageAssignment->recommendOnly && // this user only can give recommendations, isn't a deciding editor
in_array($groupStage->stageId, [WORKFLOW_STAGE_ID_EXTERNAL_REVIEW, WORKFLOW_STAGE_ID_INTERNAL_REVIEW]) &&
isset($decisions) && $decisions->isNotEmpty() // only for submissions list
) {
Expand Down Expand Up @@ -721,17 +736,22 @@ protected function getPropertyStages(Enumerable $stageAssignments, Submission $s
}
}

// Set recommendation if current user is a deciding editor
foreach ($stages as $stageId => $stage) {
// Determine if deciding editor is assigned
if ($hasDecidingEditor && $hasRecommendingEditors) {
$stages[$stageId]['isDecidingEditorAssigned'] = true;
}

if (empty($recommendations)) {
break;
}

// Set recommendation if current user is a deciding editor
if (!in_array($stageId, [WORKFLOW_STAGE_ID_EXTERNAL_REVIEW, WORKFLOW_STAGE_ID_INTERNAL_REVIEW])) {
continue;
}

if (!$stage['isCurrentUserDecidingEditor']) {
if (!$isCurrentUserDecidingEditor) {
continue;
}

Expand Down
3 changes: 3 additions & 0 deletions schemas/submission.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"items": {
"type": "object",
"properties": {
"stageId": {
"type": "integer"
},
"id": {
"type": "integer"
},
Expand Down

0 comments on commit 41ed351

Please sign in to comment.