Streamline ap routes (part 14: remove old code)

This commit is contained in:
freamon 2025-01-08 20:23:11 +00:00
parent 309a016d97
commit f82c2fe9b4

View file

@ -1175,223 +1175,6 @@ def process_inbox_request(request_json, store_ap_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
# Announce is new content and votes that happened on a remote server.
#if request_json['type'] == 'Announce':
# should be able to remove the rest of this, and process the activities above.
# Then for any activities that are both sent direct and Announced, one can be dropped when shared_inbox() checks for dupes
#if request_json['object']['type'] == 'Create' or request_json['object']['type'] == 'Update':
# object_type = request_json['object']['object']['type']
# new_content_types = ['Page', 'Article', 'Link', 'Note', 'Question']
# if object_type in new_content_types: # create or update a post
# process_new_content(user, community, store_ap_json, request_json)
# elif request_json['object']['type'] == 'Update' and request_json['object']['object']['type'] == 'Group':
# # force refresh next time community is heard from
# community.ap_fetched_at = None
# db.session.commit()
# log_incoming_ap(id, APLOG_UPDATE, APLOG_SUCCESS, request_json if store_ap_json else None)
# else:
# log_incoming_ap(id, APLOG_CREATE, APLOG_FAILURE, request_json if store_ap_json else None, 'Unacceptable type (create): ' + object_type)
# return
#if request_json['object']['type'] == 'Delete': # Announced Delete
# if isinstance(request_json['object']['object'], str):
# ap_id = request_json['object']['object'] # lemmy
# else:
# ap_id = request_json['object']['object']['id'] # kbin
# to_delete = find_liked_object(ap_id) # Just for Posts and Replies (User deletes aren't announced)
# if to_delete:
# if to_delete.deleted:
# log_incoming_ap(id, APLOG_DELETE, APLOG_IGNORED, request_json if store_ap_json else None, 'Activity about local content which is already deleted')
# else:
# delete_post_or_comment(user, to_delete, store_ap_json, request_json)
# else:
# log_incoming_ap(id, APLOG_DELETE, APLOG_FAILURE, request_json if store_ap_json else None, 'Delete: cannot find ' + ap_id)
# return
#if request_json['object']['type'] == 'Like' or request_json['object']['type'] == 'EmojiReact': # Announced Upvote
# process_upvote(user, store_ap_json, request_json)
# return
#if request_json['object']['type'] == 'Dislike': # Announced Downvote
# if site.enable_downvotes is False:
# log_incoming_ap(id, APLOG_DISLIKE, APLOG_IGNORED, request_json if store_ap_json else None, 'Dislike ignored because of allow_dislike setting')
# return
# process_downvote(user, store_ap_json, request_json)
# return
#if request_json['object']['type'] == 'Flag': # Announce of reported content
# reported = find_reported_object(request_json['object']['object'])
# if reported:
# process_report(user, reported, request_json['object'])
# log_incoming_ap(id, APLOG_REPORT, APLOG_SUCCESS, request_json if store_ap_json else None)
# else:
# log_incoming_ap(id, APLOG_REPORT, APLOG_IGNORED, request_json if store_ap_json else None, 'Report ignored due to missing content')
# return
#if request_json['object']['type'] == 'Lock': # Announce of post lock
# mod = user
# post_id = request_json['object']['object']
# post = Post.query.filter_by(ap_id=post_id).first()
# reason = request_json['object']['summary'] if 'summary' in request_json['object'] else ''
# if post:
# if post.community.is_moderator(mod) or post.community.is_instance_admin(mod):
# post.comments_enabled = False
# db.session.commit()
# add_to_modlog_activitypub('lock_post', mod, community_id=post.community.id,
# link_text=shorten_string(post.title), link=f'post/{post.id}',
# reason=reason)
# log_incoming_ap(id, APLOG_LOCK, APLOG_SUCCESS, request_json if store_ap_json else None)
# else:
# log_incoming_ap(id, APLOG_LOCK, APLOG_FAILURE, request_json if store_ap_json else None, 'Lock: Does not have permission')
# else:
# log_incoming_ap(id, APLOG_LOCK, APLOG_FAILURE, request_json if store_ap_json else None, 'Lock: post not found')
# return
#if request_json['object']['type'] == 'Add': # Announce of adding mods or stickying a post
# target = request_json['object']['target']
# featured_url = community.ap_featured_url
# moderators_url = community.ap_moderators_url
# if target == featured_url:
# post = Post.query.filter_by(ap_id=request_json['object']['object']).first()
# if post:
# post.sticky = True
# db.session.commit()
# log_incoming_ap(id, APLOG_ADD, APLOG_SUCCESS, request_json if store_ap_json else None)
# else:
# log_incoming_ap(id, APLOG_ADD, APLOG_FAILURE, request_json if store_ap_json else None, 'Cannot find: ' + request_json['object']['object'])
# return
# if target == moderators_url:
# user = find_actor_or_create(request_json['object']['object'])
# if user:
# existing_membership = CommunityMember.query.filter_by(community_id=community.id, user_id=user.id).first()
# if existing_membership:
# existing_membership.is_moderator = True
# else:
# new_membership = CommunityMember(community_id=community.id, user_id=user.id, is_moderator=True)
# db.session.add(new_membership)
# db.session.commit()
# log_incoming_ap(id, APLOG_ADD, APLOG_SUCCESS, request_json if store_ap_json else None)
# else:
# log_incoming_ap(id, APLOG_ADD, APLOG_FAILURE, request_json if store_ap_json else None, 'Cannot find: ' + request_json['object']['object'])
# return
# log_incoming_ap(id, APLOG_ADD, APLOG_FAILURE, request_json if store_ap_json else None, 'Unknown target for Add')
# return
#if request_json['object']['type'] == 'Remove': # Announce of removing mods or unstickying a post
# target = request_json['object']['target']
# featured_url = community.ap_featured_url
# moderators_url = community.ap_moderators_url
# if target == featured_url:
# post = Post.query.filter_by(ap_id=request_json['object']['object']).first()
# if post:
# post.sticky = False
# db.session.commit()
# log_incoming_ap(id, APLOG_REMOVE, APLOG_SUCCESS, request_json if store_ap_json else None)
# else:
# log_incoming_ap(id, APLOG_REMOVE, APLOG_FAILURE, request_json if store_ap_json else None, 'Cannot find: ' + target)
# return
# if target == moderators_url:
# user = find_actor_or_create(request_json['object']['object'], create_if_not_found=False)
# if user:
# existing_membership = CommunityMember.query.filter_by(community_id=community.id, user_id=user.id).first()
# if existing_membership:
# existing_membership.is_moderator = False
# db.session.commit()
# log_incoming_ap(id, APLOG_REMOVE, APLOG_SUCCESS, request_json if store_ap_json else None)
# else:
# log_incoming_ap(id, APLOG_REMOVE, APLOG_FAILURE, request_json if store_ap_json else None, 'Cannot find: ' + request_json['object']['object'])
# return
# log_incoming_ap(id, APLOG_REMOVE, APLOG_FAILURE, request_json if store_ap_json else None, 'Unknown target for Remove')
# return
#if request_json['object']['type'] == 'Block': # Announce of user ban. Mod is banning a user from a community,
# blocker = user # or an admin is banning a user from all the site's communities as part of a site ban
# blocked_ap_id = request_json['object']['object'].lower()
# blocked = User.query.filter_by(ap_profile_id=blocked_ap_id).first()
# if not blocked:
# log_incoming_ap(id, APLOG_USERBAN, APLOG_IGNORED, request_json if store_ap_json else None, 'Does not exist here')
# return
# remove_data = request_json['object']['removeData'] if 'removeData' in request_json['object'] else False
# if not community.is_moderator(blocker) and not community.is_instance_admin(blocker):
# log_incoming_ap(id, APLOG_USERBAN, APLOG_FAILURE, request_json if store_ap_json else None, 'Does not have permission')
# return
# if remove_data == True:
# community_ban_remove_data(blocker.id, community.id, blocked)
# log_incoming_ap(id, APLOG_USERBAN, APLOG_SUCCESS, request_json if store_ap_json else None)
# else:
# log_incoming_ap(id, APLOG_USERBAN, APLOG_IGNORED, request_json if store_ap_json else None, 'Banned, but content retained')
# ban_user(blocker, blocked, community, request_json)
# return
#if request_json['object']['type'] == 'Undo':
#if request_json['object']['object']['type'] == 'Delete': # Announce of undo of Delete
# if isinstance(request_json['object']['object']['object'], str):
# ap_id = request_json['object']['object']['object'] # lemmy
# else:
# ap_id = request_json['object']['object']['object']['id'] # kbin
# restorer = user
# to_restore = find_liked_object(ap_id) # a user or a mod/admin is undoing the delete of a post or reply
# if to_restore:
# if not to_restore.deleted:
# log_incoming_ap(id, APLOG_UNDO_DELETE, APLOG_IGNORED, request_json if store_ap_json else None, 'Content was not deleted')
# else:
# restore_post_or_comment(restorer, to_restore, store_ap_json, request_json)
# else:
# log_incoming_ap(id, APLOG_UNDO_DELETE, APLOG_FAILURE, request_json if store_ap_json else None, 'Undo delete: cannot find ' + ap_id)
# return
#if request_json['object']['object']['type'] == 'Like' or request_json['object']['object']['type'] == 'Dislike': # Announce of undo of upvote or downvote
# post = comment = None
# target_ap_id = request_json['object']['object']['object']
# post_or_comment = undo_vote(comment, post, target_ap_id, user)
# if post_or_comment:
# log_incoming_ap(id, APLOG_UNDO_VOTE, APLOG_SUCCESS, request_json if store_ap_json else None)
# else:
# log_incoming_ap(id, APLOG_UNDO_VOTE, APLOG_FAILURE, request_json if store_ap_json else None, 'Unfound object ' + target_ap_id)
# return
#if request_json['object']['object']['type'] == 'Lock': # Announce of undo of post lock
# mod = user
# post_id = request_json['object']['object']['object']
# post = Post.query.filter_by(ap_id=post_id).first()
# reason = request_json['object']['summary'] if 'summary' in request_json['object'] else ''
# if post:
# if post.community.is_moderator(mod) or post.community.is_instance_admin(mod):
# post.comments_enabled = True
# db.session.commit()
# add_to_modlog_activitypub('unlock_post', mod, community_id=post.community.id,
# link_text=shorten_string(post.title), link=f'post/{post.id}',
# reason=reason)
# log_incoming_ap(id, APLOG_LOCK, APLOG_SUCCESS, request_json if store_ap_json else None)
# else:
# log_incoming_ap(id, APLOG_LOCK, APLOG_FAILURE, request_json if store_ap_json else None, 'Lock: Does not have permission')
# else:
# log_incoming_ap(id, APLOG_LOCK, APLOG_FAILURE, request_json if store_ap_json else None, 'Lock: post not found')
# return
#if request_json['object']['object']['type'] == 'Block': # Announce of undo of user ban. Mod is unbanning a user from a community,
# blocker = user # or an admin is unbanning a user from all the site's communities as part of a site unban
# blocked_ap_id = request_json['object']['object']['object'].lower()
# blocked = User.query.filter_by(ap_profile_id=blocked_ap_id).first()
# if not blocked:
# log_incoming_ap(id, APLOG_USERBAN, APLOG_IGNORED, request_json if store_ap_json else None, 'Does not exist here')
# return
# if not community.is_moderator(blocker) and not community.is_instance_admin(blocker):
# log_incoming_ap(id, APLOG_USERBAN, APLOG_FAILURE, request_json if store_ap_json else None, 'Does not have permission')
# return
# unban_user(blocker, blocked, community, request_json)
# log_incoming_ap(id, APLOG_USERBAN, APLOG_SUCCESS, request_json if store_ap_json else None)
# return
log_incoming_ap(id, APLOG_MONITOR, APLOG_PROCESSING, request_json, 'Unmatched activity') log_incoming_ap(id, APLOG_MONITOR, APLOG_PROCESSING, request_json, 'Unmatched activity')