Add option for admins to fixup a broken post from the remote version

This commit is contained in:
freamon 2024-12-04 17:36:28 +00:00
parent 958a0c9f0c
commit bd37423ba4
2 changed files with 23 additions and 2 deletions

View file

@ -10,7 +10,7 @@ from wtforms import SelectField, RadioField
from app import db, constants, cache, celery
from app.activitypub.signature import HttpSignature, post_request, default_context, post_request_in_background
from app.activitypub.util import notify_about_post_reply, inform_followers_of_post_update
from app.activitypub.util import notify_about_post_reply, inform_followers_of_post_update, update_post_from_activity
from app.community.util import save_post, send_to_remote_instance
from app.inoculation import inoculation
from app.post.forms import NewReplyForm, ReportPostForm, MeaCulpaForm, CrossPostForm
@ -32,7 +32,7 @@ from app.utils import get_setting, render_template, allowlist_html, markdown_to_
blocked_instances, blocked_domains, community_moderators, blocked_phrases, show_ban_message, recently_upvoted_posts, \
recently_downvoted_posts, recently_upvoted_post_replies, recently_downvoted_post_replies, reply_is_stupid, \
languages_for_form, menu_topics, add_to_modlog, blocked_communities, piefed_markdown_to_lemmy_markdown, \
permission_required, blocked_users
permission_required, blocked_users, get_request
def show_post(post_id: int):
@ -1901,6 +1901,25 @@ def post_reply_view_voting_activity(comment_id: int):
)
@bp.route('/post/<int:post_id>/fixup_from_remote', methods=['GET'])
@login_required
@permission_required('change instance settings')
def post_fixup_from_remote(post_id: int):
post = Post.query.get_or_404(post_id)
# will fail for some MBIN objects for same reason that 'View original on ...' does
# (ap_id is lowercase, but original URL was mixed-case and remote instance software is case-sensitive)
remote_post_request = get_request(post.ap_id, headers={'Accept': 'application/activity+json'})
if remote_post_request.status_code == 200:
remote_post_json = remote_post_request.json()
remote_post_request.close()
if 'type' in remote_post_json and remote_post_json['type'] == 'Page':
update_json = {'type': 'Update', 'object': remote_post_json}
update_post_from_activity(post, update_json)
return redirect(url_for('activitypub.post_ap', post_id=post.id))
@bp.route('/post/<int:post_id>/cross-post', methods=['GET', 'POST'])
@login_required
def post_cross_post(post_id: int):

View file

@ -71,6 +71,8 @@
{% if current_user.is_authenticated and (current_user.is_admin() or current_user.is_staff()) -%}
<li><a href="{{ url_for('post.post_view_voting_activity', post_id=post.id) }}" class="no-underline" rel="nofollow"><span class="fe fe-sticky-left"></span>
{{ _('View Voting Activity') }}</a></li>
<li><a href="{{ url_for('post.post_fixup_from_remote', post_id=post.id) }}" class="no-underline" rel="nofollow"><span class="fe fe-sticky-right"></span>
{{ _('Fixup from remote') }}</a></li>
{% endif -%}
</ul>
<p>{{ _('If you want to perform more than one of these (e.g. block and report), hold down Ctrl and click, then complete the operation in the new tabs that open.') }}</p>