mirror of
https://github.com/jointakahe/takahe.git
synced 2024-11-20 14:21:00 +00:00
Downgrade follow not found to capture_message
This commit is contained in:
parent
773c9b2afc
commit
a22ba4859b
1 changed files with 29 additions and 7 deletions
|
@ -3,6 +3,7 @@ from typing import Optional
|
||||||
import httpx
|
import httpx
|
||||||
from django.db import models, transaction
|
from django.db import models, transaction
|
||||||
|
|
||||||
|
from core.exceptions import capture_message
|
||||||
from core.ld import canonicalise, get_str_or_id
|
from core.ld import canonicalise, get_str_or_id
|
||||||
from core.snowflake import Snowflake
|
from core.snowflake import Snowflake
|
||||||
from stator.models import State, StateField, StateGraph, StatorModel
|
from stator.models import State, StateField, StateGraph, StatorModel
|
||||||
|
@ -303,7 +304,14 @@ class Follow(StatorModel):
|
||||||
from activities.models import TimelineEvent
|
from activities.models import TimelineEvent
|
||||||
|
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
follow = cls.by_ap(data, create=True)
|
try:
|
||||||
|
follow = cls.by_ap(data, create=True)
|
||||||
|
except Identity.DoesNotExist:
|
||||||
|
capture_message(
|
||||||
|
"Identity not found for incoming Follow", extras={"data": data}
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
# Force it into remote_requested so we send an accept
|
# Force it into remote_requested so we send an accept
|
||||||
follow.transition_perform(FollowStates.remote_requested)
|
follow.transition_perform(FollowStates.remote_requested)
|
||||||
# Add a timeline event
|
# Add a timeline event
|
||||||
|
@ -317,8 +325,13 @@ class Follow(StatorModel):
|
||||||
# Resolve source and target and see if a Follow exists (it really should)
|
# Resolve source and target and see if a Follow exists (it really should)
|
||||||
try:
|
try:
|
||||||
follow = cls.by_ap(data["object"])
|
follow = cls.by_ap(data["object"])
|
||||||
except cls.DoesNotExist:
|
except (cls.DoesNotExist, Identity.DoesNotExist):
|
||||||
raise ValueError("No Follow locally for incoming Accept", data)
|
capture_message(
|
||||||
|
"Follow or Identity not found for incoming Accept",
|
||||||
|
extras={"data": data},
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
# Ensure the Accept actor is the Follow's target
|
# Ensure the Accept actor is the Follow's target
|
||||||
if data["actor"] != follow.target.actor_uri:
|
if data["actor"] != follow.target.actor_uri:
|
||||||
raise ValueError("Accept actor does not match its Follow object", data)
|
raise ValueError("Accept actor does not match its Follow object", data)
|
||||||
|
@ -337,8 +350,13 @@ class Follow(StatorModel):
|
||||||
# Resolve source and target and see if a Follow exists (it really should)
|
# Resolve source and target and see if a Follow exists (it really should)
|
||||||
try:
|
try:
|
||||||
follow = cls.by_ap(data["object"])
|
follow = cls.by_ap(data["object"])
|
||||||
except cls.DoesNotExist:
|
except (cls.DoesNotExist, Identity.DoesNotExist):
|
||||||
raise ValueError("No Follow locally for incoming Reject", data)
|
capture_message(
|
||||||
|
"Follow or Identity not found for incoming Reject",
|
||||||
|
extras={"data": data},
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
# Ensure the Accept actor is the Follow's target
|
# Ensure the Accept actor is the Follow's target
|
||||||
if data["actor"] != follow.target.actor_uri:
|
if data["actor"] != follow.target.actor_uri:
|
||||||
raise ValueError("Reject actor does not match its Follow object", data)
|
raise ValueError("Reject actor does not match its Follow object", data)
|
||||||
|
@ -353,8 +371,12 @@ class Follow(StatorModel):
|
||||||
# Resolve source and target and see if a Follow exists (it hopefully does)
|
# Resolve source and target and see if a Follow exists (it hopefully does)
|
||||||
try:
|
try:
|
||||||
follow = cls.by_ap(data["object"])
|
follow = cls.by_ap(data["object"])
|
||||||
except cls.DoesNotExist:
|
except (cls.DoesNotExist, Identity.DoesNotExist):
|
||||||
raise ValueError("No Follow locally for incoming Undo", data)
|
capture_message(
|
||||||
|
"Follow or Identity not found for incoming Undo", extras={"data": data}
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
# Ensure the Undo actor is the Follow's source
|
# Ensure the Undo actor is the Follow's source
|
||||||
if data["actor"] != follow.source.actor_uri:
|
if data["actor"] != follow.source.actor_uri:
|
||||||
raise ValueError("Accept actor does not match its Follow object", data)
|
raise ValueError("Accept actor does not match its Follow object", data)
|
||||||
|
|
Loading…
Reference in a new issue