log remote user bans

This commit is contained in:
Hendrik L 2024-12-02 14:05:54 +01:00
parent e270bc9a0e
commit f8b5f77421
2 changed files with 26 additions and 26 deletions

View file

@ -24,7 +24,7 @@ from app.activitypub.util import public_key, users_total, active_half_year, acti
user_removed_from_remote_server, create_post, create_post_reply, update_post_reply_from_activity, \
update_post_from_activity, undo_vote, undo_downvote, post_to_page, get_redis_connection, find_reported_object, \
process_report, ensure_domains_match, can_edit, can_delete, remove_data_from_banned_user, resolve_remote_post, \
inform_followers_of_post_update, comment_model_to_json, restore_post_or_comment, ban_local_user, unban_local_user, \
inform_followers_of_post_update, comment_model_to_json, restore_post_or_comment, ban_user, unban_user, \
lock_post, log_incoming_ap, find_community_ap_id, site_ban_remove_data, community_ban_remove_data
from app.utils import gibberish, get_setting, render_template, \
community_membership, ap_datetime, ip_address, can_downvote, \
@ -1180,8 +1180,7 @@ def process_inbox_request(request_json, store_ap_json):
else:
log_incoming_ap(id, APLOG_USERBAN, APLOG_IGNORED, request_json if store_ap_json else None, 'Banned, but content retained')
if blocked.is_local():
ban_local_user(blocker, blocked, community, request_json)
ban_user(blocker, blocked, community, request_json)
return
if request_json['object']['type'] == 'Undo':
@ -1238,8 +1237,7 @@ def process_inbox_request(request_json, store_ap_json):
log_incoming_ap(id, APLOG_USERBAN, APLOG_FAILURE, request_json if store_ap_json else None, 'Does not have permission')
return
if blocked.is_local():
unban_local_user(blocker, blocked, community, request_json)
unban_user(blocker, blocked, community, request_json)
log_incoming_ap(id, APLOG_USERBAN, APLOG_SUCCESS, request_json if store_ap_json else None)
return

View file

@ -1545,7 +1545,7 @@ def community_ban_remove_data(blocker_id, community_id, blocked):
db.session.commit()
def ban_local_user(blocker, blocked, community, request_json):
def ban_user(blocker, blocked, community, request_json):
existing = CommunityBan.query.filter_by(community_id=community.id, user_id=blocked.id).first()
if not existing:
new_ban = CommunityBan(community_id=community.id, user_id=blocked.id, banned_by=blocker.id)
@ -1566,40 +1566,42 @@ def ban_local_user(blocker, blocked, community, request_json):
if community_membership_record:
community_membership_record.is_banned = True
# Notify banned person
notify = Notification(title=shorten_string('You have been banned from ' + community.title),
url=f'/notifications', user_id=blocked.id,
author_id=blocker.id)
db.session.add(notify)
if not current_app.debug: # user.unread_notifications += 1 hangs app if 'user' is the same person
blocked.unread_notifications += 1 # who pressed 'Re-submit this activity'.
if blocked.is_local():
# Notify banned person
notify = Notification(title=shorten_string('You have been banned from ' + community.title),
url=f'/notifications', user_id=blocked.id,
author_id=blocker.id)
db.session.add(notify)
if not current_app.debug: # user.unread_notifications += 1 hangs app if 'user' is the same person
blocked.unread_notifications += 1 # who pressed 'Re-submit this activity'.
# Remove their notification subscription, if any
db.session.query(NotificationSubscription).filter(NotificationSubscription.entity_id == community.id,
NotificationSubscription.user_id == blocked.id,
NotificationSubscription.type == NOTIF_COMMUNITY).delete()
# Remove their notification subscription, if any
db.session.query(NotificationSubscription).filter(NotificationSubscription.entity_id == community.id,
NotificationSubscription.user_id == blocked.id,
NotificationSubscription.type == NOTIF_COMMUNITY).delete()
db.session.commit()
cache.delete_memoized(communities_banned_from, blocked.id)
cache.delete_memoized(joined_communities, blocked.id)
cache.delete_memoized(moderating_communities, blocked.id)
add_to_modlog_activitypub('ban_user', blocker, community_id=community.id, link_text=blocked.display_name(), link=blocked.link(), reason=reason)
add_to_modlog_activitypub('ban_user', blocker, community_id=community.id, link_text=blocked.display_name(), link=f'u/{blocked.link()}', reason=reason)
def unban_local_user(blocker, blocked, community, request_json):
def unban_user(blocker, blocked, community, request_json):
db.session.query(CommunityBan).filter(CommunityBan.community_id == community.id, CommunityBan.user_id == blocked.id).delete()
community_membership_record = CommunityMember.query.filter_by(community_id=community.id, user_id=blocked.id).first()
if community_membership_record:
community_membership_record.is_banned = False
reason = request_json['object']['summary'] if 'summary' in request_json['object'] else ''
# Notify unbanned person
notify = Notification(title=shorten_string('You have been unbanned from ' + community.title),
url=f'/notifications', user_id=blocked.id, author_id=blocker.id)
db.session.add(notify)
if not current_app.debug: # user.unread_notifications += 1 hangs app if 'user' is the same person
blocked.unread_notifications += 1 # who pressed 'Re-submit this activity'.
if blocked.is_local():
# Notify unbanned person
notify = Notification(title=shorten_string('You have been unbanned from ' + community.title),
url=f'/notifications', user_id=blocked.id, author_id=blocker.id)
db.session.add(notify)
if not current_app.debug: # user.unread_notifications += 1 hangs app if 'user' is the same person
blocked.unread_notifications += 1 # who pressed 'Re-submit this activity'.
db.session.commit()
@ -1607,7 +1609,7 @@ def unban_local_user(blocker, blocked, community, request_json):
cache.delete_memoized(joined_communities, blocked.id)
cache.delete_memoized(moderating_communities, blocked.id)
add_to_modlog_activitypub('unban_user', blocker, community_id=community.id, link_text=blocked.display_name(), link=blocked.link(), reason=reason)
add_to_modlog_activitypub('unban_user', blocker, community_id=community.id, link_text=blocked.display_name(), link=f'u/{blocked.link()}', reason=reason)
def lock_post(mod_ap_id, post_id, comments_enabled, request_json):