Skip to content

Commit

Permalink
pkp/pkp-lib#10537 Add available editorial decisions to submission's s…
Browse files Browse the repository at this point in the history
…tages data
  • Loading branch information
taslangraham authored Oct 26, 2024
2 parents 6ace27d + 6ae7432 commit c39fcd6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
50 changes: 50 additions & 0 deletions classes/submission/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}
}

0 comments on commit c39fcd6

Please sign in to comment.