mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
Streamline ap routes (part 10: undo deletes)
This commit is contained in:
parent
e640ab7ed8
commit
e8b2861d88
2 changed files with 29 additions and 25 deletions
|
@ -1049,7 +1049,7 @@ 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
|
||||||
|
|
||||||
if request_json['type'] == 'Undo':
|
if core_activity['type'] == 'Undo':
|
||||||
if request_json['object']['type'] == 'Follow': # Unsubscribe from a community or user
|
if request_json['object']['type'] == 'Follow': # Unsubscribe from a community or user
|
||||||
target_ap_id = request_json['object']['object']
|
target_ap_id = request_json['object']['object']
|
||||||
target = find_actor_or_create(target_ap_id, create_if_not_found=False)
|
target = find_actor_or_create(target_ap_id, create_if_not_found=False)
|
||||||
|
@ -1079,11 +1079,11 @@ def process_inbox_request(request_json, store_ap_json):
|
||||||
log_incoming_ap(id, APLOG_UNDO_FOLLOW, APLOG_FAILURE, request_json if store_ap_json else None, 'Unfound target')
|
log_incoming_ap(id, APLOG_UNDO_FOLLOW, APLOG_FAILURE, request_json if store_ap_json else None, 'Unfound target')
|
||||||
return
|
return
|
||||||
|
|
||||||
if request_json['object']['type'] == 'Delete': # Restore something previously deleted
|
if core_activity['object']['type'] == 'Delete': # Restore something previously deleted
|
||||||
if isinstance(request_json['object']['object'], str):
|
if isinstance(core_activity['object']['object'], str):
|
||||||
ap_id = request_json['object']['object'] # lemmy
|
ap_id = core_activity['object']['object'] # lemmy
|
||||||
else:
|
else:
|
||||||
ap_id = request_json['object']['object']['id'] # kbin
|
ap_id = core_activity['object']['object']['id'] # kbin
|
||||||
|
|
||||||
restorer = user
|
restorer = user
|
||||||
to_restore = find_liked_object(ap_id) # a user or a mod/admin is undoing the delete of a post or reply
|
to_restore = find_liked_object(ap_id) # a user or a mod/admin is undoing the delete of a post or reply
|
||||||
|
@ -1091,8 +1091,10 @@ def process_inbox_request(request_json, store_ap_json):
|
||||||
if not to_restore.deleted:
|
if not to_restore.deleted:
|
||||||
log_incoming_ap(id, APLOG_UNDO_DELETE, APLOG_IGNORED, request_json if store_ap_json else None, 'Activity about local content which is already restored')
|
log_incoming_ap(id, APLOG_UNDO_DELETE, APLOG_IGNORED, request_json if store_ap_json else None, 'Activity about local content which is already restored')
|
||||||
else:
|
else:
|
||||||
restore_post_or_comment(restorer, to_restore, store_ap_json, request_json)
|
reason = core_activity['object']['summary'] if 'summary' in core_activity['object'] else ''
|
||||||
announce_activity_to_followers(to_restore.community, user, request_json)
|
restore_post_or_comment(restorer, to_restore, store_ap_json, request_json, reason)
|
||||||
|
if not announced:
|
||||||
|
announce_activity_to_followers(to_restore.community, user, request_json)
|
||||||
else:
|
else:
|
||||||
log_incoming_ap(id, APLOG_UNDO_DELETE, APLOG_FAILURE, request_json if store_ap_json else None, 'Undo delete: cannot find ' + ap_id)
|
log_incoming_ap(id, APLOG_UNDO_DELETE, APLOG_FAILURE, request_json if store_ap_json else None, 'Undo delete: cannot find ' + ap_id)
|
||||||
return
|
return
|
||||||
|
@ -1284,22 +1286,22 @@ def process_inbox_request(request_json, store_ap_json):
|
||||||
# return
|
# return
|
||||||
|
|
||||||
if request_json['object']['type'] == 'Undo':
|
if request_json['object']['type'] == 'Undo':
|
||||||
if request_json['object']['object']['type'] == 'Delete': # Announce of undo of Delete
|
#if request_json['object']['object']['type'] == 'Delete': # Announce of undo of Delete
|
||||||
if isinstance(request_json['object']['object']['object'], str):
|
# if isinstance(request_json['object']['object']['object'], str):
|
||||||
ap_id = request_json['object']['object']['object'] # lemmy
|
# ap_id = request_json['object']['object']['object'] # lemmy
|
||||||
else:
|
# else:
|
||||||
ap_id = request_json['object']['object']['object']['id'] # kbin
|
# ap_id = request_json['object']['object']['object']['id'] # kbin
|
||||||
|
|
||||||
restorer = user
|
# restorer = user
|
||||||
to_restore = find_liked_object(ap_id) # a user or a mod/admin is undoing the delete of a post or reply
|
# 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 to_restore:
|
||||||
if not to_restore.deleted:
|
# 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')
|
# log_incoming_ap(id, APLOG_UNDO_DELETE, APLOG_IGNORED, request_json if store_ap_json else None, 'Content was not deleted')
|
||||||
else:
|
# else:
|
||||||
restore_post_or_comment(restorer, to_restore, store_ap_json, request_json)
|
# restore_post_or_comment(restorer, to_restore, store_ap_json, request_json)
|
||||||
else:
|
# else:
|
||||||
log_incoming_ap(id, APLOG_UNDO_DELETE, APLOG_FAILURE, request_json if store_ap_json else None, 'Undo delete: cannot find ' + ap_id)
|
# log_incoming_ap(id, APLOG_UNDO_DELETE, APLOG_FAILURE, request_json if store_ap_json else None, 'Undo delete: cannot find ' + ap_id)
|
||||||
return
|
# return
|
||||||
|
|
||||||
if request_json['object']['object']['type'] == 'Like' or request_json['object']['object']['type'] == 'Dislike': # Announce of undo of upvote or downvote
|
if request_json['object']['object']['type'] == 'Like' or request_json['object']['object']['type'] == 'Dislike': # Announce of undo of upvote or downvote
|
||||||
post = comment = None
|
post = comment = None
|
||||||
|
|
|
@ -1344,11 +1344,13 @@ def delete_post_or_comment(deletor, to_delete, store_ap_json, request_json, reas
|
||||||
log_incoming_ap(id, APLOG_DELETE, APLOG_FAILURE, request_json if store_ap_json else None, 'Deletor did not have permisson')
|
log_incoming_ap(id, APLOG_DELETE, APLOG_FAILURE, request_json if store_ap_json else None, 'Deletor did not have permisson')
|
||||||
|
|
||||||
|
|
||||||
def restore_post_or_comment(restorer, to_restore, store_ap_json, request_json):
|
def restore_post_or_comment(restorer, to_restore, store_ap_json, request_json, reason):
|
||||||
id = request_json['id']
|
id = request_json['id']
|
||||||
community = to_restore.community
|
community = to_restore.community
|
||||||
reason = request_json['object']['summary'] if 'summary' in request_json['object'] else ''
|
if (to_restore.user_id == restorer.id or
|
||||||
if to_restore.user_id == restorer.id or restorer.is_admin() or community.is_moderator(restorer) or community.is_instance_admin(restorer):
|
(restorer.instance_id == to_restore.author.instance_id and restorer.is_instance_admin()) or
|
||||||
|
community.is_moderator(restorer) or
|
||||||
|
community.is_instance_admin(restorer)):
|
||||||
if isinstance(to_restore, Post):
|
if isinstance(to_restore, Post):
|
||||||
to_restore.deleted = False
|
to_restore.deleted = False
|
||||||
to_restore.deleted_by = None
|
to_restore.deleted_by = None
|
||||||
|
|
Loading…
Reference in a new issue