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 97b3337 + d3fe7ac commit b94c061
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 1 deletion.
119 changes: 119 additions & 0 deletions classes/submission/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,34 @@
namespace APP\submission\maps;

use APP\core\Application;
use APP\decision\types\AcceptFromInternal;
use APP\decision\types\CancelInternalReviewRound;
use APP\decision\types\DeclineInternal;
use APP\decision\types\RequestRevisionsInternal;
use APP\decision\types\RevertDeclineInternal;
use APP\decision\types\SendExternalReview;
use APP\decision\types\SendInternalReview;
use APP\decision\types\SkipInternalReview;
use APP\facades\Repo;
use APP\press\FeatureDAO;
use APP\press\NewReleaseDAO;
use APP\submission\Submission;
use Illuminate\Support\Collection;
use PKP\db\DAORegistry;
use PKP\decision\DecisionType;
use PKP\decision\types\Accept;
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\SendToProduction;
use PKP\decision\types\SkipExternalReview;
use PKP\plugins\Hook;
use PKP\security\Role;
use PKP\submission\reviewRound\ReviewRound;
use PKP\submission\reviewRound\ReviewRoundDAO;

Expand Down Expand Up @@ -103,4 +126,100 @@ protected function getReviewRoundsFromSubmission(Submission $submission): Collec
return collect($reviewRoundDao->getBySubmissionId($submission->getId())->toIterator())
->groupBy(fn (ReviewRound $reviewRound) => $reviewRound->getData('round'));
}

/**
* 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 */

$reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO'); /** @var ReviewRoundDAO $reviewRoundDao */
$reviewRound = $reviewRoundDao->getLastReviewRoundBySubmissionId($submission->getId(), $stageId);

$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 SkipInternalReview(),
new SkipExternalReview(),
];

if ($submission->getData('status') === Submission::STATUS_DECLINED) {
$decisionTypes[] = new RevertInitialDecline();
} elseif ($submission->getData('status') === Submission::STATUS_QUEUED) {
$decisionTypes[] = new InitialDecline();
}
$decisionTypes[] = new SendInternalReview();
break;
case WORKFLOW_STAGE_ID_INTERNAL_REVIEW:
$decisionTypes = [
new RequestRevisionsInternal(),
new SendExternalReview(),
new AcceptFromInternal(),
];
$cancelInternalReviewRound = new CancelInternalReviewRound();

if ($cancelInternalReviewRound->canRetract($submission, $reviewRound->getId())) {
$decisionTypes[] = $cancelInternalReviewRound;
}

if ($submission->getData('status') === Submission::STATUS_DECLINED) {
$decisionTypes[] = new RevertDeclineInternal();
} elseif ($submission->getData('status') === Submission::STATUS_QUEUED) {
$decisionTypes[] = new DeclineInternal();
}
break;
case WORKFLOW_STAGE_ID_EXTERNAL_REVIEW:
$decisionTypes = [
new RequestRevisions(),
new Accept(),
];

$cancelReviewRound = new CancelReviewRound();
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 b94c061

Please sign in to comment.