diff --git a/app/activitypub/routes.py b/app/activitypub/routes.py index 399eb718..f47d0af1 100644 --- a/app/activitypub/routes.py +++ b/app/activitypub/routes.py @@ -293,7 +293,7 @@ def community_profile(actor): def shared_inbox(): if request.method == 'POST': # save all incoming data to aid in debugging and development. Set result to 'success' if things go well - activity_log = ActivityPubLog(direction='in', activity_json=request.data, result='failure') + activity_log = ActivityPubLog(direction='in', result='failure') try: request_json = request.get_json(force=True) @@ -313,7 +313,8 @@ def shared_inbox(): return '' activity_log.activity_id = request_json['id'] - activity_log.activity_json = json.dumps(request_json) + if g.site.log_activitypub_json: + activity_log.activity_json = json.dumps(request_json) activity_log.result = 'processing' db.session.add(activity_log) db.session.commit() @@ -327,7 +328,8 @@ def shared_inbox(): return '' else: activity_log.activity_id = '' - activity_log.activity_json = json.dumps(request_json) + if g.site.log_activitypub_json: + activity_log.activity_json = json.dumps(request_json) db.session.add(activity_log) db.session.commit() diff --git a/app/admin/forms.py b/app/admin/forms.py index 2c8ef0c8..51c52e6d 100644 --- a/app/admin/forms.py +++ b/app/admin/forms.py @@ -28,6 +28,7 @@ class SiteMiscForm(FlaskForm): types = [('Open', _l('Open')), ('RequireApplication', _l('Require application')), ('Closed', _l('Closed'))] registration_mode = SelectField(_l('Registration mode'), choices=types, default=1, coerce=str) application_question = TextAreaField(_l('Question to ask people applying for an account')) + log_activitypub_json = BooleanField(_l('Log ActivityPub JSON for debugging')) submit = SubmitField(_l('Save')) diff --git a/app/admin/routes.py b/app/admin/routes.py index fd1192f2..5fce6f0f 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -76,6 +76,7 @@ def admin_misc(): site.reports_email_admins = form.reports_email_admins.data site.registration_mode = form.registration_mode.data site.application_question = form.application_question.data + site.log_activitypub_json = form.log_activitypub_json.data site.updated = utcnow() if site.id is None: db.session.add(site) @@ -91,6 +92,7 @@ def admin_misc(): form.reports_email_admins.data = site.reports_email_admins form.registration_mode.data = site.registration_mode form.application_question.data = site.application_question + form.log_activitypub_json.data = site.log_activitypub_json return render_template('admin/misc.html', title=_('Misc settings'), form=form, moderating_communities=moderating_communities(current_user.get_id()), joined_communities=joined_communities(current_user.get_id()) diff --git a/app/models.py b/app/models.py index 31e2c285..87eccb51 100644 --- a/app/models.py +++ b/app/models.py @@ -979,6 +979,7 @@ class Site(db.Model): created_at = db.Column(db.DateTime, default=utcnow) updated = db.Column(db.DateTime, default=utcnow) last_active = db.Column(db.DateTime, default=utcnow) + log_activitypub_json = db.Column(db.Boolean, default=False) @staticmethod def admins() -> List[User]: diff --git a/migrations/versions/8885aafd5291_activitypub_logging.py b/migrations/versions/8885aafd5291_activitypub_logging.py new file mode 100644 index 00000000..351ae27a --- /dev/null +++ b/migrations/versions/8885aafd5291_activitypub_logging.py @@ -0,0 +1,32 @@ +"""activitypub logging + +Revision ID: 8885aafd5291 +Revises: 0b49f0997073 +Create Date: 2024-01-13 11:04:43.569931 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '8885aafd5291' +down_revision = '0b49f0997073' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('site', schema=None) as batch_op: + batch_op.add_column(sa.Column('log_activitypub_json', sa.Boolean(), nullable=True)) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('site', schema=None) as batch_op: + batch_op.drop_column('log_activitypub_json') + + # ### end Alembic commands ###