Merge pull request 'Update community deletion modlog entry' (#287) from JollyDevelopment/pyfedi:jollydev/fix-delete-community-modlog-break into main

Reviewed-on: https://codeberg.org/rimu/pyfedi/pulls/287
This commit is contained in:
rimu 2024-08-12 08:05:02 +00:00
commit 407c80931d
2 changed files with 10 additions and 3 deletions

View file

@ -425,12 +425,16 @@ def admin_community_edit(community_id):
def admin_community_delete(community_id): def admin_community_delete(community_id):
community = Community.query.get_or_404(community_id) community = Community.query.get_or_404(community_id)
community.banned = True # Unsubscribing everyone could take a long time so until that is completed hide this community from the UI by banning it. community.banned = True # Unsubscribing everyone could take a long time so until that is completed hide this community from the UI by banning it.
community.last_active = utcnow() community.last_active = utcnow()
db.session.commit() db.session.commit()
unsubscribe_everyone_then_delete(community.id) unsubscribe_everyone_then_delete(community.id)
reason = f"Community {community.name} deleted by {current_user.user_name}"
add_to_modlog('delete_community', reason=reason)
flash(_('Community deleted')) flash(_('Community deleted'))
return redirect(url_for('admin.admin_communities')) return redirect(url_for('admin.admin_communities'))

View file

@ -951,13 +951,16 @@ def community_delete(community_id: int):
if community.is_local(): if community.is_local():
community.banned = True community.banned = True
# todo: federate deletion out to all instances. At end of federation process, delete_dependencies() and delete community # todo: federate deletion out to all instances. At end of federation process, delete_dependencies() and delete community
# record for modlog
reason = f"Community {community.name} deleted by {current_user.user_name}"
add_to_modlog('delete_community', reason=reason)
# actually delete the community
community.delete_dependencies() community.delete_dependencies()
db.session.delete(community) db.session.delete(community)
db.session.commit() db.session.commit()
add_to_modlog('delete_community', community_id=community.id, link_text=community.display_name(),
link=community.link())
flash(_('Community deleted')) flash(_('Community deleted'))
return redirect('/communities') return redirect('/communities')