diff --git a/classes/submission/maps/Schema.php b/classes/submission/maps/Schema.php index d27c2bbf3a..54bed79bae 100644 --- a/classes/submission/maps/Schema.php +++ b/classes/submission/maps/Schema.php @@ -14,8 +14,14 @@ namespace APP\submission\maps; use APP\core\Application; +use APP\decision\types\Decline; +use APP\decision\types\RevertDecline; +use APP\facades\Repo; use APP\submission\Submission; use Illuminate\Support\Collection; +use PKP\decision\DecisionType; +use PKP\plugins\Hook; +use PKP\security\Role; class Schema extends \PKP\submission\maps\Schema { @@ -48,4 +54,48 @@ protected function mapByProperties(array $props, Submission $submission, bool|Co return $this->withExtensions($output, $submission); } + + + /** + * Gets the Editorial decisions available to editors for a given stage of a submission + * + * This method returns decisions only for active stages. For inactive stages, it returns an empty array. + * + * @return DecisionType[] + * + * @hook Workflow::Decisions [[&$decisionTypes, $stageId]] + */ + protected function getAvailableEditorialDecisions(int $stageId, Submission $submission): array + { + $request = Application::get()->getRequest(); + $user = $request->getUser(); + $isActiveStage = $submission->getData('stageId') == $stageId; + $userHasAccessibleRoles = $user->hasRole([Role::ROLE_ID_SUB_EDITOR, Role::ROLE_ID_MANAGER, Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_ASSISTANT], $request->getContext()->getId()); + $permissions = $this->checkDecisionPermissions($stageId, $submission, $user, $request->getContext()->getId()); + + /** Only the production stage is supported in OPS.*/ + if ($stageId !== WORKFLOW_STAGE_ID_PRODUCTION || !$userHasAccessibleRoles || !$isActiveStage || !$permissions['canMakeDecision']) { + return []; + } + + $isOnlyRecommending = $permissions['isOnlyRecommending']; + $decisionTypes = []; /** @var DecisionType[] $decisionTypes */ + + if ($isOnlyRecommending) { + $decisionTypes[] = Repo::decision()->getDecisionTypesMadeByRecommendingUsers($stageId); + } else { + switch ($submission->getData('status')) { + case Submission::STATUS_DECLINED: + $decisionTypes[] = new RevertDecline(); + break; + case Submission::STATUS_QUEUED: + $decisionTypes[] = new Decline(); + break; + } + } + + Hook::call('Workflow::Decisions', [&$decisionTypes, $stageId]); + + return $decisionTypes; + } } diff --git a/lib/pkp b/lib/pkp index 6882fa48c8..af501d2e3d 160000 --- a/lib/pkp +++ b/lib/pkp @@ -1 +1 @@ -Subproject commit 6882fa48c8bc68992843ab07d010bd6303f77d4d +Subproject commit af501d2e3d0bcec2b0b57986349bc1280f21b6dc