mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 11:26:56 -08:00
modlog: propagate reasons for incoming mod actions
This commit is contained in:
parent
04cce6ec9d
commit
48a0cb64ce
1 changed files with 17 additions and 7 deletions
|
@ -1343,6 +1343,7 @@ def is_activitypub_request():
|
|||
def delete_post_or_comment(deletor, to_delete, store_ap_json, request_json):
|
||||
id = request_json['id']
|
||||
community = to_delete.community
|
||||
reason = request_json['object']['summary'] if 'summary' in request_json['object'] else ''
|
||||
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
|
||||
|
@ -1358,7 +1359,8 @@ def delete_post_or_comment(deletor, to_delete, store_ap_json, request_json):
|
|||
db.session.commit()
|
||||
if to_delete.author.id != deletor.id:
|
||||
add_to_modlog_activitypub('delete_post', deletor, community_id=community.id,
|
||||
link_text=shorten_string(to_delete.title), link=f'post/{to_delete.id}')
|
||||
link_text=shorten_string(to_delete.title), link=f'post/{to_delete.id}',
|
||||
reason=reason)
|
||||
elif isinstance(to_delete, PostReply):
|
||||
to_delete.deleted = True
|
||||
to_delete.deleted_by = deletor.id
|
||||
|
@ -1370,7 +1372,8 @@ def delete_post_or_comment(deletor, to_delete, store_ap_json, request_json):
|
|||
if to_delete.author.id != deletor.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}')
|
||||
link=f'post/{to_delete.post.id}#comment_{to_delete.id}',
|
||||
reason=reason)
|
||||
log_incoming_ap(id, APLOG_DELETE, APLOG_SUCCESS, request_json if store_ap_json else None)
|
||||
else:
|
||||
log_incoming_ap(id, APLOG_DELETE, APLOG_FAILURE, request_json if store_ap_json else None, 'Deletor did not have permisson')
|
||||
|
@ -1379,6 +1382,7 @@ def delete_post_or_comment(deletor, to_delete, store_ap_json, request_json):
|
|||
def restore_post_or_comment(restorer, to_restore, store_ap_json, request_json):
|
||||
id = request_json['id']
|
||||
community = to_restore.community
|
||||
reason = request_json['object']['summary'] if 'summary' in request_json['object'] else ''
|
||||
if to_restore.user_id == restorer.id or restorer.is_admin() or community.is_moderator(restorer) or community.is_instance_admin(restorer):
|
||||
if isinstance(to_restore, Post):
|
||||
to_restore.deleted = False
|
||||
|
@ -1400,7 +1404,8 @@ def restore_post_or_comment(restorer, to_restore, store_ap_json, request_json):
|
|||
db.session.commit()
|
||||
if to_restore.author.id != restorer.id:
|
||||
add_to_modlog_activitypub('restore_post', restorer, community_id=community.id,
|
||||
link_text=shorten_string(to_restore.title), link=f'post/{to_restore.id}')
|
||||
link_text=shorten_string(to_restore.title), link=f'post/{to_restore.id}',
|
||||
reason=reason)
|
||||
|
||||
elif isinstance(to_restore, PostReply):
|
||||
to_restore.deleted = False
|
||||
|
@ -1412,7 +1417,8 @@ def restore_post_or_comment(restorer, to_restore, store_ap_json, request_json):
|
|||
if to_restore.author.id != restorer.id:
|
||||
add_to_modlog_activitypub('restore_post_reply', restorer, community_id=community.id,
|
||||
link_text=f'comment on {shorten_string(to_restore.post.title)}',
|
||||
link=f'post/{to_restore.post_id}#comment_{to_restore.id}')
|
||||
link=f'post/{to_restore.post_id}#comment_{to_restore.id}',
|
||||
reason=reason)
|
||||
log_incoming_ap(id, APLOG_UNDO_DELETE, APLOG_SUCCESS, request_json if store_ap_json else None)
|
||||
else:
|
||||
log_incoming_ap(id, APLOG_UNDO_DELETE, APLOG_FAILURE, request_json if store_ap_json else None, 'Restorer did not have permisson')
|
||||
|
@ -1543,8 +1549,11 @@ def ban_local_user(blocker, blocked, community, request_json):
|
|||
existing = CommunityBan.query.filter_by(community_id=community.id, user_id=blocked.id).first()
|
||||
if not existing:
|
||||
new_ban = CommunityBan(community_id=community.id, user_id=blocked.id, banned_by=blocker.id)
|
||||
if 'summary' in request_json:
|
||||
if 'summary' in request_json['object']:
|
||||
new_ban.reason=request_json['object']['summary']
|
||||
reason = request_json['object']['summary']
|
||||
else:
|
||||
reason = ''
|
||||
if 'expires' in request_json and datetime.fromisoformat(request_json['object']['expires']) > datetime.now(timezone.utc):
|
||||
new_ban.ban_until = datetime.fromisoformat(request_json['object']['expires'])
|
||||
elif 'endTime' in request_json and datetime.fromisoformat(request_json['object']['endTime']) > datetime.now(timezone.utc):
|
||||
|
@ -1575,7 +1584,7 @@ def ban_local_user(blocker, blocked, community, request_json):
|
|||
cache.delete_memoized(joined_communities, blocked.id)
|
||||
cache.delete_memoized(moderating_communities, blocked.id)
|
||||
|
||||
add_to_modlog_activitypub('ban_user', blocker, community_id=community.id, link_text=blocked.display_name(), link=blocked.link())
|
||||
add_to_modlog_activitypub('ban_user', blocker, community_id=community.id, link_text=blocked.display_name(), link=blocked.link(), reason=reason)
|
||||
|
||||
|
||||
def unban_local_user(blocker, blocked, community, request_json):
|
||||
|
@ -1583,6 +1592,7 @@ def unban_local_user(blocker, blocked, community, request_json):
|
|||
community_membership_record = CommunityMember.query.filter_by(community_id=community.id, user_id=blocked.id).first()
|
||||
if community_membership_record:
|
||||
community_membership_record.is_banned = False
|
||||
reason = request_json['object']['summary'] if 'summary' in request_json['object'] else ''
|
||||
|
||||
# Notify unbanned person
|
||||
notify = Notification(title=shorten_string('You have been unbanned from ' + community.title),
|
||||
|
@ -1597,7 +1607,7 @@ def unban_local_user(blocker, blocked, community, request_json):
|
|||
cache.delete_memoized(joined_communities, blocked.id)
|
||||
cache.delete_memoized(moderating_communities, blocked.id)
|
||||
|
||||
add_to_modlog_activitypub('unban_user', blocker, community_id=community.id, link_text=blocked.display_name(), link=blocked.link())
|
||||
add_to_modlog_activitypub('unban_user', blocker, community_id=community.id, link_text=blocked.display_name(), link=blocked.link(), reason=reason)
|
||||
|
||||
|
||||
def lock_post(mod_ap_id, post_id, comments_enabled):
|
||||
|
|
Loading…
Reference in a new issue