remove lock_post helper function

This commit is contained in:
Hendrik L 2024-12-03 11:35:46 +01:00
parent a9e9c81272
commit 3cee732a0b
2 changed files with 14 additions and 31 deletions

View file

@ -25,11 +25,11 @@ from app.activitypub.util import public_key, users_total, active_half_year, acti
update_post_from_activity, undo_vote, undo_downvote, post_to_page, get_redis_connection, find_reported_object, \
process_report, ensure_domains_match, can_edit, can_delete, remove_data_from_banned_user, resolve_remote_post, \
inform_followers_of_post_update, comment_model_to_json, restore_post_or_comment, ban_user, unban_user, \
lock_post, log_incoming_ap, find_community_ap_id, site_ban_remove_data, community_ban_remove_data
log_incoming_ap, find_community_ap_id, site_ban_remove_data, community_ban_remove_data
from app.utils import gibberish, get_setting, render_template, \
community_membership, ap_datetime, ip_address, can_downvote, \
can_upvote, can_create_post, awaken_dormant_instance, shorten_string, can_create_post_reply, sha256_digest, \
community_moderators, markdown_to_html, html_to_text
community_moderators, markdown_to_html, html_to_text, add_to_modlog_activitypub
@bp.route('/testredis')
@ -1094,9 +1094,14 @@ def process_inbox_request(request_json, store_ap_json):
mod = user
post_id = request_json['object']['object']
post = Post.query.filter_by(ap_id=post_id).first()
reason = request_json['object']['summary'] if 'summary' in request_json['object'] else ''
if post:
if post.community.is_moderator(mod) or post.community.is_instance_admin(mod):
lock_post(user_ap_id, post_id, False, request_json)
post.comments_enabled = False
db.session.commit()
add_to_modlog_activitypub('lock_post', mod, community_id=post.community.id,
link_text=shorten_string(post.title), link=f'post/{post.id}',
reason=reason)
log_incoming_ap(id, APLOG_LOCK, APLOG_SUCCESS, request_json if store_ap_json else None)
else:
log_incoming_ap(id, APLOG_LOCK, APLOG_FAILURE, request_json if store_ap_json else None, 'Lock: Does not have permission')
@ -1215,9 +1220,14 @@ def process_inbox_request(request_json, store_ap_json):
mod = user
post_id = request_json['object']['object']['object']
post = Post.query.filter_by(ap_id=post_id).first()
reason = request_json['object']['summary'] if 'summary' in request_json['object'] else ''
if post:
if post.community.is_moderator(mod) or post.community.is_instance_admin(mod):
lock_post(user_ap_id, post_id, True, request_json)
post.comments_enabled = True
db.session.commit()
add_to_modlog_activitypub('unlock_post', mod, community_id=post.community.id,
link_text=shorten_string(post.title), link=f'post/{post.id}',
reason=reason)
log_incoming_ap(id, APLOG_LOCK, APLOG_SUCCESS, request_json if store_ap_json else None)
else:
log_incoming_ap(id, APLOG_LOCK, APLOG_FAILURE, request_json if store_ap_json else None, 'Lock: Does not have permission')

View file

@ -1612,33 +1612,6 @@ def unban_user(blocker, blocked, community, request_json):
add_to_modlog_activitypub('unban_user', blocker, community_id=community.id, link_text=blocked.display_name(), link=f'u/{blocked.link()}', reason=reason)
def lock_post(mod_ap_id, post_id, comments_enabled, request_json):
if current_app.debug:
lock_post_task(mod_ap_id, post_id, comments_enabled, request_json)
else:
lock_post_task.delay(mod_ap_id, post_id, comments_enabled, request_json)
@celery.task
def lock_post_task(mod_ap_id, post_id, comments_enabled, request_json):
mod = find_actor_or_create(mod_ap_id, create_if_not_found=False)
post = Post.query.filter_by(ap_id=post_id).first()
community = post.community
reason = request_json['object']['summary'] if 'summary' in request_json['object'] else ''
if mod and post:
if post.community.is_moderator(mod) or post.community.is_instance_admin(mod):
post.comments_enabled = comments_enabled
db.session.commit()
if comments_enabled:
add_to_modlog_activitypub('unlock_post', mod, community_id=community.id,
link_text=shorten_string(post.title), link=f'post/{post.id}',
reason=reason)
else:
add_to_modlog_activitypub('lock_post', mod, community_id=community.id,
link_text=shorten_string(post.title), link=f'post/{post.id}',
reason=reason)
def create_post_reply(store_ap_json, community: Community, in_reply_to, request_json: dict, user: User, announce_id=None) -> Union[PostReply, None]:
id = request_json['id']
if community.local_only: