changeset 7424:0ac1aaccd19c

controllers: align pullrequests.delete_comment with changeset.delete_comment This commit purely serves to highlight the differences. The subsequent commit will remove the duplication.
author Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
date Fri, 19 Oct 2018 22:02:55 +0200
parents 5a958556bc9c
children c6207df9841f
files kallithea/controllers/changeset.py kallithea/controllers/pullrequests.py
diffstat 2 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/changeset.py	Tue Nov 20 21:22:43 2018 +0100
+++ b/kallithea/controllers/changeset.py	Fri Oct 19 22:02:55 2018 +0200
@@ -399,10 +399,14 @@
     @LoginRequired()
     @HasRepoPermissionLevelDecorator('read')
     @jsonify
-    def delete_comment(self, repo_name, comment_id):
+    def delete_comment(self, repo_name, comment_id, pr_comment=False):
         co = ChangesetComment.get_or_404(comment_id)
         if co.repo.repo_name != repo_name:
             raise HTTPNotFound()
+        if pr_comment and co.pull_request.is_closed():
+            # don't allow deleting comments on closed pull request
+            raise HTTPForbidden()
+
         owner = co.author_id == request.authuser.user_id
         repo_admin = h.HasRepoPermissionLevel('admin')(repo_name)
         if h.HasPermissionAny('hg.admin')() or repo_admin or owner:
--- a/kallithea/controllers/pullrequests.py	Tue Nov 20 21:22:43 2018 +0100
+++ b/kallithea/controllers/pullrequests.py	Fri Oct 19 22:02:55 2018 +0200
@@ -716,13 +716,15 @@
     @HasRepoPermissionLevelDecorator('read')
     @jsonify
     def delete_comment(self, repo_name, comment_id):
-        co = ChangesetComment.get(comment_id)
+        co = ChangesetComment.get_or_404(comment_id)
+        if co.repo.repo_name != repo_name:
+            raise HTTPNotFound()
         if co.pull_request.is_closed():
             # don't allow deleting comments on closed pull request
             raise HTTPForbidden()
 
         owner = co.author_id == request.authuser.user_id
-        repo_admin = h.HasRepoPermissionLevel('admin')(c.repo_name)
+        repo_admin = h.HasRepoPermissionLevel('admin')(repo_name)
         if h.HasPermissionAny('hg.admin')() or repo_admin or owner:
             ChangesetCommentsModel().delete(comment=co)
             Session().commit()