From 3db988250bcd279f20bd1742ca454aa187d89368 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Sun, 10 Nov 2019 16:30:21 +0300 Subject: [PATCH] [#1335] User: refactored :blocks field into :blocked_users relation. Introduced UserBlock. --- lib/pleroma/notification.ex | 4 +- lib/pleroma/user.ex | 57 +++++++++------ lib/pleroma/user/search.ex | 15 +++- lib/pleroma/user_block.ex | 72 +++++++++++++++++++ lib/pleroma/web/activity_pub/activity_pub.ex | 8 +-- .../controllers/account_controller.ex | 4 +- lib/pleroma/web/streamer/worker.ex | 2 +- .../20191108161911_create_user_blocks.exs | 14 ++++ ...11_data_migration_populate_user_blocks.exs | 50 +++++++++++++ test/conversation/participation_test.exs | 6 +- test/notification_test.exs | 6 +- test/user_test.exs | 27 +++---- test/web/activity_pub/activity_pub_test.exs | 12 ++-- .../transmogrifier/follow_handling_test.exs | 2 +- .../controllers/account_controller_test.exs | 2 +- .../controllers/status_controller_test.exs | 4 +- .../controllers/timeline_controller_test.exs | 2 +- .../mastodon_api/views/account_view_test.exs | 6 +- test/web/streamer/streamer_test.exs | 6 +- test/web/twitter_api/util_controller_test.exs | 4 +- 20 files changed, 234 insertions(+), 69 deletions(-) create mode 100644 lib/pleroma/user_block.ex create mode 100644 priv/repo/migrations/20191108161911_create_user_blocks.exs create mode 100644 priv/repo/migrations/20191108173911_data_migration_populate_user_blocks.exs diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index b7ecf51e4..82faef85e 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -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 diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index f8c2db1e1..d4fc1c093 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -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 diff --git a/lib/pleroma/user/search.ex b/lib/pleroma/user/search.ex index 09664db76..8fa1e2e97 100644 --- a/lib/pleroma/user/search.ex +++ b/lib/pleroma/user/search.ex @@ -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 index 000000000..1cdb15886 --- /dev/null +++ b/lib/pleroma/user_block.ex @@ -0,0 +1,72 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# 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 diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 65dd251f3..82203ef5c 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -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) diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex index 73fad519e..7c94a35d9 100644 --- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex @@ -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 diff --git a/lib/pleroma/web/streamer/worker.ex b/lib/pleroma/web/streamer/worker.ex index 33b24840d..672dd52ee 100644 --- a/lib/pleroma/web/streamer/worker.ex +++ b/lib/pleroma/web/streamer/worker.ex @@ -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 index 000000000..c882d2bd6 --- /dev/null +++ b/priv/repo/migrations/20191108161911_create_user_blocks.exs @@ -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 index 000000000..728da8211 --- /dev/null +++ b/priv/repo/migrations/20191108173911_data_migration_populate_user_blocks.exs @@ -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 diff --git a/test/conversation/participation_test.exs b/test/conversation/participation_test.exs index 863270022..a36f45a5a 100644 --- a/test/conversation/participation_test.exs +++ b/test/conversation/participation_test.exs @@ -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 diff --git a/test/notification_test.exs b/test/notification_test.exs index f8d429223..5388214ba 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -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}"}) diff --git a/test/user_test.exs b/test/user_test.exs index 6b1b24ce5..fa8d336f2 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -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 diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 0d0281faf..17d283954 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -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!"}) diff --git a/test/web/activity_pub/transmogrifier/follow_handling_test.exs b/test/web/activity_pub/transmogrifier/follow_handling_test.exs index 75cfbea2e..5c67d41c5 100644 --- a/test/web/activity_pub/transmogrifier/follow_handling_test.exs +++ b/test/web/activity_pub/transmogrifier/follow_handling_test.exs @@ -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") diff --git a/test/web/mastodon_api/controllers/account_controller_test.exs b/test/web/mastodon_api/controllers/account_controller_test.exs index 8fc2d9300..b98d9c8e3 100644 --- a/test/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/web/mastodon_api/controllers/account_controller_test.exs @@ -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 diff --git a/test/web/mastodon_api/controllers/status_controller_test.exs b/test/web/mastodon_api/controllers/status_controller_test.exs index a96fd860b..e8a1054ac 100644 --- a/test/web/mastodon_api/controllers/status_controller_test.exs +++ b/test/web/mastodon_api/controllers/status_controller_test.exs @@ -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) diff --git a/test/web/mastodon_api/controllers/timeline_controller_test.exs b/test/web/mastodon_api/controllers/timeline_controller_test.exs index 61b6cea75..524529d1f 100644 --- a/test/web/mastodon_api/controllers/timeline_controller_test.exs +++ b/test/web/mastodon_api/controllers/timeline_controller_test.exs @@ -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, %{ diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs index af88841ed..c34bf7ba9 100644 --- a/test/web/mastodon_api/views/account_view_test.exs +++ b/test/web/mastodon_api/views/account_view_test.exs @@ -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 = %{ diff --git a/test/web/streamer/streamer_test.exs b/test/web/streamer/streamer_test.exs index 80a7541b2..6461fc4c3 100644 --- a/test/web/streamer/streamer_test.exs +++ b/test/web/streamer/streamer_test.exs @@ -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}"}) diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index f0211f59c..986ee01f3 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -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 -- 2.45.2