Skip to content

Commit c475464

Browse files
committed
#10263 block authors from editing any version if a submission has a published or scheduled publication
1 parent d26aa0f commit c475464

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed

classes/submission/Repository.php

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -515,36 +515,31 @@ public function canCurrentUserDelete(Submission $submission): bool
515515
public function canEditPublication(int $submissionId, int $userId): bool
516516
{
517517
// block authors can never edit a published publication even if an editor granted them canChangeMetadata
518-
$submission = $this->get($submissionId);
519-
if ($submission) {
520-
$currentPub = $submission->getCurrentPublication();
521-
if (
522-
$currentPub
523-
&& $currentPub->getData('status') === Submission::STATUS_PUBLISHED
524-
) {
525-
// fetch this user’s stage assignments
526-
$assignments = StageAssignment::withSubmissionIds([$submissionId])->withUserId($userId)->get();
527-
528-
// if all of their assignments are to an author group then block them
529-
$hasNonAuthor = $assignments->contains(fn($sa) => $sa->userGroup && $sa->userGroup->roleId !== Role::ROLE_ID_AUTHOR);
530-
if (!$hasNonAuthor) {
531-
return false;
532-
}
533-
}
534-
}
535-
536-
// Replaces StageAssignmentDAO::getBySubmissionAndUserIdAndStageId
537-
$stageAssignments = StageAssignment::withSubmissionIds([$submissionId])
518+
$assignments = StageAssignment::withSubmissionIds([$submissionId])
538519
->withUserId($userId)
539520
->get();
540521

541-
// Check for permission from stage assignments
542-
if ($stageAssignments->contains(fn ($stageAssignment) => $stageAssignment->canChangeMetadata)) {
522+
$submission = $this->get($submissionId);
523+
// any published or scheduled then probe
524+
$hasLockedPublication = $submission
525+
&& $submission->getData('publications')
526+
->contains(fn($p) =>
527+
in_array(
528+
$p->getData('status'),
529+
[Submission::STATUS_PUBLISHED, Submission::STATUS_SCHEDULED]
530+
)
531+
);
532+
533+
if ($hasLockedPublication && !$assignments->contains(fn($sa) => $sa->userGroup && $sa->userGroup->roleId !== Role::ROLE_ID_AUTHOR)) {
534+
return false;
535+
}
536+
537+
if ($assignments->contains(fn($sa) => $sa->canChangeMetadata)) {
543538
return true;
544539
}
545540
// If user has no stage assigments, check if user can edit anyway ie. is manager
546541
$context = Application::get()->getRequest()->getContext();
547-
if ($stageAssignments->isEmpty() && $this->_canUserAccessUnassignedSubmissions($context->getId(), $userId)) {
542+
if ($assignments->isEmpty() && $this->_canUserAccessUnassignedSubmissions($context->getId(), $userId)) {
548543
return true;
549544
}
550545
// Else deny access

classes/task/PublishSubmissions.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ public function executeActions(): bool
5252
$datePublished = $submission->getCurrentPublication()->getData('datePublished');
5353
if ($datePublished && strtotime($datePublished) <= strtotime(Core::getCurrentDate())) {
5454
Repo::publication()->publish($submission->getCurrentPublication());
55-
56-
// dispatch the MetadataChanged event after publishing
57-
event(new MetadataChanged($submission));
55+
// dispatch the MetadataChanged event after publishing
56+
event(new MetadataChanged($submission));
5857
}
5958
}
6059
}

0 commit comments

Comments
 (0)