mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-24 03:43:42 -08:00
log remote user bans
This commit is contained in:
parent
e270bc9a0e
commit
f8b5f77421
2 changed files with 26 additions and 26 deletions
|
@ -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, \
|
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, \
|
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, \
|
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
|
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, \
|
from app.utils import gibberish, get_setting, render_template, \
|
||||||
community_membership, ap_datetime, ip_address, can_downvote, \
|
community_membership, ap_datetime, ip_address, can_downvote, \
|
||||||
|
@ -1180,8 +1180,7 @@ def process_inbox_request(request_json, store_ap_json):
|
||||||
else:
|
else:
|
||||||
log_incoming_ap(id, APLOG_USERBAN, APLOG_IGNORED, request_json if store_ap_json else None, 'Banned, but content retained')
|
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_user(blocker, blocked, community, request_json)
|
||||||
ban_local_user(blocker, blocked, community, request_json)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if request_json['object']['type'] == 'Undo':
|
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')
|
log_incoming_ap(id, APLOG_USERBAN, APLOG_FAILURE, request_json if store_ap_json else None, 'Does not have permission')
|
||||||
return
|
return
|
||||||
|
|
||||||
if blocked.is_local():
|
unban_user(blocker, blocked, community, request_json)
|
||||||
unban_local_user(blocker, blocked, community, request_json)
|
|
||||||
log_incoming_ap(id, APLOG_USERBAN, APLOG_SUCCESS, request_json if store_ap_json else None)
|
log_incoming_ap(id, APLOG_USERBAN, APLOG_SUCCESS, request_json if store_ap_json else None)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -1545,7 +1545,7 @@ def community_ban_remove_data(blocker_id, community_id, blocked):
|
||||||
db.session.commit()
|
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()
|
existing = CommunityBan.query.filter_by(community_id=community.id, user_id=blocked.id).first()
|
||||||
if not existing:
|
if not existing:
|
||||||
new_ban = CommunityBan(community_id=community.id, user_id=blocked.id, banned_by=blocker.id)
|
new_ban = CommunityBan(community_id=community.id, user_id=blocked.id, banned_by=blocker.id)
|
||||||
|
@ -1566,6 +1566,7 @@ def ban_local_user(blocker, blocked, community, request_json):
|
||||||
if community_membership_record:
|
if community_membership_record:
|
||||||
community_membership_record.is_banned = True
|
community_membership_record.is_banned = True
|
||||||
|
|
||||||
|
if blocked.is_local():
|
||||||
# Notify banned person
|
# Notify banned person
|
||||||
notify = Notification(title=shorten_string('You have been banned from ' + community.title),
|
notify = Notification(title=shorten_string('You have been banned from ' + community.title),
|
||||||
url=f'/notifications', user_id=blocked.id,
|
url=f'/notifications', user_id=blocked.id,
|
||||||
|
@ -1584,16 +1585,17 @@ def ban_local_user(blocker, blocked, community, request_json):
|
||||||
cache.delete_memoized(joined_communities, blocked.id)
|
cache.delete_memoized(joined_communities, blocked.id)
|
||||||
cache.delete_memoized(moderating_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()
|
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()
|
community_membership_record = CommunityMember.query.filter_by(community_id=community.id, user_id=blocked.id).first()
|
||||||
if community_membership_record:
|
if community_membership_record:
|
||||||
community_membership_record.is_banned = False
|
community_membership_record.is_banned = False
|
||||||
reason = request_json['object']['summary'] if 'summary' in request_json['object'] else ''
|
reason = request_json['object']['summary'] if 'summary' in request_json['object'] else ''
|
||||||
|
|
||||||
|
if blocked.is_local():
|
||||||
# Notify unbanned person
|
# Notify unbanned person
|
||||||
notify = Notification(title=shorten_string('You have been unbanned from ' + community.title),
|
notify = Notification(title=shorten_string('You have been unbanned from ' + community.title),
|
||||||
url=f'/notifications', user_id=blocked.id, author_id=blocker.id)
|
url=f'/notifications', user_id=blocked.id, author_id=blocker.id)
|
||||||
|
@ -1607,7 +1609,7 @@ def unban_local_user(blocker, blocked, community, request_json):
|
||||||
cache.delete_memoized(joined_communities, blocked.id)
|
cache.delete_memoized(joined_communities, blocked.id)
|
||||||
cache.delete_memoized(moderating_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):
|
def lock_post(mod_ap_id, post_id, comments_enabled, request_json):
|
||||||
|
|
Loading…
Add table
Reference in a new issue