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 a222a1d + 378c2b9 commit c1079c5
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
93 changes: 93 additions & 0 deletions classes/submission/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,27 @@
namespace APP\submission\maps;

use APP\core\Application;
use APP\decision\types\Accept;
use APP\decision\types\SkipExternalReview;
use APP\facades\Repo;
use APP\submission\Submission;
use Illuminate\Support\Collection;
use PKP\db\DAORegistry;
use PKP\decision\DecisionType;
use PKP\decision\types\BackFromCopyediting;
use PKP\decision\types\BackFromProduction;
use PKP\decision\types\CancelReviewRound;
use PKP\decision\types\Decline;
use PKP\decision\types\InitialDecline;
use PKP\decision\types\RequestRevisions;
use PKP\decision\types\RevertDecline;
use PKP\decision\types\RevertInitialDecline;
use PKP\decision\types\SendExternalReview;
use PKP\decision\types\SendToProduction;
use PKP\plugins\Hook;
use PKP\security\Role;
use PKP\submission\PKPSubmission;
use PKP\submission\reviewRound\ReviewRoundDAO;

class Schema extends \PKP\submission\maps\Schema
{
Expand Down Expand Up @@ -62,4 +80,79 @@ protected function appSpecificProps(): array
'scheduledIn',
];
}


/**
* 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;
$permissions = $this->checkDecisionPermissions($stageId, $submission, $user, $request->getContext()->getId());
$userHasAccessibleRoles = $user->hasRole([Role::ROLE_ID_SUB_EDITOR, Role::ROLE_ID_MANAGER, Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_ASSISTANT], $request->getContext()->getId());

if (!$userHasAccessibleRoles || !$isActiveStage || !$permissions['canMakeDecision']) {
return [];
}

$decisionTypes = []; /** @var DecisionType[] $decisionTypes */
$isOnlyRecommending = $permissions['isOnlyRecommending'];

if ($isOnlyRecommending && $stageId == WORKFLOW_STAGE_ID_SUBMISSION) {
$decisionTypes[] = Repo::decision()->getDecisionTypesMadeByRecommendingUsers($stageId);
} else {
switch ($stageId) {
case WORKFLOW_STAGE_ID_SUBMISSION:
$decisionTypes = [
new SendExternalReview(),
new SkipExternalReview(),
];
if ($submission->getData('status') === Submission::STATUS_DECLINED) {
$decisionTypes[] = new RevertInitialDecline();
} elseif ($submission->getData('status') === Submission::STATUS_QUEUED) {
$decisionTypes[] = new InitialDecline();
}
break;
case WORKFLOW_STAGE_ID_EXTERNAL_REVIEW:
$decisionTypes = [
new RequestRevisions(),
new Accept(),
];
$cancelReviewRound = new CancelReviewRound();
$reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO'); /** @var ReviewRoundDAO $reviewRoundDao */
$reviewRound = $reviewRoundDao->getLastReviewRoundBySubmissionId($submission->getId(), $stageId);

if ($cancelReviewRound->canRetract($submission, $reviewRound->getId())) {
$decisionTypes[] = $cancelReviewRound;
}
if ($submission->getData('status') === Submission::STATUS_DECLINED) {
$decisionTypes[] = new RevertDecline();
} elseif ($submission->getData('status') === Submission::STATUS_QUEUED) {
$decisionTypes[] = new Decline();
}
break;
case WORKFLOW_STAGE_ID_EDITING:
$decisionTypes = [
new SendToProduction(),
new BackFromCopyediting(),
];
break;
case WORKFLOW_STAGE_ID_PRODUCTION:
$decisionTypes[] = new BackFromProduction();
break;
}
}

Hook::call('Workflow::Decisions', [&$decisionTypes, $stageId]);

return $decisionTypes;
}
}
2 changes: 1 addition & 1 deletion lib/pkp

0 comments on commit c1079c5

Please sign in to comment.