Move user active check into Federator.perform/1

This commit is contained in:
Mark Felder 2024-08-28 18:35:01 -04:00
parent e498d252e4
commit 1821ef4f15
3 changed files with 10 additions and 12 deletions

View file

@ -102,7 +102,8 @@ defmodule Pleroma.Web.Federator do
# NOTE: we use the actor ID to do the containment, this is fine because an
# actor shouldn't be acting on objects outside their own AP server.
with {_, {:ok, _user}} <- {:actor, User.get_or_fetch_by_ap_id(actor)},
with {_, {:ok, user}} <- {:actor, User.get_or_fetch_by_ap_id(actor)},
{:user_active, true} <- {:user_active, match?(true, user.is_active)},
nil <- Activity.normalize(params["id"]),
{_, :ok} <-
{:correct_origin?, Containment.contain_origin_from_id(actor, params)},

View file

@ -33,8 +33,7 @@ defmodule Pleroma.Workers.ReceiverWorker do
query_string: query_string
}
with {:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(conn_data.params["actor"]),
{:user_active, true} <- {:user_active, match?(true, actor.is_active)},
with {:ok, %User{}} <- User.get_or_fetch_by_ap_id(conn_data.params["actor"]),
{:ok, _public_key} <- Signature.refetch_public_key(conn_data),
{:signature, true} <- {:signature, Signature.validate_signature(conn_data)},
{:ok, res} <- Federator.perform(:incoming_ap_doc, params) do
@ -65,7 +64,7 @@ defmodule Pleroma.Workers.ReceiverWorker do
{:error, :not_found} = reason -> {:cancel, reason}
{:error, :forbidden} = reason -> {:cancel, reason}
# Inactive user
{:user_active, false} = reason -> {:cancel, reason}
{:error, {:user_active, false} = reason} -> {:cancel, reason}
# Validator will error and return a changeset error
# e.g., duplicate activities or if the object was deleted
{:error, {:validate, {:error, _changeset} = reason}} -> {:cancel, reason}

View file

@ -138,15 +138,13 @@ defmodule Pleroma.Workers.ReceiverWorkerTest do
{:ok, %User{}} = User.set_activation(user, false)
{:ok, oban_job} =
ReceiverWorker.new(%{
"op" => "incoming_ap_doc",
"method" => "POST",
"req_headers" => [],
"request_path" => "/inbox",
"params" => params,
"query_string" => ""
Federator.incoming_ap_doc(%{
method: "POST",
req_headers: [],
request_path: "/inbox",
params: params,
query_string: ""
})
|> Oban.insert()
assert {:cancel, {:user_active, false}} = ReceiverWorker.perform(oban_job)
end