diff mbox series

[v4,5/9] models: change edit permissions for comments

Message ID 20210820045030.3364156-6-raxel@google.com
State Accepted
Headers show
Series patch-detail: add unaddressed/addressed status to patch comments | expand

Commit Message

Raxel Gutierrez Aug. 20, 2021, 4:50 a.m. UTC
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 <raxel@google.com>
---
 patchwork/models.py | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
diff mbox series

Patch

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']