diff --git a/hypha/apply/funds/forms.py b/hypha/apply/funds/forms.py index 4ed149714b6aa11d1cc99603b55afaa82d807f17..ed280143099856aaf6e11bb9e85da14d455086e5 100644 --- a/hypha/apply/funds/forms.py +++ b/hypha/apply/funds/forms.py @@ -253,10 +253,12 @@ class UpdateReviewersForm(ApplicationSubmissionModelForm): def can_alter_external_reviewers(self, instance, user): if instance.stage.has_external_review: + if user.is_superuser: + return True if settings.GIVE_STAFF_LEAD_PERMS: - return user.is_apply_staff or user.is_superuser + return user.is_apply_staff else: - return user == instance.lead or user.is_superuser + return user == instance.lead return False def clean(self): @@ -355,7 +357,7 @@ class BatchUpdateReviewersForm(forms.Form): submissions = self.cleaned_data['submissions'] if external_reviewers: # User needs to be superuser or lead of all selected submissions. - if self.user_cant_alter_submissions_external_reviewers(submissions, self.user): + if not self.user_can_alter_submissions_external_reviewers(submissions, self.user): self.add_error('external_reviewers', _("Only Lead can change the External Reviewers")) # If user is trying to change the external reviewers for submissions that doesn't have workflow with external_review stage. elif self.submissions_cant_have_external_reviewers(submissions): @@ -379,12 +381,14 @@ class BatchUpdateReviewersForm(forms.Form): return True return False - def user_cant_alter_submissions_external_reviewers(self, submissions, user): - for submission in submissions: - if settings.GIVE_STAFF_LEAD_PERMS: - return user != submission.lead and not user.is_superuser - else: - return not user.is_apply_staff and not user.is_superuser + def user_can_alter_submissions_external_reviewers(self, submissions, user): + # User needs to be superuser or lead of all selected submissions. + if user.is_superuser: + return True + if settings.GIVE_STAFF_LEAD_PERMS and user.is_apply_staff: + return True + if submissions.count() == submissions.filter(lead=user).count(): + return True return False def save(self):