🔒(backend) prevent admins from rewriting other users comments

Admins/owners could overwrite another user's comment text and silently
take ownership of it.
Split write permissions: destroy stays broad (author + admin/owner) for
moderation.
    
Signed-off-by: Mohamed El Amine BOUKERFA <boukerfa.ma@gmail.com>
This commit is contained in:
Amine BOUKERFA
2026-05-26 10:26:31 +02:00
committed by GitHub
parent 8d42f814b7
commit 3264e29941
7 changed files with 33 additions and 28 deletions
+5
View File
@@ -3004,6 +3004,11 @@ class CommentViewSet(
context["thread_id"] = self.kwargs["thread_id"]
return context
def perform_create(self, serializer):
"""Attach the request user as the comment author."""
user = self.request.user if self.request.user.is_authenticated else None
serializer.save(user=user)
@drf.decorators.action(
detail=True,
methods=["post", "delete"],