From 781ed8efe265f5057a009f6d4b3385bd84810c00 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 17 Jun 2018 21:54:16 +0200 Subject: [PATCH] Some tests are passing --- activitypub.py | 19 +++++++++---------- app.py | 10 +++++----- dev-requirements.txt | 1 + 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/activitypub.py b/activitypub.py index 8dd4399..d7e55a1 100644 --- a/activitypub.py +++ b/activitypub.py @@ -79,7 +79,7 @@ class MicroblogPubBackend(Backend): DB.outbox.find_one( { "type": ap.ActivityType.BLOCK.value, - "activity.object": as_actor.id, + "activity.object": actor_id, "meta.undo": False, } ) @@ -92,14 +92,13 @@ class MicroblogPubBackend(Backend): # Check if the activity is owned by this server if iri.startswith(BASE_URL): data = DB.outbox.find_one({"remote_id": iri}) - if not data: - raise ActivityNotFoundError(f"{iri} not found on this server") - return data["activity"] - - # Check if the activity is stored in the inbox - data = DB.inbox.find_one({"remote_id": iri}) - if data: - return data["activity"] + if data: + return data["activity"] + else: + # Check if the activity is stored in the inbox + data = DB.inbox.find_one({"remote_id": iri}) + if data: + return data["activity"] # Fetch the URL via HTTP return super().fetch_iri(iri) @@ -142,7 +141,7 @@ class MicroblogPubBackend(Backend): @ensure_it_is_me def new_following(self, as_actor: ap.Person, follow: ap.Follow) -> None: - remote_actor = follow.get_actor().id + remote_actor = follow.get_object().id if DB.following.find({"remote_actor": remote_actor}).count() == 0: DB.following.insert_one({"remote_actor": remote_actor}) diff --git a/app.py b/app.py index 0ab5e29..0e3461d 100644 --- a/app.py +++ b/app.py @@ -384,7 +384,7 @@ def authorize_follow(): if DB.following.find({"remote_actor": actor}).count() > 0: return redirect("/following") - follow = activitypub.Follow(actor=MY_PERSON, object=actor) + follow = activitypub.Follow(actor=MY_PERSON.id, object=actor) OUTBOX.post(follow) return redirect("/following") @@ -1182,7 +1182,7 @@ def api_upload(): content = request.args.get("content") to = request.args.get("to") note = ap.Note( - actor=MY_PERSON, + attributedTo=MY_PERSON.id, cc=[ID + "/followers"], to=[to if to else ap.AS_PUBLIC], content=content, # TODO(tsileo): handle markdown @@ -1225,7 +1225,7 @@ def api_new_note(): cc.append(tag["href"]) note = ap.Note( - actor=MY_PERSON, + attributedTo=MY_PERSON.id, cc=list(set(cc)), to=[to if to else ap.AS_PUBLIC], content=content, @@ -1261,7 +1261,7 @@ def api_block(): if existing: return _user_api_response(activity=existing["activity"]["id"]) - block = ap.Block(actor=MY_PERSON, object=actor) + block = ap.Block(actor=MY_PERSON.id, object=actor) OUTBOX.post(block) return _user_api_response(activity=block.id) @@ -1276,7 +1276,7 @@ def api_follow(): if existing: return _user_api_response(activity=existing["activity"]["id"]) - follow = ap.Follow(actor=MY_PERSON, object=actor) + follow = ap.Follow(actor=MY_PERSON.id, object=actor) OUTBOX.post(follow) return _user_api_response(activity=follow.id) diff --git a/dev-requirements.txt b/dev-requirements.txt index a4ab4e5..7db7fab 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,3 +1,4 @@ +git+https://github.com/tsileo/little-boxes.git pytest requests html2text