activitypub logging

This commit is contained in:
rimu 2024-01-13 11:12:31 +13:00
parent bb35a4cb05
commit 7c7d0b7a56
5 changed files with 41 additions and 3 deletions

View file

@ -293,7 +293,7 @@ def community_profile(actor):
def shared_inbox(): def shared_inbox():
if request.method == 'POST': if request.method == 'POST':
# save all incoming data to aid in debugging and development. Set result to 'success' if things go well # 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: try:
request_json = request.get_json(force=True) request_json = request.get_json(force=True)
@ -313,7 +313,8 @@ def shared_inbox():
return '' return ''
activity_log.activity_id = request_json['id'] 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' activity_log.result = 'processing'
db.session.add(activity_log) db.session.add(activity_log)
db.session.commit() db.session.commit()
@ -327,7 +328,8 @@ def shared_inbox():
return '' return ''
else: else:
activity_log.activity_id = '' 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.add(activity_log)
db.session.commit() db.session.commit()

View file

@ -28,6 +28,7 @@ class SiteMiscForm(FlaskForm):
types = [('Open', _l('Open')), ('RequireApplication', _l('Require application')), ('Closed', _l('Closed'))] types = [('Open', _l('Open')), ('RequireApplication', _l('Require application')), ('Closed', _l('Closed'))]
registration_mode = SelectField(_l('Registration mode'), choices=types, default=1, coerce=str) registration_mode = SelectField(_l('Registration mode'), choices=types, default=1, coerce=str)
application_question = TextAreaField(_l('Question to ask people applying for an account')) 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')) submit = SubmitField(_l('Save'))

View file

@ -76,6 +76,7 @@ def admin_misc():
site.reports_email_admins = form.reports_email_admins.data site.reports_email_admins = form.reports_email_admins.data
site.registration_mode = form.registration_mode.data site.registration_mode = form.registration_mode.data
site.application_question = form.application_question.data site.application_question = form.application_question.data
site.log_activitypub_json = form.log_activitypub_json.data
site.updated = utcnow() site.updated = utcnow()
if site.id is None: if site.id is None:
db.session.add(site) db.session.add(site)
@ -91,6 +92,7 @@ def admin_misc():
form.reports_email_admins.data = site.reports_email_admins form.reports_email_admins.data = site.reports_email_admins
form.registration_mode.data = site.registration_mode form.registration_mode.data = site.registration_mode
form.application_question.data = site.application_question 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, return render_template('admin/misc.html', title=_('Misc settings'), form=form,
moderating_communities=moderating_communities(current_user.get_id()), moderating_communities=moderating_communities(current_user.get_id()),
joined_communities=joined_communities(current_user.get_id()) joined_communities=joined_communities(current_user.get_id())

View file

@ -979,6 +979,7 @@ class Site(db.Model):
created_at = db.Column(db.DateTime, default=utcnow) created_at = db.Column(db.DateTime, default=utcnow)
updated = db.Column(db.DateTime, default=utcnow) updated = db.Column(db.DateTime, default=utcnow)
last_active = db.Column(db.DateTime, default=utcnow) last_active = db.Column(db.DateTime, default=utcnow)
log_activitypub_json = db.Column(db.Boolean, default=False)
@staticmethod @staticmethod
def admins() -> List[User]: def admins() -> List[User]:

View file

@ -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 ###