diff --git a/hypha/apply/activity/migrations/0082_change_staff_pii_visibility.py b/hypha/apply/activity/migrations/0082_change_staff_pii_visibility.py index d9cd3c3f06..d58e1529d3 100644 --- a/hypha/apply/activity/migrations/0082_change_staff_pii_visibility.py +++ b/hypha/apply/activity/migrations/0082_change_staff_pii_visibility.py @@ -4,7 +4,7 @@ import re from hypha.apply.activity.adapters.activity_feed import ActivityAdapter -from hypha.apply.activity.models import TEAM, Activity +from hypha.apply.activity.models import TEAM from hypha.apply.activity.options import MESSAGES @@ -27,6 +27,7 @@ def change_updatelead_visibility(apps, schema_editor): ActivityAdapter.messages[MESSAGES.UNARCHIVE_SUBMISSION], ] + Activity = apps.get_model("activity", "Activity") staff_identity_set = Activity.objects.none() for message in lead_messages: diff --git a/hypha/apply/activity/migrations/0088_activity_deleted.py b/hypha/apply/activity/migrations/0088_activity_deleted.py new file mode 100644 index 0000000000..02e95ff85c --- /dev/null +++ b/hypha/apply/activity/migrations/0088_activity_deleted.py @@ -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), + ), + ] diff --git a/hypha/apply/activity/models.py b/hypha/apply/activity/models.py index 99addde1f7..c3d8cae455 100644 --- a/hypha/apply/activity/models.py +++ b/hypha/apply/activity/models.py @@ -216,6 +216,7 @@ class Activity(models.Model): # Fields for handling versioning of the comment activity models edited = models.DateTimeField(default=None, null=True) + deleted = models.DateTimeField(default=None, null=True) current = models.BooleanField(default=True) previous = models.ForeignKey("self", on_delete=models.CASCADE, null=True) diff --git a/hypha/apply/activity/services.py b/hypha/apply/activity/services.py index 7806ab4483..1eff7ae1c9 100644 --- a/hypha/apply/activity/services.py +++ b/hypha/apply/activity/services.py @@ -37,6 +37,33 @@ def edit_comment(activity: Activity, message: str) -> Activity: return activity +def delete_comment(activity: Activity) -> Activity: + """ + Soft delete a comment by creating a clone of the original comment with a delete message. + + Args: + activity (Activity): The original comment activity to be soft deleted. + + Returns: + Activity: The soft deleted comment activitye. + """ + + # Create a clone of the comment to soft delete + previous = Activity.objects.get(pk=activity.pk) + previous.pk = None + previous.current = False + previous.save() + + activity.previous = previous + activity.deleted = timezone.now() + activity.edited = None + activity.message = "" + activity.current = True + activity.save() + + return activity + + def get_related_activities_for_user(obj, user): """Return comments/communications related to an object, esp. useful with ApplicationSubmission and Project. diff --git a/hypha/apply/activity/templates/activity/partial_comment_message.html b/hypha/apply/activity/templates/activity/partial_comment_message.html index dd2e3808b7..60583b2294 100644 --- a/hypha/apply/activity/templates/activity/partial_comment_message.html +++ b/hypha/apply/activity/templates/activity/partial_comment_message.html @@ -1,11 +1,15 @@ -{% load heroicons activity_tags nh3_tags markdown_tags submission_tags apply_tags users_tags %} +{% load i18n heroicons activity_tags nh3_tags markdown_tags submission_tags apply_tags users_tags %}