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 #796

Merged
merged 2 commits into from
Oct 26, 2024
Merged
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
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) {
Copy link
Contributor Author

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 ($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;
}
}