mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 11:26:56 -08:00
activitypub logging
This commit is contained in:
parent
bb35a4cb05
commit
7c7d0b7a56
5 changed files with 41 additions and 3 deletions
|
@ -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,6 +313,7 @@ def shared_inbox():
|
|||
return ''
|
||||
|
||||
activity_log.activity_id = request_json['id']
|
||||
if g.site.log_activitypub_json:
|
||||
activity_log.activity_json = json.dumps(request_json)
|
||||
activity_log.result = 'processing'
|
||||
db.session.add(activity_log)
|
||||
|
@ -327,6 +328,7 @@ def shared_inbox():
|
|||
return ''
|
||||
else:
|
||||
activity_log.activity_id = ''
|
||||
if g.site.log_activitypub_json:
|
||||
activity_log.activity_json = json.dumps(request_json)
|
||||
db.session.add(activity_log)
|
||||
db.session.commit()
|
||||
|
|
|
@ -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'))
|
||||
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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]:
|
||||
|
|
32
migrations/versions/8885aafd5291_activitypub_logging.py
Normal file
32
migrations/versions/8885aafd5291_activitypub_logging.py
Normal 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 ###
|
Loading…
Reference in a new issue