diff options
author | Andrew Godwin | 2022-11-20 12:32:49 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-11-20 12:32:49 -0700 |
commit | f491fdb56e2de9200e14b855b5576009ca99dfa5 (patch) | |
tree | 5389fa8e3fef60ba1c7284087eba0d5616d222b3 /users/models | |
parent | 77643a4fe144cb908a372a2ceb99f36634457ca5 (diff) | |
download | takahe-f491fdb56e2de9200e14b855b5576009ca99dfa5.tar.gz takahe-f491fdb56e2de9200e14b855b5576009ca99dfa5.tar.bz2 takahe-f491fdb56e2de9200e14b855b5576009ca99dfa5.zip |
Actor delete, sentry async, faster stator
Diffstat (limited to 'users/models')
-rw-r--r-- | users/models/identity.py | 19 | ||||
-rw-r--r-- | users/models/inbox_message.py | 2 |
2 files changed, 20 insertions, 1 deletions
diff --git a/users/models/identity.py b/users/models/identity.py index a78a451..c26762d 100644 --- a/users/models/identity.py +++ b/users/models/identity.py @@ -12,6 +12,7 @@ from django.template.defaultfilters import linebreaks_filter from django.templatetags.static import static from django.utils import timezone +from core.exceptions import ActorMismatchError from core.html import sanitize_post from core.ld import canonicalise, media_type_from_filename from core.uploads import upload_namer @@ -261,6 +262,24 @@ class Identity(StatorModel): except cls.DoesNotExist: pass + @classmethod + def handle_delete_ap(cls, data): + """ + Takes an incoming update.person message and just forces us to add it + to our fetch queue (don't want to bother with two load paths right now) + """ + # Assert that the actor matches the object + if data["actor"] != data["object"]: + raise ActorMismatchError( + f"Actor {data['actor']} trying to delete identity {data['object']}" + ) + # Find by actor + try: + actor = cls.by_actor_uri(data["actor"]) + actor.delete() + except cls.DoesNotExist: + pass + ### Actor/Webfinger fetching ### @classmethod diff --git a/users/models/inbox_message.py b/users/models/inbox_message.py index fc81d71..a73166a 100644 --- a/users/models/inbox_message.py +++ b/users/models/inbox_message.py @@ -67,7 +67,7 @@ class InboxMessageStates(StateGraph): case "delete": # If there is no object type, it's probably a profile if not isinstance(instance.message["object"], dict): - raise ValueError("Cannot handle activity of type delete") + await sync_to_async(Identity.handle_delete_ap)(instance.message) match instance.message_object_type: case "tombstone": await sync_to_async(Post.handle_delete_ap)(instance.message) |