Move the check to the inbox

This commit is contained in:
Mark Felder 2024-08-23 14:24:04 -04:00
parent 4bc6f334f4
commit 1c394dd18c
2 changed files with 26 additions and 21 deletions

View file

@ -294,6 +294,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
end end
def inbox(%{assigns: %{valid_signature: false}} = conn, params) do def inbox(%{assigns: %{valid_signature: false}} = conn, params) do
case unknown_delete?(params) do
true ->
:ok
false ->
Federator.incoming_ap_doc(%{ Federator.incoming_ap_doc(%{
method: conn.method, method: conn.method,
req_headers: conn.req_headers, req_headers: conn.req_headers,
@ -301,6 +306,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
params: params, params: params,
query_string: conn.query_string query_string: conn.query_string
}) })
end
json(conn, "ok") json(conn, "ok")
end end
@ -558,4 +564,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubController do
|> json(UserView.render("featured.json", %{user: user})) |> json(UserView.render("featured.json", %{user: user}))
end end
end end
defp unknown_delete?(%{
"type" => "Delete",
"actor" => actor
}) do
case User.get_cached_by_ap_id(actor) do
%User{} -> false
_ -> true
end
end
defp unknown_delete?(_), do: false
end end

View file

@ -33,8 +33,7 @@ defmodule Pleroma.Workers.ReceiverWorker do
query_string: query_string query_string: query_string
} }
with {_, false} <- {:unknown_delete, unknown_delete?(params)}, with {:ok, %User{} = _actor} <- User.get_or_fetch_by_ap_id(conn_data.params["actor"]),
{:ok, %User{} = _actor} <- User.get_or_fetch_by_ap_id(conn_data.params["actor"]),
{:ok, _public_key} <- Signature.refetch_public_key(conn_data), {:ok, _public_key} <- Signature.refetch_public_key(conn_data),
{:signature, true} <- {:signature, Signature.validate_signature(conn_data)}, {:signature, true} <- {:signature, Signature.validate_signature(conn_data)},
{:ok, res} <- Federator.perform(:incoming_ap_doc, params) do {:ok, res} <- Federator.perform(:incoming_ap_doc, params) do
@ -73,16 +72,4 @@ defmodule Pleroma.Workers.ReceiverWorker do
e -> {:error, e} e -> {:error, e}
end end
end end
defp unknown_delete?(%{
"type" => "Delete",
"actor" => actor
}) do
case User.get_cached_by_ap_id(actor) do
%User{} -> false
_ -> true
end
end
defp unknown_delete?(_), do: false
end end