From 9c8906150a782cd2a9996f6f60d129a7323b8043 Mon Sep 17 00:00:00 2001 From: Raxel Gutierrez Date: Fri, 20 Aug 2021 04:50:26 +0000 Subject: [PATCH] models: change edit permissions for comments Change patch comments' edit permissions to match that of the patch associated with the comment (i.e. patch author, project maintainers, and delegate) and add permissions for both patch and cover comment authors to be able to change the `addressed` status of comments as well. For cover comments, add permissions to edit for cover submitter and project maintainers. Signed-off-by: Raxel Gutierrez Signed-off-by: Daniel Axtens --- patchwork/models.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/patchwork/models.py b/patchwork/models.py index 90e34815..58e4c51e 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -675,6 +675,20 @@ class CoverComment(EmailMixin, models.Model): return reverse('comment-redirect', kwargs={'comment_id': self.id}) def is_editable(self, user): + if not user.is_authenticated: + return False + + # user submitted comment + if user == self.submitter.user: + return True + + # user submitted cover letter + if user == self.cover.submitter.user: + return True + + # user is project maintainer + if self.cover.project.is_editable(user): + return True return False class Meta: @@ -720,7 +734,9 @@ class PatchComment(EmailMixin, models.Model): self.patch.refresh_tag_counts() def is_editable(self, user): - return False + if user == self.submitter.user: + return True + return self.patch.is_editable(user) class Meta: ordering = ['date'] -- 2.47.3