-
Notifications
You must be signed in to change notification settings - Fork 39
Allow staff to delete their own comments. #4705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Generated by Django 5.2.11 on 2026-02-18 14:46 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("activity", "0087_alter_event_type"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="activity", | ||
| name="deleted", | ||
| field=models.DateTimeField(default=None, null=True), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||||||||||||||||||||
| from django.contrib.auth.decorators import login_required | ||||||||||||||||||||||||||||
| from django.contrib.auth.decorators import login_required, user_passes_test | ||||||||||||||||||||||||||||
| from django.core.exceptions import PermissionDenied | ||||||||||||||||||||||||||||
| from django.core.paginator import Paginator | ||||||||||||||||||||||||||||
| from django.shortcuts import get_object_or_404, render | ||||||||||||||||||||||||||||
|
|
@@ -8,7 +8,7 @@ | |||||||||||||||||||||||||||
| from rolepermissions.checkers import has_object_permission | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| from hypha.apply.funds.models.submissions import ApplicationSubmission | ||||||||||||||||||||||||||||
| from hypha.apply.users.decorators import staff_required | ||||||||||||||||||||||||||||
| from hypha.apply.users.decorators import is_apply_staff, staff_required | ||||||||||||||||||||||||||||
| from hypha.apply.utils.storage import PrivateMediaView | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| from . import services | ||||||||||||||||||||||||||||
|
|
@@ -59,6 +59,9 @@ def edit_comment(request, pk): | |||||||||||||||||||||||||||
| if activity.type != COMMENT or activity.user != request.user: | ||||||||||||||||||||||||||||
| raise PermissionError("You can only edit your own comments") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if activity.deleted: | ||||||||||||||||||||||||||||
| raise PermissionError("You can not edit a deleted comment") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if request.GET.get("action") == "cancel": | ||||||||||||||||||||||||||||
| return render( | ||||||||||||||||||||||||||||
| request, | ||||||||||||||||||||||||||||
|
|
@@ -78,6 +81,34 @@ def edit_comment(request, pk): | |||||||||||||||||||||||||||
| return render(request, "activity/ui/edit_comment_form.html", {"activity": activity}) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| @login_required | ||||||||||||||||||||||||||||
| @user_passes_test(is_apply_staff) | ||||||||||||||||||||||||||||
| def delete_comment(request, pk): | ||||||||||||||||||||||||||||
| """Soft delete a comment.""" | ||||||||||||||||||||||||||||
| activity = get_object_or_404(Activity, id=pk) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if activity.type != COMMENT or activity.user != request.user: | ||||||||||||||||||||||||||||
| raise PermissionError("You can only delete your own comments") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if activity.deleted: | ||||||||||||||||||||||||||||
| raise PermissionError("You can not delete a deleted comment") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if request.method == "DELETE": | ||||||||||||||||||||||||||||
| activity = services.delete_comment(activity) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return render( | ||||||||||||||||||||||||||||
| request, | ||||||||||||||||||||||||||||
| "activity/ui/activity-comment-item.html", | ||||||||||||||||||||||||||||
| {"activity": activity, "success": True}, | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
|
Comment on lines
+99
to
+103
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are your thoughts on this:
Suggested change
Combined with a new listener in comments.html Just so the comment auto-updates and tosses the delete/edit buttons on delete
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! I have now set target to comment item instead of comment text to get this result. This has the same result but we do not need to reload all activities. |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return render( | ||||||||||||||||||||||||||||
| request, | ||||||||||||||||||||||||||||
| "activity/ui/activity-comment-item.html", | ||||||||||||||||||||||||||||
| {"activity": activity}, | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| class ActivityContextMixin: | ||||||||||||||||||||||||||||
| """Mixin to add related 'comments' of the current view's 'self.object'""" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never use the model directly in a migration. If you later on add fields etc. the migrations will fail. Instead use
get_model()like above.