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

Raxel Gutierrez raxel at google.com
Fri Aug 20 14:50:26 AEST 2021


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 at google.com>
---
 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.33.0.rc2.250.ged5fa647cd-goog



More information about the Patchwork mailing list