validators/add_remove: don't crash on failure to resolve reference

It allows for informed error handling and retry/discard job
decisions lateron which a future commit will add.
This commit is contained in:
Oneric 2024-12-14 02:02:04 +00:00
parent ead44c6671
commit 25d24cc5f6

View file

@ -9,6 +9,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AddRemoveValidator do
import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
require Pleroma.Constants require Pleroma.Constants
require Logger
alias Pleroma.User alias Pleroma.User
@ -27,14 +28,21 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AddRemoveValidator do
end end
def cast_and_validate(data) do def cast_and_validate(data) do
{:ok, actor} = User.get_or_fetch_by_ap_id(data["actor"]) with {_, {:ok, actor}} <- {:user, User.get_or_fetch_by_ap_id(data["actor"])},
{_, {:ok, actor}} <- {:feataddr, maybe_refetch_user(actor)} do
{:ok, actor} = maybe_refetch_user(actor)
data data
|> maybe_fix_data_for_mastodon(actor) |> maybe_fix_data_for_mastodon(actor)
|> cast_data() |> cast_data()
|> validate_data(actor) |> validate_data(actor)
else
{:feataddr, _} ->
{:error,
{:validate,
"Actor doesn't provide featured collection address to verify against: #{data["id"]}"}}
{:user, _} ->
{:error, :link_resolve_failed}
end
end end
defp maybe_fix_data_for_mastodon(data, actor) do defp maybe_fix_data_for_mastodon(data, actor) do