BlockValidator: Restore old behavior for incoming blocks.
authorlain <lain@soykaf.club>
Fri, 26 Jun 2020 09:58:40 +0000 (11:58 +0200)
committerlain <lain@soykaf.club>
Fri, 26 Jun 2020 09:58:40 +0000 (11:58 +0200)
lib/pleroma/web/activity_pub/object_validators/block_validator.ex
lib/pleroma/web/activity_pub/side_effects.ex
test/web/activity_pub/object_validator_test.exs

index 1dde771985749524bed1c03e238a374f25bfac65..1989585b7b92dbaae2fce0d760129a18b9c9b94c 100644 (file)
@@ -6,6 +6,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.BlockValidator do
   use Ecto.Schema
 
   alias Pleroma.EctoType.ActivityPub.ObjectValidators
+  alias Pleroma.User
 
   import Ecto.Changeset
   import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
@@ -32,6 +33,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.BlockValidator do
     |> validate_inclusion(:type, ["Block"])
     |> validate_actor_presence()
     |> validate_actor_presence(field_name: :object)
+    |> validate_block_acceptance()
   end
 
   def cast_and_validate(data) do
@@ -39,4 +41,15 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.BlockValidator 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
index 48350d2b3fab9211259c283fa9751887a5e6948b..5cc2eb378d76a62a9a429ebe9d285f34dc318a62 100644 (file)
@@ -29,7 +29,6 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
       ) 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
 
index e9655276354a0257ebed20c01ed7d2933365e6bb..a3d43ef3cc7fb4914b6b6e95793dc16167c35b68 100644 (file)
@@ -657,7 +657,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidatorTest do
 
   describe "blocks" do
     setup do
-      user = insert(:user)
+      user = insert(:user, local: false)
       blocked = insert(:user)
 
       {:ok, valid_block, []} = Builder.block(user, blocked)
@@ -680,5 +680,11 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidatorTest do
 
       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