Skip to content

pkp/pkp-lib#11389 Validate contributor user group role is author before allowing add or edit in API #11412

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

Open
wants to merge 2 commits into
base: stable-3_5_0
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions api/v1/submissions/PKPSubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,16 @@ public function addContributor(Request $illuminateRequest): JsonResponse
$submissionContext = app()->get('context')->get($submission->getData('contextId'));
}

// validate that the supplied group is an AUTHOR group
if (isset($params['userGroupId'])) {
$userGroup = Repo::userGroup()->get($params['userGroupId']);
if (!$userGroup || $userGroup->roleId !== Role::ROLE_ID_AUTHOR) {
return response()->json([
'userGroupId' => [__('submission.upload.invalidUserGroup')]
], Response::HTTP_BAD_REQUEST);
}
}

$errors = Repo::author()->validate(null, $params, $submission, $submissionContext);

if (!empty($errors)) {
Expand Down Expand Up @@ -1685,6 +1695,13 @@ public function editContributor(Request $illuminateRequest): JsonResponse
], Response::HTTP_FORBIDDEN);
}

$userGroup = Repo::userGroup()->get($params['userGroupId']);
if (!$userGroup || $userGroup->roleId !== Role::ROLE_ID_AUTHOR) {
return response()->json([
'userGroupId' => [__('submission.upload.invalidUserGroup')]
], Response::HTTP_BAD_REQUEST);
}

$errors = Repo::author()->validate($author, $params, $submission, $submissionContext);

if (!empty($errors)) {
Expand Down