Streamline ap routes (part 08: deletes)

This commit is contained in:
freamon 2025-01-08 18:28:27 +00:00
parent 63495dd5d9
commit 9dc1589783
2 changed files with 27 additions and 23 deletions

View file

@ -839,18 +839,20 @@ def process_inbox_request(request_json, store_ap_json):
log_incoming_ap(id, APLOG_CREATE, APLOG_FAILURE, request_json if store_ap_json else None, 'Unacceptable type (create): ' + object_type) log_incoming_ap(id, APLOG_CREATE, APLOG_FAILURE, request_json if store_ap_json else None, 'Unacceptable type (create): ' + object_type)
return return
if request_json['type'] == 'Delete': if core_activity['type'] == 'Delete':
if isinstance(request_json['object'], str): if isinstance(core_activity['object'], str):
ap_id = request_json['object'] # lemmy ap_id = core_activity['object'] # lemmy
else: else:
ap_id = request_json['object']['id'] # kbin ap_id = core_activity['object']['id'] # kbin
to_delete = find_liked_object(ap_id) # Just for Posts and Replies (User deletes go through process_delete_request()) to_delete = find_liked_object(ap_id) # Just for Posts and Replies (User deletes go through process_delete_request())
if to_delete: if to_delete:
if to_delete.deleted: 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') 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: else:
delete_post_or_comment(user, to_delete, store_ap_json, request_json) reason = core_activity['summary'] if 'summary' in core_activity else ''
delete_post_or_comment(user, to_delete, store_ap_json, request_json, reason)
if not announced:
announce_activity_to_followers(to_delete.community, user, request_json) announce_activity_to_followers(to_delete.community, user, request_json)
else: else:
log_incoming_ap(id, APLOG_DELETE, APLOG_FAILURE, request_json if store_ap_json else None, 'Delete: cannot find ' + ap_id) log_incoming_ap(id, APLOG_DELETE, APLOG_FAILURE, request_json if store_ap_json else None, 'Delete: cannot find ' + ap_id)
@ -1141,21 +1143,21 @@ def process_inbox_request(request_json, store_ap_json):
log_incoming_ap(id, APLOG_CREATE, APLOG_FAILURE, request_json if store_ap_json else None, 'Unacceptable type (create): ' + object_type) log_incoming_ap(id, APLOG_CREATE, APLOG_FAILURE, request_json if store_ap_json else None, 'Unacceptable type (create): ' + object_type)
return return
if request_json['object']['type'] == 'Delete': # Announced Delete #if request_json['object']['type'] == 'Delete': # Announced Delete
if isinstance(request_json['object']['object'], str): # if isinstance(request_json['object']['object'], str):
ap_id = request_json['object']['object'] # lemmy # ap_id = request_json['object']['object'] # lemmy
else: # else:
ap_id = request_json['object']['object']['id'] # kbin # 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) # to_delete = find_liked_object(ap_id) # Just for Posts and Replies (User deletes aren't announced)
if to_delete: # if to_delete:
if to_delete.deleted: # 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') # 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: # else:
delete_post_or_comment(user, to_delete, store_ap_json, request_json) # delete_post_or_comment(user, to_delete, store_ap_json, request_json)
else: # else:
log_incoming_ap(id, APLOG_DELETE, APLOG_FAILURE, request_json if store_ap_json else None, 'Delete: cannot find ' + ap_id) # log_incoming_ap(id, APLOG_DELETE, APLOG_FAILURE, request_json if store_ap_json else None, 'Delete: cannot find ' + ap_id)
return # return
#if request_json['object']['type'] == 'Like' or request_json['object']['type'] == 'EmojiReact': # Announced Upvote #if request_json['object']['type'] == 'Like' or request_json['object']['type'] == 'EmojiReact': # Announced Upvote
# process_upvote(user, store_ap_json, request_json) # process_upvote(user, store_ap_json, request_json)

View file

@ -1303,11 +1303,13 @@ def is_activitypub_request():
return 'application/ld+json' in request.headers.get('Accept', '') or 'application/activity+json' in request.headers.get('Accept', '') return 'application/ld+json' in request.headers.get('Accept', '') or 'application/activity+json' in request.headers.get('Accept', '')
def delete_post_or_comment(deletor, to_delete, store_ap_json, request_json): def delete_post_or_comment(deletor, to_delete, store_ap_json, request_json, reason):
id = request_json['id'] id = request_json['id']
community = to_delete.community community = to_delete.community
reason = request_json['object']['summary'] if 'summary' in request_json['object'] else '' if (to_delete.user_id == deletor.id or
if to_delete.user_id == deletor.id or deletor.is_admin() or community.is_moderator(deletor) or community.is_instance_admin(deletor): (deletor.instance_id == to_delete.author.instance_id and deletor.is_instance_admin()) or
community.is_moderator(deletor) or
community.is_instance_admin(deletor)):
if isinstance(to_delete, Post): if isinstance(to_delete, Post):
to_delete.deleted = True to_delete.deleted = True
to_delete.deleted_by = deletor.id to_delete.deleted_by = deletor.id