[#1335] User: refactored :blocks field into :blocked_users relation.
authorIvan Tashkinov <ivantashkinov@gmail.com>
Sun, 10 Nov 2019 13:30:21 +0000 (16:30 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Sun, 10 Nov 2019 13:30:21 +0000 (16:30 +0300)
Introduced UserBlock.

20 files changed:
lib/pleroma/notification.ex
lib/pleroma/user.ex
lib/pleroma/user/search.ex
lib/pleroma/user_block.ex [new file with mode: 0644]
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/mastodon_api/controllers/account_controller.ex
lib/pleroma/web/streamer/worker.ex
priv/repo/migrations/20191108161911_create_user_blocks.exs [new file with mode: 0644]
priv/repo/migrations/20191108173911_data_migration_populate_user_blocks.exs [new file with mode: 0644]
test/conversation/participation_test.exs
test/notification_test.exs
test/user_test.exs
test/web/activity_pub/activity_pub_test.exs
test/web/activity_pub/transmogrifier/follow_handling_test.exs
test/web/mastodon_api/controllers/account_controller_test.exs
test/web/mastodon_api/controllers/status_controller_test.exs
test/web/mastodon_api/controllers/timeline_controller_test.exs
test/web/mastodon_api/views/account_view_test.exs
test/web/streamer/streamer_test.exs
test/web/twitter_api/util_controller_test.exs

index b7ecf51e4681fc9a25b8d1cd9d596c928f930bba..82faef85e3e28bd3053cb8fe72fea66c40b99060 100644 (file)
@@ -60,8 +60,10 @@ defmodule Pleroma.Notification do
   end
 
   defp exclude_blocked(query, user) do
+    blocked_ap_ids = User.blocked_ap_ids(user)
+
     query
-    |> where([n, a], a.actor not in ^user.blocks)
+    |> where([n, a], a.actor not in ^blocked_ap_ids)
     |> where(
       [n, a],
       fragment("substring(? from '.*://([^/]*)')", a.actor) not in ^user.domain_blocks
index f8c2db1e1ebc3b1128c288db28f2229970d1c779..d4fc1c093d2197b56335e58e582f2a5913522dfc 100644 (file)
@@ -7,6 +7,7 @@ defmodule Pleroma.User do
 
   import Ecto.Changeset
   import Ecto.Query
+  import Ecto, only: [assoc: 2]
 
   alias Comeonin.Pbkdf2
   alias Ecto.Multi
@@ -21,6 +22,7 @@ defmodule Pleroma.User do
   alias Pleroma.Repo
   alias Pleroma.RepoStreamer
   alias Pleroma.User
+  alias Pleroma.UserBlock
   alias Pleroma.Web
   alias Pleroma.Web.ActivityPub.ActivityPub
   alias Pleroma.Web.ActivityPub.Utils
@@ -74,7 +76,6 @@ defmodule Pleroma.User do
     field(:password_reset_pending, :boolean, default: false)
     field(:confirmation_token, :string, default: nil)
     field(:default_scope, :string, default: "public")
-    field(:blocks, {:array, :string}, default: [])
     field(:domain_blocks, {:array, :string}, default: [])
     field(:mutes, {:array, :string}, default: [])
     field(:muted_reblogs, {:array, :string}, default: [])
@@ -118,9 +119,16 @@ defmodule Pleroma.User do
     has_many(:notifications, Notification)
     has_many(:registrations, Registration)
     has_many(:deliveries, Delivery)
+    has_many(:blocker_blocks, UserBlock, foreign_key: :blocker_id)
+    has_many(:blockee_blocks, UserBlock, foreign_key: :blockee_id)
+    has_many(:blocked_users, through: [:blocker_blocks, :blockee])
+    has_many(:blocker_users, through: [:blockee_blocks, :blocker])
 
     field(:info, :map, default: %{})
 
+    # `:blocks` is deprecated (replaced with `blocked_users` relation)
+    field(:blocks, {:array, :string}, default: [])
+
     timestamps()
   end
 
@@ -986,7 +994,7 @@ defmodule Pleroma.User do
     end
   end
 
-  def block(blocker, %User{ap_id: ap_id} = blocked) do
+  def block(blocker, %User{} = blocked) do
     # sever any follow relationships to prevent leaks per activitypub (Pleroma issue #213)
     blocker =
       if following?(blocker, blocked) do
@@ -1015,7 +1023,7 @@ defmodule Pleroma.User do
 
     {:ok, blocker} = update_follower_count(blocker)
     {:ok, blocker, _} = Participation.mark_all_as_read(blocker, blocked)
-    add_to_block(blocker, ap_id)
+    add_to_block(blocker, blocked)
   end
 
   # helper to handle the block given only an actor's AP id
@@ -1023,8 +1031,13 @@ defmodule Pleroma.User do
     block(blocker, get_cached_by_ap_id(ap_id))
   end
 
+  def unblock(blocker, %User{} = blocked) do
+    remove_from_block(blocker, blocked)
+  end
+
+  # helper to handle the block given only an actor's AP id
   def unblock(blocker, %{ap_id: ap_id}) do
-    remove_from_block(blocker, ap_id)
+    unblock(blocker, get_cached_by_ap_id(ap_id))
   end
 
   def mutes?(nil, _), do: false
@@ -1043,7 +1056,7 @@ defmodule Pleroma.User do
   def blocks?(nil, _), do: false
 
   def blocks_ap_id?(%User{} = user, %User{} = target) do
-    Enum.member?(user.blocks, target.ap_id)
+    UserBlock.exists?(user, target)
   end
 
   def blocks_ap_id?(_, _), do: false
@@ -1070,10 +1083,20 @@ defmodule Pleroma.User do
 
   @spec blocked_users(User.t()) :: [User.t()]
   def blocked_users(user) do
-    User.Query.build(%{ap_id: user.blocks, deactivated: false})
+    user
+    |> assoc(:blocked_users)
+    |> restrict_deactivated()
     |> Repo.all()
   end
 
+  def blocked_ap_ids(user) do
+    Repo.all(
+      from(u in assoc(user, :blocked_users),
+        select: u.ap_id
+      )
+    )
+  end
+
   @spec subscribers(User.t()) :: [User.t()]
   def subscribers(user) do
     User.Query.build(%{ap_id: user.subscribers, deactivated: false})
@@ -1179,7 +1202,7 @@ defmodule Pleroma.User do
       blocked_identifiers,
       fn blocked_identifier ->
         with {:ok, %User{} = blocked} <- get_or_fetch(blocked_identifier),
-             {:ok, blocker} <- block(blocker, blocked),
+             {:ok, _user_block} <- block(blocker, blocked),
              {:ok, _} <- ActivityPub.block(blocker, blocked) do
           blocked
         else
@@ -1844,21 +1867,15 @@ defmodule Pleroma.User do
     set_domain_blocks(user, List.delete(user.domain_blocks, domain_blocked))
   end
 
-  defp set_blocks(user, blocks) do
-    params = %{blocks: blocks}
-
-    user
-    |> cast(params, [:blocks])
-    |> validate_required([:blocks])
-    |> update_and_set_cache()
-  end
-
-  def add_to_block(user, blocked) do
-    set_blocks(user, Enum.uniq([blocked | user.blocks]))
+  @spec add_to_block(User.t(), User.t()) :: {:ok, UserBlock.t()} | {:error, Ecto.Changeset.t()}
+  defp add_to_block(%User{} = user, %User{} = blocked) do
+    UserBlock.create(user, blocked)
   end
 
-  def remove_from_block(user, blocked) do
-    set_blocks(user, List.delete(user.blocks, blocked))
+  @spec add_to_block(User.t(), User.t()) ::
+          {:ok, UserBlock.t()} | {:ok, nil} | {:error, Ecto.Changeset.t()}
+  defp remove_from_block(%User{} = user, %User{} = blocked) do
+    UserBlock.delete(user, blocked)
   end
 
   defp set_mutes(user, mutes) do
index 09664db76b7393a144c9d54972ba3a884eabb7bf..8fa1e2e979f88f0e42ce62ada245bacb2320bf9e 100644 (file)
@@ -98,9 +98,18 @@ defmodule Pleroma.User.Search do
   defp base_query(_user, false), do: User
   defp base_query(user, true), do: User.get_followers_query(user)
 
-  defp filter_blocked_user(query, %User{blocks: blocks})
-       when length(blocks) > 0 do
-    from(q in query, where: not (q.ap_id in ^blocks))
+  defp filter_blocked_user(query, %User{} = blocker) do
+    blocker_id = FlakeId.from_string(blocker.id)
+
+    from(
+      q in query,
+      where:
+        fragment(
+          "? NOT IN (SELECT blockee_id FROM user_blocks WHERE user_blocks.blocker_id = ?)",
+          q.id,
+          ^blocker_id
+        )
+    )
   end
 
   defp filter_blocked_user(query, _), do: query
diff --git a/lib/pleroma/user_block.ex b/lib/pleroma/user_block.ex
new file mode 100644 (file)
index 0000000..1cdb158
--- /dev/null
@@ -0,0 +1,72 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.UserBlock do
+  use Ecto.Schema
+
+  import Ecto.Changeset
+  import Ecto.Query
+
+  alias Pleroma.Repo
+  alias Pleroma.User
+  alias Pleroma.UserBlock
+
+  schema "user_blocks" do
+    belongs_to(:blocker, User, type: FlakeId.Ecto.CompatType)
+    belongs_to(:blockee, User, type: FlakeId.Ecto.CompatType)
+
+    timestamps(updated_at: false)
+  end
+
+  def changeset(%UserBlock{} = user_block, params \\ %{}) do
+    user_block
+    |> cast(params, [:blocker_id, :blockee_id])
+    |> validate_required([:blocker_id, :blockee_id])
+    |> unique_constraint(:blockee_id, name: :user_blocks_blocker_id_blockee_id_index)
+    |> validate_not_self_block()
+  end
+
+  def exists?(%User{} = blocker, %User{} = blockee) do
+    UserBlock
+    |> where(blocker_id: ^blocker.id, blockee_id: ^blockee.id)
+    |> Repo.exists?()
+  end
+
+  def create(%User{} = blocker, %User{} = blockee) do
+    %UserBlock{}
+    |> changeset(%{blocker_id: blocker.id, blockee_id: blockee.id})
+    |> Repo.insert(
+      on_conflict: :replace_all_except_primary_key,
+      conflict_target: [:blocker_id, :blockee_id]
+    )
+  end
+
+  def delete(%User{} = blocker, %User{} = blockee) do
+    attrs = %{blocker_id: blocker.id, blockee_id: blockee.id}
+
+    if is_nil(existing_record = Repo.get_by(UserBlock, attrs)) do
+      {:ok, nil}
+    else
+      Repo.delete(existing_record)
+    end
+  end
+
+  defp validate_not_self_block(%Ecto.Changeset{} = changeset) do
+    changeset
+    |> validate_change(:blockee_id, fn _, blockee_id ->
+      if blockee_id == changeset.changes[:blocker_id] || changeset.data.blocker_id do
+        [blockee_id: "can't be equal to blocker_id"]
+      else
+        []
+      end
+    end)
+    |> validate_change(:blocker_id, fn _, blocker_id ->
+      if blocker_id == changeset.changes[:blockee_id] || changeset.data.blockee_id do
+        [blocker_id: "can't be equal to blockee_id"]
+      else
+        []
+      end
+    end)
+  end
+end
index 65dd251f3ea3ddb62ab6b5fa2460e41db288e162..82203ef5c4b50d28880819812aab2c3b5d91993b 100644 (file)
@@ -876,7 +876,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
   defp restrict_muted(query, _), do: query
 
   defp restrict_blocked(query, %{"blocking_user" => %User{} = user}) do
-    blocks = user.blocks || []
+    blocked_ap_ids = User.blocked_ap_ids(user)
     domain_blocks = user.domain_blocks || []
 
     query =
@@ -884,14 +884,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
 
     from(
       [activity, object: o] in query,
-      where: fragment("not (? = ANY(?))", activity.actor, ^blocks),
-      where: fragment("not (? && ?)", activity.recipients, ^blocks),
+      where: fragment("not (? = ANY(?))", activity.actor, ^blocked_ap_ids),
+      where: fragment("not (? && ?)", activity.recipients, ^blocked_ap_ids),
       where:
         fragment(
           "not (?->>'type' = 'Announce' and ?->'to' \\?| ?)",
           activity.data,
           activity.data,
-          ^blocks
+          ^blocked_ap_ids
         ),
       where: fragment("not (split_part(?, '/', 3) = ANY(?))", activity.actor, ^domain_blocks),
       where: fragment("not (split_part(?->>'actor', '/', 3) = ANY(?))", o.data, ^domain_blocks)
index 73fad519ecbe1259f3ab0782beaddbf818943bcc..7c94a35d9d0ab8b86490fdae347e57e75bb339da 100644 (file)
@@ -341,7 +341,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
 
   @doc "POST /api/v1/accounts/:id/block"
   def block(%{assigns: %{user: blocker, account: blocked}} = conn, _params) do
-    with {:ok, blocker} <- User.block(blocker, blocked),
+    with {:ok, _user_block} <- User.block(blocker, blocked),
          {:ok, _activity} <- ActivityPub.block(blocker, blocked) do
       render(conn, "relationship.json", user: blocker, target: blocked)
     else
@@ -351,7 +351,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
 
   @doc "POST /api/v1/accounts/:id/unblock"
   def unblock(%{assigns: %{user: blocker, account: blocked}} = conn, _params) do
-    with {:ok, blocker} <- User.unblock(blocker, blocked),
+    with {:ok, _user_block} <- User.unblock(blocker, blocked),
          {:ok, _activity} <- ActivityPub.unblock(blocker, blocked) do
       render(conn, "relationship.json", user: blocker, target: blocked)
     else
index 33b24840d1794c17625c03507f6667c68f17fb35..672dd52ee67731e9eb592ff73a14b36077e94da6 100644 (file)
@@ -129,7 +129,7 @@ defmodule Pleroma.Web.Streamer.Worker do
   end
 
   defp should_send?(%User{} = user, %Activity{} = item) do
-    blocks = user.blocks || []
+    blocks = User.blocked_ap_ids(user)
     mutes = user.mutes || []
     reblog_mutes = user.muted_reblogs || []
     recipient_blocks = MapSet.new(blocks ++ mutes)
diff --git a/priv/repo/migrations/20191108161911_create_user_blocks.exs b/priv/repo/migrations/20191108161911_create_user_blocks.exs
new file mode 100644 (file)
index 0000000..c882d2b
--- /dev/null
@@ -0,0 +1,14 @@
+defmodule Pleroma.Repo.Migrations.CreateUserBlocks do
+  use Ecto.Migration
+
+  def change do
+    create_if_not_exists table(:user_blocks) do
+      add(:blocker_id, references(:users, type: :uuid, on_delete: :delete_all))
+      add(:blockee_id, references(:users, type: :uuid, on_delete: :delete_all))
+
+      timestamps(updated_at: false)
+    end
+
+    create_if_not_exists(unique_index(:user_blocks, [:blocker_id, :blockee_id]))
+  end
+end
diff --git a/priv/repo/migrations/20191108173911_data_migration_populate_user_blocks.exs b/priv/repo/migrations/20191108173911_data_migration_populate_user_blocks.exs
new file mode 100644 (file)
index 0000000..728da82
--- /dev/null
@@ -0,0 +1,50 @@
+defmodule Pleroma.Repo.Migrations.DataMigrationPopulateUserBlocks do
+  use Ecto.Migration
+
+  alias Ecto.Adapters.SQL
+  alias Pleroma.Repo
+
+  require Logger
+
+  def up do
+    {:ok, %{rows: block_rows}} =
+      SQL.query(Repo, "SELECT id, blocks FROM users WHERE blocks != '{}'")
+
+    blockee_ap_ids =
+      Enum.flat_map(
+        block_rows,
+        fn [_, ap_ids] -> ap_ids end
+      )
+      |> Enum.uniq()
+
+    # Selecting ids of all blockees at once in order to reduce the number of SELECT queries
+    {:ok, %{rows: blockee_ap_id_id}} =
+      SQL.query(Repo, "SELECT ap_id, id FROM users WHERE ap_id = ANY($1)", [blockee_ap_ids])
+
+    blockee_id_by_ap_id = Enum.into(blockee_ap_id_id, %{}, fn [k, v] -> {k, v} end)
+
+    Enum.each(
+      block_rows,
+      fn [blocker_id, blockee_ap_ids] ->
+        blocker_uuid = Ecto.UUID.cast!(blocker_id)
+
+        for blockee_ap_id <- blockee_ap_ids do
+          blockee_id = blockee_id_by_ap_id[blockee_ap_id]
+          blockee_uuid = blockee_id && Ecto.UUID.cast!(blockee_id)
+
+          with {:ok, blockee_uuid} <- Ecto.UUID.cast(blockee_id) do
+            execute(
+              "INSERT INTO user_blocks(blocker_id, blockee_id, inserted_at) " <>
+                "VALUES('#{blocker_uuid}'::uuid, '#{blockee_uuid}'::uuid, now()) " <>
+                "ON CONFLICT (blocker_id, blockee_id) DO NOTHING"
+            )
+          else
+            _ -> Logger.warn("Missing reference: (#{blocker_uuid}, #{blockee_id})")
+          end
+        end
+      end
+    )
+  end
+
+  def down, do: :noop
+end
index 863270022e8c0f8ac8675277114642cc46498598..a36f45a5a9747f5d3625fc6b315da774c2307cf1 100644 (file)
@@ -252,7 +252,7 @@ defmodule Pleroma.Conversation.ParticipationTest do
 
       assert User.get_cached_by_id(blocker.id).unread_conversation_count == 4
 
-      {:ok, blocker} = User.block(blocker, blocked)
+      {:ok, _user_block} = User.block(blocker, blocked)
 
       # The conversations with the blocked user are marked as read
       assert [%{read: true}, %{read: true}, %{read: true}, %{read: false}] =
@@ -274,7 +274,7 @@ defmodule Pleroma.Conversation.ParticipationTest do
       blocked = insert(:user)
       third_user = insert(:user)
 
-      {:ok, blocker} = User.block(blocker, blocked)
+      {:ok, _user_block} = User.block(blocker, blocked)
 
       # When the blocked user is the author
       {:ok, _direct1} =
@@ -311,7 +311,7 @@ defmodule Pleroma.Conversation.ParticipationTest do
           "visibility" => "direct"
         })
 
-      {:ok, blocker} = User.block(blocker, blocked)
+      {:ok, _user_block} = User.block(blocker, blocked)
       assert [%{read: true}] = Participation.for_user(blocker)
       assert User.get_cached_by_id(blocker.id).unread_conversation_count == 0
 
index f8d42922322353a2d509dc8fc2c4c33313db186a..5388214baa921b7912b5e712f3bfedc5f162270d 100644 (file)
@@ -93,7 +93,7 @@ defmodule Pleroma.NotificationTest do
       activity = insert(:note_activity)
       author = User.get_cached_by_ap_id(activity.data["actor"])
       user = insert(:user)
-      {:ok, user} = User.block(user, author)
+      {:ok, _user_block} = User.block(user, author)
 
       assert Notification.create_notification(activity, user)
     end
@@ -656,7 +656,7 @@ defmodule Pleroma.NotificationTest do
     test "it doesn't return notifications for blocked user" do
       user = insert(:user)
       blocked = insert(:user)
-      {:ok, user} = User.block(user, blocked)
+      {:ok, _user_block} = User.block(user, blocked)
 
       {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
 
@@ -696,7 +696,7 @@ defmodule Pleroma.NotificationTest do
     test "it doesn't return notifications from a blocked user when with_muted is set" do
       user = insert(:user)
       blocked = insert(:user)
-      {:ok, user} = User.block(user, blocked)
+      {:ok, _user_block} = User.block(user, blocked)
 
       {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
 
index 6b1b24ce5fd2ef5693937bd867b067fe420d5bd3..fa8d336f27160cd3c52525bf43b2af35c96e094d 100644 (file)
@@ -100,7 +100,7 @@ defmodule Pleroma.UserTest do
     CommonAPI.follow(follower, followed)
     assert [_activity] = User.get_follow_requests(followed)
 
-    {:ok, _follower} = User.block(followed, follower)
+    {:ok, _user_block} = User.block(followed, follower)
     assert [] = User.get_follow_requests(followed)
   end
 
@@ -113,8 +113,8 @@ defmodule Pleroma.UserTest do
     not_followed = insert(:user)
     reverse_blocked = insert(:user)
 
-    {:ok, user} = User.block(user, blocked)
-    {:ok, reverse_blocked} = User.block(reverse_blocked, user)
+    {:ok, _user_block} = User.block(user, blocked)
+    {:ok, _user_block} = User.block(reverse_blocked, user)
 
     {:ok, user} = User.follow(user, followed_zero)
 
@@ -166,7 +166,7 @@ defmodule Pleroma.UserTest do
     blocker = insert(:user)
     blockee = insert(:user)
 
-    {:ok, blocker} = User.block(blocker, blockee)
+    {:ok, _user_block} = User.block(blocker, blockee)
 
     {:error, _} = User.follow(blockee, blocker)
   end
@@ -175,7 +175,7 @@ defmodule Pleroma.UserTest do
     blocker = insert(:user)
     blocked = insert(:user)
 
-    {:ok, blocker} = User.block(blocker, blocked)
+    {:ok, _user_block} = User.block(blocker, blocked)
 
     {:error, _} = User.subscribe(blocked, blocker)
   end
@@ -711,7 +711,7 @@ defmodule Pleroma.UserTest do
 
       refute User.blocks?(user, blocked_user)
 
-      {:ok, user} = User.block(user, blocked_user)
+      {:ok, _user_block} = User.block(user, blocked_user)
 
       assert User.blocks?(user, blocked_user)
     end
@@ -720,8 +720,8 @@ defmodule Pleroma.UserTest do
       user = insert(:user)
       blocked_user = insert(:user)
 
-      {:ok, user} = User.block(user, blocked_user)
-      {:ok, user} = User.unblock(user, blocked_user)
+      {:ok, _user_block} = User.block(user, blocked_user)
+      {:ok, _user_block} = User.unblock(user, blocked_user)
 
       refute User.blocks?(user, blocked_user)
     end
@@ -736,7 +736,7 @@ defmodule Pleroma.UserTest do
       assert User.following?(blocker, blocked)
       assert User.following?(blocked, blocker)
 
-      {:ok, blocker} = User.block(blocker, blocked)
+      {:ok, _user_block} = User.block(blocker, blocked)
       blocked = User.get_cached_by_id(blocked.id)
 
       assert User.blocks?(blocker, blocked)
@@ -754,7 +754,7 @@ defmodule Pleroma.UserTest do
       assert User.following?(blocker, blocked)
       refute User.following?(blocked, blocker)
 
-      {:ok, blocker} = User.block(blocker, blocked)
+      {:ok, _user_block} = User.block(blocker, blocked)
       blocked = User.get_cached_by_id(blocked.id)
 
       assert User.blocks?(blocker, blocked)
@@ -772,7 +772,7 @@ defmodule Pleroma.UserTest do
       refute User.following?(blocker, blocked)
       assert User.following?(blocked, blocker)
 
-      {:ok, blocker} = User.block(blocker, blocked)
+      {:ok, _user_block} = User.block(blocker, blocked)
       blocked = User.get_cached_by_id(blocked.id)
 
       assert User.blocks?(blocker, blocked)
@@ -790,7 +790,7 @@ defmodule Pleroma.UserTest do
       assert User.subscribed_to?(blocked, blocker)
       refute User.subscribed_to?(blocker, blocked)
 
-      {:ok, blocker} = User.block(blocker, blocked)
+      {:ok, _user_block} = User.block(blocker, blocked)
 
       assert User.blocks?(blocker, blocked)
       refute User.subscribed_to?(blocker, blocked)
@@ -1313,7 +1313,8 @@ defmodule Pleroma.UserTest do
     {:ok, _follower2} = User.follow(follower2, user)
     {:ok, _follower3} = User.follow(follower3, user)
 
-    {:ok, user} = User.block(user, follower)
+    {:ok, _user_block} = User.block(user, follower)
+    user = refresh_record(user)
 
     assert User.user_info(user).follower_count == 2
   end
index 0d0281fafeeb4ee333f5b9b42ed2878bc5c360f3..17d283954f5cc7274b941a76004d6dcc0a9bf588 100644 (file)
@@ -484,7 +484,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
       activity_five = insert(:note_activity)
       user = insert(:user)
 
-      {:ok, user} = User.block(user, %{ap_id: activity_five.data["actor"]})
+      {:ok, _user_block} = User.block(user, %{ap_id: activity_five.data["actor"]})
 
       activities = ActivityPub.fetch_activities_for_context("2hu", %{"blocking_user" => user})
       assert activities == [activity_two, activity]
@@ -497,7 +497,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
     activity_three = insert(:note_activity)
     user = insert(:user)
     booster = insert(:user)
-    {:ok, user} = User.block(user, %{ap_id: activity_one.data["actor"]})
+    {:ok, _user_block} = User.block(user, %{ap_id: activity_one.data["actor"]})
 
     activities =
       ActivityPub.fetch_activities([], %{"blocking_user" => user, "skip_preload" => true})
@@ -506,7 +506,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
     assert Enum.member?(activities, activity_three)
     refute Enum.member?(activities, activity_one)
 
-    {:ok, user} = User.unblock(user, %{ap_id: activity_one.data["actor"]})
+    {:ok, _user_block} = User.unblock(user, %{ap_id: activity_one.data["actor"]})
 
     activities =
       ActivityPub.fetch_activities([], %{"blocking_user" => user, "skip_preload" => true})
@@ -515,7 +515,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
     assert Enum.member?(activities, activity_three)
     assert Enum.member?(activities, activity_one)
 
-    {:ok, user} = User.block(user, %{ap_id: activity_three.data["actor"]})
+    {:ok, _user_block} = User.block(user, %{ap_id: activity_three.data["actor"]})
     {:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.repeat(activity_three.id, booster)
     %Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id)
     activity_three = Activity.get_by_id(activity_three.id)
@@ -542,7 +542,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
     blockee = insert(:user)
     friend = insert(:user)
 
-    {:ok, blocker} = User.block(blocker, blockee)
+    {:ok, _user_block} = User.block(blocker, blockee)
 
     {:ok, activity_one} = CommonAPI.post(friend, %{"status" => "hey!"})
 
@@ -565,7 +565,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
     blockee = insert(:user)
     friend = insert(:user)
 
-    {:ok, blocker} = User.block(blocker, blockee)
+    {:ok, _user_block} = User.block(blocker, blockee)
 
     {:ok, activity_one} = CommonAPI.post(friend, %{"status" => "hey!"})
 
index 75cfbea2e284195811b4e18eba5a9bb6bf89ea29..5c67d41c5a31de070e23a469454dc7facfa0384d 100644 (file)
@@ -128,7 +128,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
       user = insert(:user)
       {:ok, target} = User.get_or_fetch("http://mastodon.example.org/users/admin")
 
-      {:ok, user} = User.block(user, target)
+      {:ok, _user_block} = User.block(user, target)
 
       data =
         File.read!("test/fixtures/mastodon-follow-activity.json")
index 8fc2d93005f5cda6ec224ff92eaf078771b19581..b98d9c8e3d6b05dd1f1464e45ede01af79692a5a 100644 (file)
@@ -883,7 +883,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
     user = insert(:user)
     other_user = insert(:user)
 
-    {:ok, user} = User.block(user, other_user)
+    {:ok, _user_block} = User.block(user, other_user)
 
     conn =
       conn
index a96fd860b50fe2edb08996e0cf7af3d5bc93137b..e8a1054acedda452b24161560ba5f8230e530c1e 100644 (file)
@@ -1108,7 +1108,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
       activity: activity
     } do
       other_user = insert(:user)
-      {:ok, user} = User.block(user, other_user)
+      {:ok, _user_block} = User.block(user, other_user)
 
       {:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
 
@@ -1205,7 +1205,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
       activity: activity
     } do
       other_user = insert(:user)
-      {:ok, user} = User.block(user, other_user)
+      {:ok, _user_block} = User.block(user, other_user)
 
       {:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
 
index 61b6cea7547c49ec2d90a115b8cf2e4abd248e3f..524529d1f92266843c86bdbdbfe830b5f371b003 100644 (file)
@@ -194,7 +194,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
       blocker = insert(:user)
       blocked = insert(:user)
       user = insert(:user)
-      {:ok, blocker} = User.block(blocker, blocked)
+      {:ok, _user_block} = User.block(blocker, blocked)
 
       {:ok, _blocked_direct} =
         CommonAPI.post(blocked, %{
index af88841ed234c5f8ba87a49312a79abe302247fe..c34bf7ba990cbcaeb3590d20055cf933e25c459d 100644 (file)
@@ -219,8 +219,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
 
       {:ok, user} = User.follow(user, other_user)
       {:ok, other_user} = User.subscribe(user, other_user)
-      {:ok, user} = User.block(user, other_user)
-      {:ok, other_user} = User.block(other_user, user)
+      {:ok, _user_block} = User.block(user, other_user)
+      {:ok, _user_block} = User.block(other_user, user)
 
       expected = %{
         id: to_string(other_user.id),
@@ -291,7 +291,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
 
     other_user = insert(:user)
     {:ok, other_user} = User.follow(other_user, user)
-    {:ok, other_user} = User.block(other_user, user)
+    {:ok, _user_block} = User.block(other_user, user)
     {:ok, _} = User.follow(insert(:user), user)
 
     expected = %{
index 80a7541b22f3a84bd731737f54ee0d7589e1e914..6461fc4c3c4bf84eaf0c0ce9de79b5fdcc42ca23 100644 (file)
@@ -59,7 +59,7 @@ defmodule Pleroma.Web.StreamerTest do
       user: user
     } do
       blocked = insert(:user)
-      {:ok, user} = User.block(user, blocked)
+      {:ok, _user_block} = User.block(user, blocked)
 
       task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
 
@@ -259,7 +259,7 @@ defmodule Pleroma.Web.StreamerTest do
     test "it doesn't send messages involving blocked users" do
       user = insert(:user)
       blocked_user = insert(:user)
-      {:ok, user} = User.block(user, blocked_user)
+      {:ok, _user_block} = User.block(user, blocked_user)
 
       task =
         Task.async(fn ->
@@ -301,7 +301,7 @@ defmodule Pleroma.Web.StreamerTest do
         "public" => [fake_socket]
       }
 
-      {:ok, blocker} = User.block(blocker, blockee)
+      {:ok, _user_block} = User.block(blocker, blockee)
 
       {:ok, activity_one} = CommonAPI.post(friend, %{"status" => "hey! @#{blockee.nickname}"})
 
index f0211f59c64e4f5681ac7c4ed1cb3462b7386a9a..986ee01f35ecb850f9493045942b4e28873d8e68 100644 (file)
@@ -387,7 +387,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
       user = insert(:user)
       user2 = insert(:user)
 
-      {:ok, _user} = Pleroma.User.block(user2, user)
+      {:ok, _user_block} = Pleroma.User.block(user2, user)
 
       response =
         conn
@@ -485,7 +485,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
       Pleroma.Config.put([:user, :deny_follow_blocked], true)
       user = insert(:user)
       user2 = insert(:user)
-      {:ok, _user} = Pleroma.User.block(user2, user)
+      {:ok, _user_block} = Pleroma.User.block(user2, user)
 
       response =
         conn