mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
apf part 13: Delete requests
This commit is contained in:
parent
046a15e617
commit
115bb8426f
2 changed files with 49 additions and 49 deletions
|
@ -721,6 +721,23 @@ def process_inbox_request(request_json, store_ap_json):
|
|||
log_incoming_ap(request_json['id'], APLOG_CREATE, APLOG_FAILURE, request_json if store_ap_json else None, 'Unacceptable type (create): ' + object_type)
|
||||
return
|
||||
|
||||
if request_json['type'] == 'Delete':
|
||||
if isinstance(request_json['object'], str):
|
||||
ap_id = request_json['object'] # lemmy
|
||||
else:
|
||||
ap_id = request_json['object']['id'] # kbin
|
||||
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.deleted:
|
||||
log_incoming_ap(request_json['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)
|
||||
announce_activity_to_followers(to_delete.community, user, request_json)
|
||||
else:
|
||||
log_incoming_ap(request_json['id'], APLOG_DELETE, APLOG_FAILURE, request_json if store_ap_json else None, 'Delete: cannot find ' + ap_id)
|
||||
return
|
||||
|
||||
|
||||
# -- below this point is code that will be incrementally replaced to use log_incoming_ap() instead --
|
||||
|
||||
|
|
|
@ -1334,20 +1334,9 @@ def is_activitypub_request():
|
|||
return 'application/ld+json' in request.headers.get('Accept', '') or 'application/activity+json' in request.headers.get('Accept', '')
|
||||
|
||||
|
||||
def delete_post_or_comment(user_ap_id, to_be_deleted_ap_id, aplog_id):
|
||||
deletor = find_actor_or_create(user_ap_id)
|
||||
to_delete = find_liked_object(to_be_deleted_ap_id)
|
||||
aplog = ActivityPubLog.query.get(aplog_id)
|
||||
|
||||
if to_delete and to_delete.deleted:
|
||||
if aplog:
|
||||
aplog.result = 'ignored'
|
||||
aplog.exception_message = 'Activity about local content which is already deleted'
|
||||
return
|
||||
|
||||
if deletor and to_delete:
|
||||
def delete_post_or_comment(deletor, to_delete, store_ap_json, request_json):
|
||||
community = to_delete.community
|
||||
if to_delete.author.id == deletor.id or deletor.is_admin() or community.is_moderator(deletor) or community.is_instance_admin(deletor):
|
||||
if to_delete.user_id == deletor.id or deletor.is_admin() or community.is_moderator(deletor) or community.is_instance_admin(deletor):
|
||||
if isinstance(to_delete, Post):
|
||||
to_delete.deleted = True
|
||||
to_delete.deleted_by = deletor.id
|
||||
|
@ -1367,6 +1356,7 @@ def delete_post_or_comment(user_ap_id, to_be_deleted_ap_id, aplog_id):
|
|||
to_delete.deleted = True
|
||||
to_delete.deleted_by = deletor.id
|
||||
to_delete.author.post_reply_count -= 1
|
||||
community.post_reply_count -= 1
|
||||
if not to_delete.author.bot:
|
||||
to_delete.post.reply_count -= 1
|
||||
db.session.commit()
|
||||
|
@ -1374,16 +1364,9 @@ def delete_post_or_comment(user_ap_id, to_be_deleted_ap_id, aplog_id):
|
|||
add_to_modlog_activitypub('delete_post_reply', deletor, community_id=community.id,
|
||||
link_text=f'comment on {shorten_string(to_delete.post.title)}',
|
||||
link=f'post/{to_delete.post.id}#comment_{to_delete.id}')
|
||||
if aplog:
|
||||
aplog.result = 'success'
|
||||
log_incoming_ap(request_json['id'], APLOG_DELETE, APLOG_SUCCESS, request_json if store_ap_json else None)
|
||||
else:
|
||||
if aplog:
|
||||
aplog.result = 'failure'
|
||||
aplog.exception_message = 'Deletor did not have permission'
|
||||
else:
|
||||
if aplog:
|
||||
aplog.result = 'failure'
|
||||
aplog.exception_message = 'Unable to resolve deletor, or target'
|
||||
log_incoming_ap(request_json['id'], APLOG_DELETE, APLOG_FAILURE, request_json if store_ap_json else None, 'Deletor did not have permisson')
|
||||
|
||||
|
||||
def restore_post_or_comment(object_json, aplog_id):
|
||||
|
|
Loading…
Add table
Reference in a new issue