forked from AkkomaGang/akkoma
Pipeline: Don't federate if federation is disabled.
This commit is contained in:
parent
e42bc5f557
commit
39031f4860
2 changed files with 46 additions and 1 deletions
|
@ -11,6 +11,7 @@ defmodule Pleroma.Web.ActivityPub.Pipeline do
|
||||||
alias Pleroma.Web.ActivityPub.ObjectValidator
|
alias Pleroma.Web.ActivityPub.ObjectValidator
|
||||||
alias Pleroma.Web.ActivityPub.SideEffects
|
alias Pleroma.Web.ActivityPub.SideEffects
|
||||||
alias Pleroma.Web.Federator
|
alias Pleroma.Web.Federator
|
||||||
|
alias Pleroma.Config
|
||||||
|
|
||||||
@spec common_pipeline(map(), keyword()) ::
|
@spec common_pipeline(map(), keyword()) ::
|
||||||
{:ok, Activity.t() | Object.t(), keyword()} | {:error, any()}
|
{:ok, Activity.t() | Object.t(), keyword()} | {:error, any()}
|
||||||
|
@ -44,7 +45,7 @@ defp maybe_federate(%Object{}, _), do: {:ok, :not_federated}
|
||||||
|
|
||||||
defp maybe_federate(%Activity{} = activity, meta) do
|
defp maybe_federate(%Activity{} = activity, meta) do
|
||||||
with {:ok, local} <- Keyword.fetch(meta, :local) do
|
with {:ok, local} <- Keyword.fetch(meta, :local) do
|
||||||
do_not_federate = meta[:do_not_federate]
|
do_not_federate = meta[:do_not_federate] || !Config.get([:instance, :federating])
|
||||||
|
|
||||||
if !do_not_federate && local do
|
if !do_not_federate && local do
|
||||||
Federator.publish(activity)
|
Federator.publish(activity)
|
||||||
|
|
|
@ -9,6 +9,11 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
describe "common_pipeline/2" do
|
describe "common_pipeline/2" do
|
||||||
|
setup do
|
||||||
|
clear_config([:instance, :federating], true)
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
test "it goes through validation, filtering, persisting, side effects and federation for local activities" do
|
test "it goes through validation, filtering, persisting, side effects and federation for local activities" do
|
||||||
activity = insert(:note_activity)
|
activity = insert(:note_activity)
|
||||||
meta = [local: true]
|
meta = [local: true]
|
||||||
|
@ -83,5 +88,44 @@ test "it goes through validation, filtering, persisting, side effects without fe
|
||||||
assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))
|
assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it goes through validation, filtering, persisting, side effects without federation for local activities if federation is deactivated" do
|
||||||
|
clear_config([:instance, :federating], false)
|
||||||
|
|
||||||
|
activity = insert(:note_activity)
|
||||||
|
meta = [local: true]
|
||||||
|
|
||||||
|
with_mocks([
|
||||||
|
{Pleroma.Web.ActivityPub.ObjectValidator, [], [validate: fn o, m -> {:ok, o, m} end]},
|
||||||
|
{
|
||||||
|
Pleroma.Web.ActivityPub.MRF,
|
||||||
|
[],
|
||||||
|
[filter: fn o -> {:ok, o} end]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Pleroma.Web.ActivityPub.ActivityPub,
|
||||||
|
[],
|
||||||
|
[persist: fn o, m -> {:ok, o, m} end]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Pleroma.Web.ActivityPub.SideEffects,
|
||||||
|
[],
|
||||||
|
[handle: fn o, m -> {:ok, o, m} end]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Pleroma.Web.Federator,
|
||||||
|
[],
|
||||||
|
[]
|
||||||
|
}
|
||||||
|
]) do
|
||||||
|
assert {:ok, ^activity, ^meta} =
|
||||||
|
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||||
|
|
||||||
|
assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
|
||||||
|
assert_called(Pleroma.Web.ActivityPub.MRF.filter(activity))
|
||||||
|
assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))
|
||||||
|
assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue