diff --git a/app/activitypub/util.py b/app/activitypub/util.py index 0431e9f4..e9f47ae6 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -709,6 +709,36 @@ def upvote_post(post, user): db.session.add(vote) +def delete_post_or_comment(user_ap_id, community_ap_id, to_be_deleted_ap_id): + if current_app.debug: + delete_post_or_comment_task(user_ap_id, community_ap_id, to_be_deleted_ap_id) + else: + delete_post_or_comment_task.delay(user_ap_id, community_ap_id, to_be_deleted_ap_id) + + +@celery.task +def delete_post_or_comment_task(user_ap_id, community_ap_id, to_be_deleted_ap_id): + deletor = find_actor_or_create(user_ap_id) + community = find_actor_or_create(community_ap_id) + to_delete = find_liked_object(to_be_deleted_ap_id) + + if deletor and community and to_delete: + if deletor.is_admin() or community.is_moderator(deletor) or to_delete.author.id == deletor.id: + if isinstance(to_delete, Post): + to_delete.delete_dependencies() + to_delete.flush_cache() + db.session.delete(to_delete) + db.session.commit() + elif isinstance(to_delete, PostReply): + if to_delete.has_replies(): + to_delete.body = 'Deleted by author' if to_delete.author.id == deletor.id else 'Deleted by moderator' + to_delete.body_html = markdown_to_html(to_delete.body) + else: + to_delete.delete_dependencies() + db.session.delete(to_delete) + db.session.commit() + + def lemmy_site_data(): site = g.site data = { diff --git a/app/admin/routes.py b/app/admin/routes.py index 675cf467..01b3c5f5 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -1,11 +1,12 @@ from datetime import datetime, timedelta -from flask import request, flash, json, url_for +from flask import request, flash, json, url_for, current_app from flask_login import login_required, current_user from flask_babel import _ from sqlalchemy import text, desc from app import db +from app.activitypub.routes import process_inbox_request from app.admin.forms import FederationForm, SiteMiscForm, SiteProfileForm from app.models import AllowedInstances, BannedInstances, ActivityPubLog, utcnow, Site from app.utils import render_template, permission_required, set_setting, get_setting @@ -145,4 +146,13 @@ def admin_activities(): def activity_json(activity_id): activity = ActivityPubLog.query.get_or_404(activity_id) return render_template('admin/activity_json.html', title=_('Activity JSON'), - activity_json_data=json.loads(activity.activity_json)) + activity_json_data=json.loads(activity.activity_json), activity=activity, current_app=current_app) + + +@bp.route('/activity_json//replay') +@login_required +@permission_required('change instance settings') +def activity_replay(activity_id): + activity = ActivityPubLog.query.get_or_404(activity_id) + process_inbox_request(json.loads(activity.activity_json), activity.id) + return 'Ok' diff --git a/app/templates/admin/activity_json.html b/app/templates/admin/activity_json.html index 5e7ea553..5a2f8b7e 100644 --- a/app/templates/admin/activity_json.html +++ b/app/templates/admin/activity_json.html @@ -11,6 +11,9 @@
{{ activity_json_data | tojson(indent=2) }}
+ {% if current_app.debug %} +

Re-submit this activity

+ {% endif %}
{% endblock %} \ No newline at end of file diff --git a/migrations/versions/52789c4b1d0f_report_comments.py b/migrations/versions/52789c4b1d0f_report_comments.py new file mode 100644 index 00000000..3147a9a6 --- /dev/null +++ b/migrations/versions/52789c4b1d0f_report_comments.py @@ -0,0 +1,34 @@ +"""report comments + +Revision ID: 52789c4b1d0f +Revises: c12823f18553 +Create Date: 2023-12-26 11:13:13.623630 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '52789c4b1d0f' +down_revision = 'c12823f18553' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('report', schema=None) as batch_op: + batch_op.add_column(sa.Column('suspect_post_reply_id', sa.Integer(), nullable=True)) + batch_op.create_foreign_key(None, 'post_reply', ['suspect_post_reply_id'], ['id']) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('report', schema=None) as batch_op: + batch_op.drop_constraint(None, type_='foreignkey') + batch_op.drop_column('suspect_post_reply_id') + + # ### end Alembic commands ###