Merge branch '1757-blocks-breaking-on-disabled-outgoing-blocks' into 'develop'
ActivityPub: Fix non-federating blocks. Closes #1757 See merge request pleroma/pleroma!2514
This commit is contained in:
commit
24c8c13640
|
@ -439,7 +439,6 @@ def block(blocker, blocked, activity_id \\ nil, local \\ true) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp do_block(blocker, blocked, activity_id, local) do
|
defp do_block(blocker, blocked, activity_id, local) do
|
||||||
outgoing_blocks = Config.get([:activitypub, :outgoing_blocks])
|
|
||||||
unfollow_blocked = Config.get([:activitypub, :unfollow_blocked])
|
unfollow_blocked = Config.get([:activitypub, :unfollow_blocked])
|
||||||
|
|
||||||
if unfollow_blocked do
|
if unfollow_blocked do
|
||||||
|
@ -447,8 +446,7 @@ defp do_block(blocker, blocked, activity_id, local) do
|
||||||
if follow_activity, do: unfollow(blocker, blocked, nil, local)
|
if follow_activity, do: unfollow(blocker, blocked, nil, local)
|
||||||
end
|
end
|
||||||
|
|
||||||
with true <- outgoing_blocks,
|
with block_data <- make_block_data(blocker, blocked, activity_id),
|
||||||
block_data <- make_block_data(blocker, blocked, activity_id),
|
|
||||||
{:ok, activity} <- insert(block_data, local),
|
{:ok, activity} <- insert(block_data, local),
|
||||||
_ <- notify_and_stream(activity),
|
_ <- notify_and_stream(activity),
|
||||||
:ok <- maybe_federate(activity) do
|
:ok <- maybe_federate(activity) do
|
||||||
|
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
||||||
alias Ecto.Changeset
|
alias Ecto.Changeset
|
||||||
alias Ecto.UUID
|
alias Ecto.UUID
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
|
alias Pleroma.Config
|
||||||
alias Pleroma.Notification
|
alias Pleroma.Notification
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
|
@ -169,8 +170,11 @@ def create_context(context) do
|
||||||
Enqueues an activity for federation if it's local
|
Enqueues an activity for federation if it's local
|
||||||
"""
|
"""
|
||||||
@spec maybe_federate(any()) :: :ok
|
@spec maybe_federate(any()) :: :ok
|
||||||
def maybe_federate(%Activity{local: true} = activity) do
|
def maybe_federate(%Activity{local: true, data: %{"type" => type}} = activity) do
|
||||||
if Pleroma.Config.get!([:instance, :federating]) do
|
outgoing_blocks = Config.get([:activitypub, :outgoing_blocks])
|
||||||
|
|
||||||
|
with true <- Config.get!([:instance, :federating]),
|
||||||
|
true <- type != "Block" || outgoing_blocks do
|
||||||
Pleroma.Web.Federator.publish(activity)
|
Pleroma.Web.Federator.publish(activity)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1061,14 +1061,38 @@ test "reverts block activity on error" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "creates a block activity" do
|
test "creates a block activity" do
|
||||||
|
clear_config([:instance, :federating], true)
|
||||||
blocker = insert(:user)
|
blocker = insert(:user)
|
||||||
blocked = insert(:user)
|
blocked = insert(:user)
|
||||||
|
|
||||||
{:ok, activity} = ActivityPub.block(blocker, blocked)
|
with_mock Pleroma.Web.Federator,
|
||||||
|
publish: fn _ -> nil end do
|
||||||
|
{:ok, activity} = ActivityPub.block(blocker, blocked)
|
||||||
|
|
||||||
assert activity.data["type"] == "Block"
|
assert activity.data["type"] == "Block"
|
||||||
assert activity.data["actor"] == blocker.ap_id
|
assert activity.data["actor"] == blocker.ap_id
|
||||||
assert activity.data["object"] == blocked.ap_id
|
assert activity.data["object"] == blocked.ap_id
|
||||||
|
|
||||||
|
assert called(Pleroma.Web.Federator.publish(activity))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "works with outgoing blocks disabled, but doesn't federate" do
|
||||||
|
clear_config([:instance, :federating], true)
|
||||||
|
clear_config([:activitypub, :outgoing_blocks], false)
|
||||||
|
blocker = insert(:user)
|
||||||
|
blocked = insert(:user)
|
||||||
|
|
||||||
|
with_mock Pleroma.Web.Federator,
|
||||||
|
publish: fn _ -> nil end do
|
||||||
|
{:ok, activity} = ActivityPub.block(blocker, blocked)
|
||||||
|
|
||||||
|
assert activity.data["type"] == "Block"
|
||||||
|
assert activity.data["actor"] == blocker.ap_id
|
||||||
|
assert activity.data["object"] == blocked.ap_id
|
||||||
|
|
||||||
|
refute called(Pleroma.Web.Federator.publish(:_))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue