|
77 | 77 | use PKP\submission\reviewAssignment\ReviewAssignment; |
78 | 78 | use PKP\submissionFile\SubmissionFile; |
79 | 79 | use PKP\userGroup\UserGroup; |
| 80 | +use PKP\observers\events\MetadataChanged; |
| 81 | +use PKP\stageAssignment\StageAssignment; |
| 82 | + |
80 | 83 |
|
81 | 84 | class PKPSubmissionController extends PKPBaseController |
82 | 85 | { |
@@ -1337,16 +1340,12 @@ public function editPublication(Request $illuminateRequest): JsonResponse |
1337 | 1340 | ], Response::HTTP_FORBIDDEN); |
1338 | 1341 | } |
1339 | 1342 |
|
1340 | | - // Publications can not be edited when they are published |
1341 | | - if ($publication->getData('status') === PKPPublication::STATUS_PUBLISHED) { |
1342 | | - return response()->json([ |
1343 | | - 'error' => __('api.publication.403.cantEditPublished'), |
1344 | | - ], Response::HTTP_FORBIDDEN); |
1345 | | - } |
1346 | | - |
1347 | | - // Prevent users from editing publications if they do not have permission. Except for admins. |
| 1343 | + // only proceed if user is allowed to edit publications |
1348 | 1344 | $userRoles = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_USER_ROLES); |
1349 | | - if (!in_array(Role::ROLE_ID_SITE_ADMIN, $userRoles) && !Repo::submission()->canEditPublication($submission->getId(), $currentUser->getId())) { |
| 1345 | + if ( |
| 1346 | + !in_array(Role::ROLE_ID_SITE_ADMIN, $userRoles) && |
| 1347 | + !Repo::submission()->canEditPublication($submission->getId(), $currentUser->getId()) |
| 1348 | + ) { |
1350 | 1349 | return response()->json([ |
1351 | 1350 | 'error' => __('api.submissions.403.userCantEdit'), |
1352 | 1351 | ], Response::HTTP_FORBIDDEN); |
@@ -1396,6 +1395,8 @@ public function editPublication(Request $illuminateRequest): JsonResponse |
1396 | 1395 |
|
1397 | 1396 | Repo::publication()->edit($publication, $params); |
1398 | 1397 | $publication = Repo::publication()->get($publication->getId()); |
| 1398 | + event(new MetadataChanged($submission)); |
| 1399 | + |
1399 | 1400 |
|
1400 | 1401 | $userGroups = UserGroup::withContextIds($submission->getData('contextId'))->cursor(); |
1401 | 1402 |
|
@@ -1455,6 +1456,17 @@ public function publishPublication(Request $illuminateRequest): JsonResponse |
1455 | 1456 |
|
1456 | 1457 | Repo::publication()->publish($publication); |
1457 | 1458 |
|
| 1459 | + $stageAssignments = StageAssignment::withSubmissionIds([$submission->getId()]) |
| 1460 | + ->get(); |
| 1461 | + |
| 1462 | + foreach ($stageAssignments as $stageAssignment) { |
| 1463 | + $userGroup = $stageAssignment->userGroup; |
| 1464 | + if ($userGroup && $userGroup->roleId === Role::ROLE_ID_AUTHOR){ |
| 1465 | + $stageAssignment->canChangeMetadata = 0; |
| 1466 | + $stageAssignment->save(); |
| 1467 | + } |
| 1468 | + } |
| 1469 | + |
1458 | 1470 | $publication = Repo::publication()->get($publication->getId()); |
1459 | 1471 |
|
1460 | 1472 | $userGroups = UserGroup::withContextIds($submission->getData('contextId'))->cursor(); |
@@ -1745,12 +1757,6 @@ public function deleteContributor(Request $illuminateRequest): JsonResponse |
1745 | 1757 | ], Response::HTTP_NOT_FOUND); |
1746 | 1758 | } |
1747 | 1759 |
|
1748 | | - // Publications can not be edited when they are published |
1749 | | - if ($publication->getData('status') === PKPPublication::STATUS_PUBLISHED) { |
1750 | | - return response()->json([ |
1751 | | - 'error' => __('api.publication.403.cantEditPublished'), |
1752 | | - ], Response::HTTP_FORBIDDEN); |
1753 | | - } |
1754 | 1760 |
|
1755 | 1761 | if ($submission->getId() !== $publication->getData('submissionId')) { |
1756 | 1762 | return response()->json([ |
@@ -1807,13 +1813,6 @@ public function editContributor(Request $illuminateRequest): JsonResponse |
1807 | 1813 | ], Response::HTTP_FORBIDDEN); |
1808 | 1814 | } |
1809 | 1815 |
|
1810 | | - // Publications can not be edited when they are published |
1811 | | - if ($publication->getData('status') === PKPPublication::STATUS_PUBLISHED) { |
1812 | | - return response()->json([ |
1813 | | - 'error' => __('api.publication.403.cantEditPublished'), |
1814 | | - ], Response::HTTP_FORBIDDEN); |
1815 | | - } |
1816 | | - |
1817 | 1816 | $params = $this->convertStringsToSchema(PKPSchemaService::SCHEMA_AUTHOR, $illuminateRequest->input()); |
1818 | 1817 | $params['id'] = $author->getId(); |
1819 | 1818 |
|
@@ -1900,13 +1899,6 @@ public function saveContributorsOrder(Request $illuminateRequest): JsonResponse |
1900 | 1899 | ], Response::HTTP_FORBIDDEN); |
1901 | 1900 | } |
1902 | 1901 |
|
1903 | | - // Publications can not be edited when they are published |
1904 | | - if ($publication->getData('status') === PKPPublication::STATUS_PUBLISHED) { |
1905 | | - return response()->json([ |
1906 | | - 'error' => __('api.publication.403.cantEditPublished'), |
1907 | | - ], Response::HTTP_FORBIDDEN); |
1908 | | - } |
1909 | | - |
1910 | 1902 | if (!empty($params['sortedAuthors'])) { |
1911 | 1903 | $authors = []; |
1912 | 1904 | foreach ($params['sortedAuthors'] as $author) { |
|
0 commit comments