]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
models: change edit permissions for comments
authorRaxel Gutierrez <raxel@google.com>
Fri, 20 Aug 2021 04:50:26 +0000 (04:50 +0000)
committerDaniel Axtens <dja@axtens.net>
Mon, 23 Aug 2021 08:54:20 +0000 (18:54 +1000)
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>
Signed-off-by: Daniel Axtens <dja@axtens.net>
patchwork/models.py

index 90e34815e37c9eeb7fc128bfcd8c3cf8d9e44c5e..58e4c51e971607b5f1ce30c0e9ff210fa1267dd0 100644 (file)
@@ -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']