1- from django .contrib .auth .decorators import login_required
1+ from django .contrib .auth .decorators import login_required , user_passes_test
22from django .core .exceptions import PermissionDenied
33from django .core .paginator import Paginator
44from django .shortcuts import get_object_or_404 , render
88from rolepermissions .checkers import has_object_permission
99
1010from hypha .apply .funds .models .submissions import ApplicationSubmission
11- from hypha .apply .users .decorators import staff_required
11+ from hypha .apply .users .decorators import is_apply_staff , staff_required
1212from hypha .apply .utils .storage import PrivateMediaView
1313
1414from . import services
@@ -59,6 +59,9 @@ def edit_comment(request, pk):
5959 if activity .type != COMMENT or activity .user != request .user :
6060 raise PermissionError ("You can only edit your own comments" )
6161
62+ if activity .deleted :
63+ raise PermissionError ("You can not edit a deleted comment" )
64+
6265 if request .GET .get ("action" ) == "cancel" :
6366 return render (
6467 request ,
@@ -78,6 +81,34 @@ def edit_comment(request, pk):
7881 return render (request , "activity/ui/edit_comment_form.html" , {"activity" : activity })
7982
8083
84+ @login_required
85+ @user_passes_test (is_apply_staff )
86+ def delete_comment (request , pk ):
87+ """Soft delete a comment."""
88+ activity = get_object_or_404 (Activity , id = pk )
89+
90+ if activity .type != COMMENT or activity .user != request .user :
91+ raise PermissionError ("You can only delete your own comments" )
92+
93+ if activity .deleted :
94+ raise PermissionError ("You can not delete a deleted comment" )
95+
96+ if request .method == "DELETE" :
97+ activity = services .delete_comment (activity )
98+
99+ return render (
100+ request ,
101+ "activity/ui/activity-comment-item.html" ,
102+ {"activity" : activity , "success" : True },
103+ )
104+
105+ return render (
106+ request ,
107+ "activity/ui/activity-comment-item.html" ,
108+ {"activity" : activity },
109+ )
110+
111+
81112class ActivityContextMixin :
82113 """Mixin to add related 'comments' of the current view's 'self.object'"""
83114
0 commit comments