@@ -515,36 +515,31 @@ public function canCurrentUserDelete(Submission $submission): bool
515
515
public function canEditPublication (int $ submissionId , int $ userId ): bool
516
516
{
517
517
// 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 ])
538
519
->withUserId ($ userId )
539
520
->get ();
540
521
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 )) {
543
538
return true ;
544
539
}
545
540
// If user has no stage assigments, check if user can edit anyway ie. is manager
546
541
$ context = Application::get ()->getRequest ()->getContext ();
547
- if ($ stageAssignments ->isEmpty () && $ this ->_canUserAccessUnassignedSubmissions ($ context ->getId (), $ userId )) {
542
+ if ($ assignments ->isEmpty () && $ this ->_canUserAccessUnassignedSubmissions ($ context ->getId (), $ userId )) {
548
543
return true ;
549
544
}
550
545
// Else deny access
0 commit comments