Skip to content

Commit d637aeb

Browse files
committed
pkp#10929 Assign Author role to user's without access to submission stage when creating a submission
1 parent 38709e1 commit d637aeb

File tree

2 files changed

+48
-41
lines changed

2 files changed

+48
-41
lines changed

api/v1/submissions/PKPSubmissionController.php

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ public function add(Request $illuminateRequest): JsonResponse
620620
} elseif ($submitterUserGroups->count()) {
621621
$submitAsUserGroup = $submitterUserGroups
622622
->sort(function (UserGroup $a, UserGroup $b) {
623-
return $a->getRoleId() === Role::ROLE_ID_AUTHOR ? 1 : -1;
623+
return $a->roleId === Role::ROLE_ID_AUTHOR ? -1 : 1;
624624
})
625625
->first();
626626
} else {
@@ -664,37 +664,37 @@ public function add(Request $illuminateRequest): JsonResponse
664664
: $submitAsUserGroup->permitMetadataEdit
665665
);
666666

667-
// Production Editor group has Managerial role but is not assigned to submission stage.
667+
// Production Editor group has Managerial role but is not assigned to submission stage.
668668
$isManager = $submitAsUserGroup->roleId === Role::ROLE_ID_MANAGER && !$request->getUser()->hasRole([Role::ROLE_ID_SITE_ADMIN], \PKP\core\PKPApplication::SITE_CONTEXT_ID);
669-
$stagesAssignedToGroup = $isManager ? Repo::userGroup()->getAssignedStagesByUserGroupId($context->getId(), $submitAsUserGroup->id) : collect();
670-
$isSubmittingAsProductionEditor = $isManager && !$stagesAssignedToGroup->contains(WORKFLOW_STAGE_ID_SUBMISSION);
671-
// Temporary solution for https://github.com/pkp/pkp-lib/issues/10929
672-
// If submitting as Production Editor, then also assign as Author to allow full access to submission stage
673-
if ($isSubmittingAsProductionEditor) {
674-
$authorGroup = Repo::userGroup()->getByRoleIds([Role::ROLE_ID_AUTHOR], $context->getId())->first();
675-
676-
// Assign author role to user if not already assigned
677-
if (!$submitterUserGroups->contains('roleId', Role::ROLE_ID_AUTHOR)) {
678-
Repo::userGroup()->assignUserToGroup(
679-
$user->getId(),
680-
$authorGroup->id
681-
);
682-
}
683-
684-
// Assign Production Editor to submission as an Author to allow access to submission stage operations
685-
Repo::stageAssignment()
686-
->build(
687-
$submission->getId(),
688-
$authorGroup->id,
689-
$request->getUser()->getId(),
690-
$authorGroup->recommendOnly,
691-
// Authors can always edit metadata before submitting
692-
true
693-
);
694-
}
669+
// $stagesAssignedToGroup = $isManager ? Repo::userGroup()->getAssignedStagesByUserGroupId($context->getId(), $submitAsUserGroup->id) : collect();
670+
// $isSubmittingAsProductionEditor = $isManager && !$stagesAssignedToGroup->contains(WORKFLOW_STAGE_ID_SUBMISSION);
671+
// // Temporary solution for https://github.com/pkp/pkp-lib/issues/10929
672+
// // If submitting as Production Editor, then also assign as Author to allow full access to submission stage
673+
// if ($isSubmittingAsProductionEditor) {
674+
// $authorGroup = Repo::userGroup()->getByRoleIds([Role::ROLE_ID_AUTHOR], $context->getId())->first();
675+
//
676+
// // Assign author role to user if not already assigned
677+
// if (!$submitterUserGroups->contains('roleId', Role::ROLE_ID_AUTHOR)) {
678+
// Repo::userGroup()->assignUserToGroup(
679+
// $user->getId(),
680+
// $authorGroup->id
681+
// );
682+
// }
683+
//
684+
// // Assign Production Editor to submission as an Author to allow access to submission stage operations
685+
// Repo::stageAssignment()
686+
// ->build(
687+
// $submission->getId(),
688+
// $authorGroup->id,
689+
// $request->getUser()->getId(),
690+
// $authorGroup->recommendOnly,
691+
// // Authors can always edit metadata before submitting
692+
// true
693+
// );
694+
// }
695695

696696
// Create an author record from the submitter's user account
697-
if ($submitAsUserGroup->roleId === Role::ROLE_ID_AUTHOR || $isSubmittingAsProductionEditor) {
697+
if ($submitAsUserGroup->roleId === Role::ROLE_ID_AUTHOR) {
698698
$author = Repo::author()->newAuthorFromUser($request->getUser(), $submission, $context);
699699
$author->setData('publicationId', $publication->getId());
700700
$author->setUserGroupId($submitAsUserGroup->id);

pages/submission/PKPSubmissionHandler.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ protected function showWizard(array $args, Request $request, Submission $submiss
232232
}
233233

234234
$userRoles = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_USER_ROLES);
235-
235+
236236
$templateMgr = TemplateManager::getManager($request);
237237
$templateMgr->setState([
238238
'categories' => Repo::category()->getBreadcrumbs($categories),
@@ -614,22 +614,29 @@ protected function getReviewerSuggestionsListPanel(
614614
*/
615615
protected function getSubmitUserGroups(Context $context, User $user): Collection
616616
{
617-
$userGroups = UserGroup::query()
618-
->withContextIds([$context->getId()])
619-
->withUserIds([$user->getId()])
620-
->withRoleIds([Role::ROLE_ID_MANAGER, Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_AUTHOR])
621-
->get();
617+
$request = Application::get()->getRequest();
618+
$isAdmin = $request->getUser()->hasRole([Role::ROLE_ID_SITE_ADMIN], \PKP\core\PKPApplication::SITE_CONTEXT_ID);
619+
$query = UserGroup::query()->withContextIds([$context->getId()])->withUserIds([$user->getId()]);
622620

623-
// Users without a submitting role can submit as an
624-
// author role that allows self registration
621+
$userGroups = $isAdmin
622+
? $query >withRoleIds([Role::ROLE_ID_MANAGER, Role::ROLE_ID_SITE_ADMIN])->get()
623+
: $query->withStageIds([WORKFLOW_STAGE_ID_SUBMISSION])->get(); // For non-admin users, query for the groups tht give them access to the submission stage
624+
625+
// Users without a submitting role or access to submission stage can submit as an
626+
// author role that allows self registration.
627+
// They are also assigned the author role
625628
if ($userGroups->isEmpty()) {
629+
Repo::userGroup()->assignUserToGroup(
630+
$user->getId(),
631+
Repo::userGroup()->getByRoleIds([Role::ROLE_ID_AUTHOR], $context->getId())->first()->id
632+
);
626633
$defaultUserGroup = UserGroup::withContextIds([$context->getId()])
627-
->withRoleIds([Role::ROLE_ID_AUTHOR])
628-
->permitSelfRegistration(true)
629-
->first();
634+
->withRoleIds([Role::ROLE_ID_AUTHOR])
635+
->permitSelfRegistration(true)
636+
->first();
630637

631638
$userGroups = collect($defaultUserGroup ? [$defaultUserGroup->id => $defaultUserGroup] : []);
632-
}
639+
}
633640

634641
return $userGroups;
635642
}

0 commit comments

Comments
 (0)