community ap id exception logging

This commit is contained in:
rimu 2024-01-05 08:45:33 +13:00
parent 14ddb92922
commit 87b4476fda

View file

@ -357,20 +357,25 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
if request_json['type'] == 'Create': if request_json['type'] == 'Create':
activity_log.activity_type = 'Create' activity_log.activity_type = 'Create'
user_ap_id = request_json['object']['attributedTo'] user_ap_id = request_json['object']['attributedTo']
community_ap_id = request_json['to'][0] try:
if community_ap_id == 'https://www.w3.org/ns/activitystreams#Public': # kbin does this when posting a reply community_ap_id = request_json['to'][0]
if 'to' in request_json['object'] and request_json['object']['to']: if community_ap_id == 'https://www.w3.org/ns/activitystreams#Public': # kbin does this when posting a reply
community_ap_id = request_json['object']['to'][0] if 'to' in request_json['object'] and request_json['object']['to']:
if community_ap_id == 'https://www.w3.org/ns/activitystreams#Public' and 'cc' in \ community_ap_id = request_json['object']['to'][0]
request_json['object'] and request_json['object']['cc']: if community_ap_id == 'https://www.w3.org/ns/activitystreams#Public' and 'cc' in \
request_json['object'] and request_json['object']['cc']:
community_ap_id = request_json['object']['cc'][0]
elif 'cc' in request_json['object'] and request_json['object']['cc']:
community_ap_id = request_json['object']['cc'][0] community_ap_id = request_json['object']['cc'][0]
elif 'cc' in request_json['object'] and request_json['object']['cc']: if community_ap_id.endswith('/followers'): # mastodon
community_ap_id = request_json['object']['cc'][0] if 'inReplyTo' in request_json['object']:
if community_ap_id.endswith('/followers'): # mastodon post_being_replied_to = Post.query.filter_by(ap_id=request_json['object']['inReplyTo']).first()
if 'inReplyTo' in request_json['object']: if post_being_replied_to:
post_being_replied_to = Post.query.filter_by(ap_id=request_json['object']['inReplyTo']).first() community_ap_id = post_being_replied_to.community.ap_profile_id
if post_being_replied_to: except:
community_ap_id = post_being_replied_to.community.ap_profile_id activity_log.activity_type = 'exception'
db.session.commit()
return
community = find_actor_or_create(community_ap_id) community = find_actor_or_create(community_ap_id)
user = find_actor_or_create(user_ap_id) user = find_actor_or_create(user_ap_id)
if (user and not user.is_local()) and community: if (user and not user.is_local()) and community:
@ -398,7 +403,12 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
if request_json['object']['type'] == 'Create': if request_json['object']['type'] == 'Create':
activity_log.activity_type = request_json['object']['type'] activity_log.activity_type = request_json['object']['type']
user_ap_id = request_json['object']['object']['attributedTo'] user_ap_id = request_json['object']['object']['attributedTo']
community_ap_id = request_json['object']['audience'] try:
community_ap_id = request_json['object']['audience'] if 'audience' in request_json['object'] else request_json['actor']
except KeyError:
activity_log.activity_type = 'exception'
db.session.commit()
return
community = find_actor_or_create(community_ap_id) community = find_actor_or_create(community_ap_id)
user = find_actor_or_create(user_ap_id) user = find_actor_or_create(user_ap_id)
if (user and not user.is_local()) and community: if (user and not user.is_local()) and community:
@ -492,14 +502,14 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
elif request_json['object']['type'] == 'Delete': elif request_json['object']['type'] == 'Delete':
activity_log.activity_type = request_json['object']['type'] activity_log.activity_type = request_json['object']['type']
user_ap_id = request_json['object']['actor'] user_ap_id = request_json['object']['actor']
community_ap_id = request_json['object']['audience'] community_ap_id = request_json['object']['audience'] if 'audience' in request_json['object'] else request_json['actor']
to_be_deleted_ap_id = request_json['object']['object'] to_be_deleted_ap_id = request_json['object']['object']
delete_post_or_comment(user_ap_id, community_ap_id, to_be_deleted_ap_id) delete_post_or_comment(user_ap_id, community_ap_id, to_be_deleted_ap_id)
activity_log.result = 'success' activity_log.result = 'success'
elif request_json['object']['type'] == 'Page': # Editing a post elif request_json['object']['type'] == 'Page': # Editing a post
post = Post.query.filter_by(ap_id=request_json['object']['id']).first() post = Post.query.filter_by(ap_id=request_json['object']['id']).first()
if post: if post:
update_post_from_activity(post, request_json) update_post_from_activity(post, request_json['object'])
activity_log.result = 'success' activity_log.result = 'success'
else: else:
activity_log.exception_message = 'Post not found' activity_log.exception_message = 'Post not found'