From 16f84f28a67c8a32e5852532d31ab440881b96f7 Mon Sep 17 00:00:00 2001 From: freamon Date: Thu, 14 Mar 2024 09:40:50 +0000 Subject: [PATCH 1/2] Use setting to log JSON for outgoing activities --- app/activitypub/signature.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/activitypub/signature.py b/app/activitypub/signature.py index 1a8f173b..d78b3bcc 100644 --- a/app/activitypub/signature.py +++ b/app/activitypub/signature.py @@ -39,7 +39,7 @@ import arrow from cryptography.exceptions import InvalidSignature from cryptography.hazmat.primitives import hashes, serialization from cryptography.hazmat.primitives.asymmetric import padding, rsa -from flask import Request, current_app +from flask import Request, current_app, g from datetime import datetime from dateutil import parser from pyld import jsonld @@ -81,8 +81,9 @@ def post_request(uri: str, body: dict | None, private_key: str, key_id: str, con if '@context' not in body: # add a default json-ld context if necessary body['@context'] = default_context() type = body['type'] if 'type' in body else '' - log = ActivityPubLog(direction='out', activity_json=json.dumps(body), activity_type=type, - result='processing', activity_id=body['id'], exception_message='') + log = ActivityPubLog(direction='out', activity_type=type, result='processing', activity_id=body['id'], exception_message='') + if g.site.log_activitypub_json: + log.activity_json=json.dumps(body) db.session.add(log) db.session.commit() try: From 22fad8c1f1b699432d51c81838a52ac7967a7ca2 Mon Sep 17 00:00:00 2001 From: freamon Date: Thu, 14 Mar 2024 10:08:54 +0000 Subject: [PATCH 2/2] Avoid crash on viewing unlogged ActivityPub JSON --- app/templates/admin/activities.html | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/templates/admin/activities.html b/app/templates/admin/activities.html index a8f86d4b..c0e09b30 100644 --- a/app/templates/admin/activities.html +++ b/app/templates/admin/activities.html @@ -38,7 +38,13 @@ {{ activity.result }} {% endif %} {{ activity.exception_message if activity.exception_message else '' }} - View + + {% if activity.activity_json is none %} + None + {% else %} + View + {% endif %} + {% endfor %} @@ -56,4 +62,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %}