mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
add some debugging logging
This commit is contained in:
parent
394f46fde3
commit
170a40738e
2 changed files with 61 additions and 49 deletions
|
@ -902,36 +902,39 @@ def process_delete_request(request_json, activitypublog_id, ip_address):
|
||||||
with current_app.app_context():
|
with current_app.app_context():
|
||||||
activity_log = ActivityPubLog.query.get(activitypublog_id)
|
activity_log = ActivityPubLog.query.get(activitypublog_id)
|
||||||
if 'type' in request_json and request_json['type'] == 'Delete':
|
if 'type' in request_json and request_json['type'] == 'Delete':
|
||||||
actor_to_delete = request_json['object'].lower()
|
if isinstance(request_json['object'], dict):
|
||||||
user = User.query.filter_by(ap_profile_id=actor_to_delete).first()
|
current_app.logger.error('Cannot delete, dict provided: ' + str(request_json['object']))
|
||||||
if user:
|
else:
|
||||||
# check that the user really has been deleted, to avoid spoofing attacks
|
actor_to_delete = request_json['object'].lower()
|
||||||
if not user.is_local():
|
user = User.query.filter_by(ap_profile_id=actor_to_delete).first()
|
||||||
if user_removed_from_remote_server(actor_to_delete, is_piefed=user.instance.software == 'PieFed'):
|
if user:
|
||||||
# Delete all their images to save moderators from having to see disgusting stuff.
|
# check that the user really has been deleted, to avoid spoofing attacks
|
||||||
files = File.query.join(Post).filter(Post.user_id == user.id).all()
|
if not user.is_local():
|
||||||
for file in files:
|
if user_removed_from_remote_server(actor_to_delete, is_piefed=user.instance.software == 'PieFed'):
|
||||||
file.delete_from_disk()
|
# Delete all their images to save moderators from having to see disgusting stuff.
|
||||||
file.source_url = ''
|
files = File.query.join(Post).filter(Post.user_id == user.id).all()
|
||||||
if user.avatar_id:
|
for file in files:
|
||||||
user.avatar.delete_from_disk()
|
file.delete_from_disk()
|
||||||
user.avatar.source_url = ''
|
file.source_url = ''
|
||||||
if user.cover_id:
|
if user.avatar_id:
|
||||||
user.cover.delete_from_disk()
|
user.avatar.delete_from_disk()
|
||||||
user.cover.source_url = ''
|
user.avatar.source_url = ''
|
||||||
user.banned = True
|
if user.cover_id:
|
||||||
user.deleted = True
|
user.cover.delete_from_disk()
|
||||||
activity_log.result = 'success'
|
user.cover.source_url = ''
|
||||||
|
user.banned = True
|
||||||
|
user.deleted = True
|
||||||
|
activity_log.result = 'success'
|
||||||
|
else:
|
||||||
|
activity_log.result = 'ignored'
|
||||||
|
activity_log.exception_message = 'User not actually deleted.'
|
||||||
else:
|
else:
|
||||||
activity_log.result = 'ignored'
|
activity_log.result = 'ignored'
|
||||||
activity_log.exception_message = 'User not actually deleted.'
|
activity_log.exception_message = 'Only remote users can be deleted remotely'
|
||||||
else:
|
else:
|
||||||
activity_log.result = 'ignored'
|
activity_log.result = 'ignored'
|
||||||
activity_log.exception_message = 'Only remote users can be deleted remotely'
|
activity_log.exception_message = 'Does not exist here'
|
||||||
else:
|
db.session.commit()
|
||||||
activity_log.result = 'ignored'
|
|
||||||
activity_log.exception_message = 'Does not exist here'
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
|
|
||||||
def announce_activity_to_followers(community, creator, activity):
|
def announce_activity_to_followers(community, creator, activity):
|
||||||
|
|
|
@ -465,27 +465,32 @@ def refresh_community_profile_task(community_id):
|
||||||
|
|
||||||
def actor_json_to_model(activity_json, address, server):
|
def actor_json_to_model(activity_json, address, server):
|
||||||
if activity_json['type'] == 'Person':
|
if activity_json['type'] == 'Person':
|
||||||
user = User(user_name=activity_json['preferredUsername'],
|
try:
|
||||||
title=activity_json['name'] if 'name' in activity_json else None,
|
user = User(user_name=activity_json['preferredUsername'],
|
||||||
email=f"{address}@{server}",
|
title=activity_json['name'] if 'name' in activity_json else None,
|
||||||
about_html=parse_summary(activity_json),
|
email=f"{address}@{server}",
|
||||||
matrix_user_id=activity_json['matrixUserId'] if 'matrixUserId' in activity_json else '',
|
about_html=parse_summary(activity_json),
|
||||||
indexable=activity_json['indexable'] if 'indexable' in activity_json else False,
|
matrix_user_id=activity_json['matrixUserId'] if 'matrixUserId' in activity_json else '',
|
||||||
searchable=activity_json['discoverable'] if 'discoverable' in activity_json else True,
|
indexable=activity_json['indexable'] if 'indexable' in activity_json else False,
|
||||||
created=activity_json['published'] if 'published' in activity_json else utcnow(),
|
searchable=activity_json['discoverable'] if 'discoverable' in activity_json else True,
|
||||||
ap_id=f"{address}@{server}",
|
created=activity_json['published'] if 'published' in activity_json else utcnow(),
|
||||||
ap_public_url=activity_json['id'],
|
ap_id=f"{address}@{server}",
|
||||||
ap_profile_id=activity_json['id'].lower(),
|
ap_public_url=activity_json['id'],
|
||||||
ap_inbox_url=activity_json['endpoints']['sharedInbox'],
|
ap_profile_id=activity_json['id'].lower(),
|
||||||
ap_followers_url=activity_json['followers'] if 'followers' in activity_json else None,
|
ap_inbox_url=activity_json['endpoints']['sharedInbox'],
|
||||||
ap_preferred_username=activity_json['preferredUsername'],
|
ap_followers_url=activity_json['followers'] if 'followers' in activity_json else None,
|
||||||
ap_manually_approves_followers=activity_json['manuallyApprovesFollowers'] if 'manuallyApprovesFollowers' in activity_json else False,
|
ap_preferred_username=activity_json['preferredUsername'],
|
||||||
ap_fetched_at=utcnow(),
|
ap_manually_approves_followers=activity_json['manuallyApprovesFollowers'] if 'manuallyApprovesFollowers' in activity_json else False,
|
||||||
ap_domain=server,
|
ap_fetched_at=utcnow(),
|
||||||
public_key=activity_json['publicKey']['publicKeyPem'],
|
ap_domain=server,
|
||||||
instance_id=find_instance_id(server)
|
public_key=activity_json['publicKey']['publicKeyPem'],
|
||||||
# language=community_json['language'][0]['identifier'] # todo: language
|
instance_id=find_instance_id(server)
|
||||||
)
|
# language=community_json['language'][0]['identifier'] # todo: language
|
||||||
|
)
|
||||||
|
except KeyError as e:
|
||||||
|
current_app.logger.error(f'KeyError for {address}@{server} while parsing ' + str(activity_json))
|
||||||
|
return None
|
||||||
|
|
||||||
if 'icon' in activity_json:
|
if 'icon' in activity_json:
|
||||||
avatar = File(source_url=activity_json['icon']['url'])
|
avatar = File(source_url=activity_json['icon']['url'])
|
||||||
user.avatar = avatar
|
user.avatar = avatar
|
||||||
|
@ -1271,7 +1276,9 @@ def notify_about_post(post: Post):
|
||||||
|
|
||||||
|
|
||||||
def update_post_reply_from_activity(reply: PostReply, request_json: dict):
|
def update_post_reply_from_activity(reply: PostReply, request_json: dict):
|
||||||
if 'source' in request_json['object'] and request_json['object']['source']['mediaType'] == 'text/markdown':
|
if 'source' in request_json['object'] and \
|
||||||
|
isinstance(request_json['object']['source'], dict) and \
|
||||||
|
request_json['object']['source']['mediaType'] == 'text/markdown':
|
||||||
reply.body = request_json['object']['source']['content']
|
reply.body = request_json['object']['source']['content']
|
||||||
reply.body_html = markdown_to_html(reply.body)
|
reply.body_html = markdown_to_html(reply.body)
|
||||||
elif 'content' in request_json['object']:
|
elif 'content' in request_json['object']:
|
||||||
|
@ -1283,7 +1290,9 @@ def update_post_reply_from_activity(reply: PostReply, request_json: dict):
|
||||||
|
|
||||||
def update_post_from_activity(post: Post, request_json: dict):
|
def update_post_from_activity(post: Post, request_json: dict):
|
||||||
post.title = request_json['object']['name']
|
post.title = request_json['object']['name']
|
||||||
if 'source' in request_json['object'] and request_json['object']['source']['mediaType'] == 'text/markdown':
|
if 'source' in request_json['object'] and \
|
||||||
|
isinstance(request_json['object']['source'], dict) and \
|
||||||
|
request_json['object']['source']['mediaType'] == 'text/markdown':
|
||||||
post.body = request_json['object']['source']['content']
|
post.body = request_json['object']['source']['content']
|
||||||
post.body_html = markdown_to_html(post.body)
|
post.body_html = markdown_to_html(post.body)
|
||||||
elif 'content' in request_json['object']:
|
elif 'content' in request_json['object']:
|
||||||
|
|
Loading…
Add table
Reference in a new issue