Skip to content

Commit

Permalink
pkp#10263 Relax editing metadata on published/posted materials
Browse files Browse the repository at this point in the history
  • Loading branch information
Hafsa-Naeem committed Aug 26, 2024
1 parent edeb709 commit 611fa20
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 34 deletions.
38 changes: 4 additions & 34 deletions api/v1/submissions/PKPSubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
use PKP\submission\PKPSubmission;
use PKP\submission\reviewAssignment\ReviewAssignment;
use PKP\userGroup\UserGroup;
use PKP\observers\events\MetadataChanged;


class PKPSubmissionController extends PKPBaseController
{
Expand Down Expand Up @@ -1100,13 +1102,6 @@ public function editPublication(Request $illuminateRequest): JsonResponse
], Response::HTTP_FORBIDDEN);
}

// Publications can not be edited when they are published
if ($publication->getData('status') === PKPSubmission::STATUS_PUBLISHED) {
return response()->json([
'error' => __('api.publication.403.cantEditPublished'),
], Response::HTTP_FORBIDDEN);
}

// Prevent users from editing publications if they do not have permission. Except for admins.
$userRoles = $this->getAuthorizedContextObject(Application::ASSOC_TYPE_USER_ROLES);
if (!in_array(Role::ROLE_ID_SITE_ADMIN, $userRoles) && !Repo::submission()->canEditPublication($submission->getId(), $currentUser->getId())) {
Expand Down Expand Up @@ -1139,6 +1134,8 @@ public function editPublication(Request $illuminateRequest): JsonResponse

Repo::publication()->edit($publication, $params);
$publication = Repo::publication()->get($publication->getId());
event(new MetadataChanged($submission));


$userGroups = Repo::userGroup()->getCollector()
->filterByContextIds([$submission->getData('contextId')])
Expand Down Expand Up @@ -1400,13 +1397,6 @@ public function addContributor(Request $illuminateRequest): JsonResponse
], Response::HTTP_FORBIDDEN);
}

// Publications can not be edited when they are published
if ($publication->getData('status') === PKPSubmission::STATUS_PUBLISHED) {
return response()->json([
'error' => __('api.publication.403.cantEditPublished'),
], Response::HTTP_FORBIDDEN);
}

$params = $this->convertStringsToSchema(PKPSchemaService::SCHEMA_AUTHOR, $illuminateRequest->input());
$params['publicationId'] = $publication->getId();

Expand Down Expand Up @@ -1449,12 +1439,6 @@ public function deleteContributor(Request $illuminateRequest): JsonResponse
], Response::HTTP_NOT_FOUND);
}

// Publications can not be edited when they are published
if ($publication->getData('status') === PKPSubmission::STATUS_PUBLISHED) {
return response()->json([
'error' => __('api.publication.403.cantEditPublished'),
], Response::HTTP_FORBIDDEN);
}

if ($submission->getId() !== $publication->getData('submissionId')) {
return response()->json([
Expand Down Expand Up @@ -1511,13 +1495,6 @@ public function editContributor(Request $illuminateRequest): JsonResponse
], Response::HTTP_FORBIDDEN);
}

// Publications can not be edited when they are published
if ($publication->getData('status') === PKPSubmission::STATUS_PUBLISHED) {
return response()->json([
'error' => __('api.publication.403.cantEditPublished'),
], Response::HTTP_FORBIDDEN);
}

$params = $this->convertStringsToSchema(PKPSchemaService::SCHEMA_AUTHOR, $illuminateRequest->input());
$params['id'] = $author->getId();

Expand Down Expand Up @@ -1580,13 +1557,6 @@ public function saveContributorsOrder(Request $illuminateRequest): JsonResponse
], Response::HTTP_FORBIDDEN);
}

// Publications can not be edited when they are published
if ($publication->getData('status') === PKPSubmission::STATUS_PUBLISHED) {
return response()->json([
'error' => __('api.publication.403.cantEditPublished'),
], Response::HTTP_FORBIDDEN);
}

if (!empty($params['sortedAuthors'])) {
$authors = [];
foreach ($params['sortedAuthors'] as $author) {
Expand Down
5 changes: 5 additions & 0 deletions classes/task/PublishSubmissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
use APP\submission\Submission;
use PKP\core\Core;
use PKP\scheduledTask\ScheduledTask;
use PKP\observers\events\MetadataChanged;


class PublishSubmissions extends ScheduledTask
{
Expand Down Expand Up @@ -50,6 +52,9 @@ public function executeActions(): bool
$datePublished = $submission->getCurrentPublication()->getData('datePublished');
if ($datePublished && strtotime($datePublished) <= strtotime(Core::getCurrentDate())) {
Repo::publication()->publish($submission->getCurrentPublication());

// dispatch the MetadataChanged event after publishing
event(new MetadataChanged($submission));
}
}
}
Expand Down

0 comments on commit 611fa20

Please sign in to comment.