forked from YokaiRick/akkoma
BlockValidator: Restore old behavior for incoming blocks.
This commit is contained in:
parent
84f9ca1956
commit
c3383d4fab
3 changed files with 20 additions and 2 deletions
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.BlockValidator do
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
|
|
||||||
alias Pleroma.EctoType.ActivityPub.ObjectValidators
|
alias Pleroma.EctoType.ActivityPub.ObjectValidators
|
||||||
|
alias Pleroma.User
|
||||||
|
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
|
import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
|
||||||
|
@ -32,6 +33,7 @@ def validate_data(cng) do
|
||||||
|> validate_inclusion(:type, ["Block"])
|
|> validate_inclusion(:type, ["Block"])
|
||||||
|> validate_actor_presence()
|
|> validate_actor_presence()
|
||||||
|> validate_actor_presence(field_name: :object)
|
|> validate_actor_presence(field_name: :object)
|
||||||
|
|> validate_block_acceptance()
|
||||||
end
|
end
|
||||||
|
|
||||||
def cast_and_validate(data) do
|
def cast_and_validate(data) do
|
||||||
|
@ -39,4 +41,15 @@ def cast_and_validate(data) do
|
||||||
|> cast_data
|
|> cast_data
|
||||||
|> validate_data
|
|> validate_data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def validate_block_acceptance(cng) do
|
||||||
|
actor = get_field(cng, :actor) |> User.get_cached_by_ap_id()
|
||||||
|
|
||||||
|
if actor.local || Pleroma.Config.get([:activitypub, :unfollow_blocked], true) do
|
||||||
|
cng
|
||||||
|
else
|
||||||
|
cng
|
||||||
|
|> add_error(:actor, "Not accepting remote blocks")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,7 +29,6 @@ def handle(
|
||||||
) do
|
) do
|
||||||
with %User{} = blocker <- User.get_cached_by_ap_id(blocking_user),
|
with %User{} = blocker <- User.get_cached_by_ap_id(blocking_user),
|
||||||
%User{} = blocked <- User.get_cached_by_ap_id(blocked_user) do
|
%User{} = blocked <- User.get_cached_by_ap_id(blocked_user) do
|
||||||
User.unfollow(blocker, blocked)
|
|
||||||
User.block(blocker, blocked)
|
User.block(blocker, blocked)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -657,7 +657,7 @@ test "returns an error if the object can't be updated by the actor", %{
|
||||||
|
|
||||||
describe "blocks" do
|
describe "blocks" do
|
||||||
setup do
|
setup do
|
||||||
user = insert(:user)
|
user = insert(:user, local: false)
|
||||||
blocked = insert(:user)
|
blocked = insert(:user)
|
||||||
|
|
||||||
{:ok, valid_block, []} = Builder.block(user, blocked)
|
{:ok, valid_block, []} = Builder.block(user, blocked)
|
||||||
|
@ -680,5 +680,11 @@ test "returns an error if we don't know the blocked user", %{
|
||||||
|
|
||||||
assert {:error, _cng} = ObjectValidator.validate(block, [])
|
assert {:error, _cng} = ObjectValidator.validate(block, [])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "returns an error if don't accept remote blocks", %{valid_block: valid_block} do
|
||||||
|
clear_config([:activitypub, :unfollow_blocked], false)
|
||||||
|
|
||||||
|
assert {:error, _cng} = ObjectValidator.validate(valid_block, [])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue