use Ecto.Schema
alias Pleroma.EctoType.ActivityPub.ObjectValidators
+ alias Pleroma.User
import Ecto.Changeset
import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
|> validate_inclusion(:type, ["Block"])
|> validate_actor_presence()
|> validate_actor_presence(field_name: :object)
+ |> validate_block_acceptance()
end
def cast_and_validate(data) do
|> cast_data
|> validate_data
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
) do
with %User{} = blocker <- User.get_cached_by_ap_id(blocking_user),
%User{} = blocked <- User.get_cached_by_ap_id(blocked_user) do
- User.unfollow(blocker, blocked)
User.block(blocker, blocked)
end
describe "blocks" do
setup do
- user = insert(:user)
+ user = insert(:user, local: false)
blocked = insert(:user)
{:ok, valid_block, []} = Builder.block(user, blocked)
assert {:error, _cng} = ObjectValidator.validate(block, [])
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