Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkp/pkp-lib#10537 Add available editorial decisions to submission's stages data #1738

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor Author

@taslangraham taslangraham Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$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