diff --git a/app/activitypub/routes.py b/app/activitypub/routes.py index 319b05d6..e5a7ccb2 100644 --- a/app/activitypub/routes.py +++ b/app/activitypub/routes.py @@ -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 diff --git a/app/activitypub/util.py b/app/activitypub/util.py index 55bc4f8f..583543ce 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -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):