User: Don't unfollow on block when the relevant setting is set.
authorlain <lain@soykaf.club>
Fri, 26 Jun 2020 10:06:00 +0000 (12:06 +0200)
committerlain <lain@soykaf.club>
Fri, 26 Jun 2020 10:06:00 +0000 (12:06 +0200)
lib/pleroma/user.ex
lib/pleroma/web/activity_pub/object_validators/block_validator.ex
test/web/activity_pub/object_validator_test.exs
test/web/activity_pub/side_effects_test.exs

index c3e2a89ad37d325ef2561b654cf658a102ddb64f..9d5c61e7981debc500f376941a47c4d8a26c9257 100644 (file)
@@ -1309,7 +1309,8 @@ defmodule Pleroma.User do
 
     unsubscribe(blocked, blocker)
 
-    if following?(blocked, blocker), do: unfollow(blocked, blocker)
+    unfollowing_blocked = Config.get([:activitypub, :unfollow_blocked], true)
+    if unfollowing_blocked && following?(blocked, blocker), do: unfollow(blocked, blocker)
 
     {:ok, blocker} = update_follower_count(blocker)
     {:ok, blocker, _} = Participation.mark_all_as_read(blocker, blocked)
index 1989585b7b92dbaae2fce0d760129a18b9c9b94c..1dde771985749524bed1c03e238a374f25bfac65 100644 (file)
@@ -6,7 +6,6 @@ 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
@@ -33,7 +32,6 @@ 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
@@ -41,15 +39,4 @@ 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 a3d43ef3cc7fb4914b6b6e95793dc16167c35b68..f38bf7e0803ee1ad0eefc98431886f3cf37280a7 100644 (file)
@@ -680,11 +680,5 @@ 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
index 36792f0153303d78d4b86cbe34b26f5304a5273f..af27c34b48edd84df389ccabcbb34929221b0d9d 100644 (file)
@@ -87,6 +87,22 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
       refute User.following?(blocked, user)
       assert User.blocks?(user, blocked)
     end
+
+    test "it blocks but does not unfollow if the relevant setting is set", %{
+      user: user,
+      blocked: blocked,
+      block: block
+    } do
+      clear_config([:activitypub, :unfollow_blocked], false)
+      assert User.following?(user, blocked)
+      assert User.following?(blocked, user)
+
+      {:ok, _, _} = SideEffects.handle(block)
+
+      refute User.following?(user, blocked)
+      assert User.following?(blocked, user)
+      assert User.blocks?(user, blocked)
+    end
   end
 
   describe "update users" do