From f1ddbcf008c727fadef600822f241a7a91f63265 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Mon, 14 Oct 2024 12:35:24 +1300 Subject: [PATCH] populate deleted_by field --- app/activitypub/util.py | 3 +++ app/admin/routes.py | 1 + app/post/routes.py | 2 ++ app/user/routes.py | 4 ++++ 4 files changed, 10 insertions(+) diff --git a/app/activitypub/util.py b/app/activitypub/util.py index 294719df..33e71395 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -1315,6 +1315,7 @@ def delete_post_or_comment_task(user_ap_id, community_ap_id, to_be_deleted_ap_id to_delete.deleted = True community.post_count -= 1 to_delete.author.post_count -= 1 + to_delete.deleted_by = deletor.id db.session.commit() if to_delete.author.id != deletor.id: add_to_modlog_activitypub('delete_post', deletor, community_id=community.id, @@ -1329,6 +1330,7 @@ def delete_post_or_comment_task(user_ap_id, community_ap_id, to_be_deleted_ap_id to_delete.delete_dependencies() to_delete.deleted = True to_delete.author.post_reply_count -= 1 + to_delete.deleted_by = deletor.id db.session.commit() if to_delete.author.id != deletor.id: add_to_modlog_activitypub('delete_post_reply', deletor, community_id=community.id, @@ -1354,6 +1356,7 @@ def restore_post_or_comment_task(object_json): if isinstance(to_restore, Post): # TODO: restore_dependencies() to_restore.deleted = False + to_restore.deleted_by = None community.post_count += 1 to_restore.author.post_count += 1 db.session.commit() diff --git a/app/admin/routes.py b/app/admin/routes.py index 7f029fa9..7985d73a 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -1206,6 +1206,7 @@ def admin_user_delete(user_id): user.banned = True # Unsubscribing everyone could take a long time so until that is completed hide this user from the UI by banning it. user.last_active = utcnow() + user.deleted_by = current_user.id db.session.commit() if user.is_local(): diff --git a/app/post/routes.py b/app/post/routes.py index eb09185f..47f5fc77 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -1016,6 +1016,7 @@ def post_delete_post(community: Community, post: Post, user_id: int, federate_al ocp.cross_posts.remove(post.id) post.delete_dependencies() post.deleted = True + post.deleted_by = user_id post.author.post_count -= 1 community.post_count -= 1 if hasattr(g, 'site'): # g.site is invalid when running from cli @@ -1606,6 +1607,7 @@ def post_reply_delete(post_id: int, comment_id: int): if not post_reply.author.bot: post.reply_count -= 1 post_reply.author.post_reply_count -= 1 + post_reply.deleted_by = current_user.id db.session.commit() flash(_('Comment deleted.')) # federate delete diff --git a/app/user/routes.py b/app/user/routes.py index 1ff279c3..270c6d68 100644 --- a/app/user/routes.py +++ b/app/user/routes.py @@ -667,6 +667,7 @@ def delete_profile(actor): else: user.banned = True user.deleted = True + user.deleted_by = current_user.id user.delete_dependencies() db.session.commit() @@ -728,6 +729,7 @@ def delete_account(): # to verify the deletes, remote servers will GET /u/ so we can't fully delete the account until the POSTs are done current_user.banned = True current_user.email = f'deleted_{current_user.id}@deleted.com' + current_user.deleted_by = current_user.id db.session.commit() if current_app.debug: @@ -803,10 +805,12 @@ def ban_purge_profile(actor): # federate deletion if user.is_local(): + user.deleted_by = current_user.id purge_user_then_delete(user.id) flash(f'{actor} has been banned, deleted and all their content deleted. This might take a few minutes.') else: user.deleted = True + user.deleted_by = current_user.id user.delete_dependencies() user.purge_content() db.session.commit()