Merge branch '1757-fix-unblocks-too' into 'develop'

CommonAPI: Unblock a user even if we don't have an activity.

Closes #1757

See merge request pleroma/pleroma!2538
This commit is contained in:
rinpatch 2020-05-16 11:17:14 +00:00
commit 3bc1138dd9
2 changed files with 24 additions and 1 deletions

View file

@ -25,10 +25,21 @@ defmodule Pleroma.Web.CommonAPI do
require Logger require Logger
def unblock(blocker, blocked) do def unblock(blocker, blocked) do
with %Activity{} = block <- Utils.fetch_latest_block(blocker, blocked), with {_, %Activity{} = block} <- {:fetch_block, Utils.fetch_latest_block(blocker, blocked)},
{:ok, unblock_data, _} <- Builder.undo(blocker, block), {:ok, unblock_data, _} <- Builder.undo(blocker, block),
{:ok, unblock, _} <- Pipeline.common_pipeline(unblock_data, local: true) do {:ok, unblock, _} <- Pipeline.common_pipeline(unblock_data, local: true) do
{:ok, unblock} {:ok, unblock}
else
{:fetch_block, nil} ->
if User.blocks?(blocker, blocked) do
User.unblock(blocker, blocked)
{:ok, :no_activity}
else
{:error, :not_blocking}
end
e ->
e
end end
end end

View file

@ -23,6 +23,18 @@ defmodule Pleroma.Web.CommonAPITest do
setup do: clear_config([:instance, :limit]) setup do: clear_config([:instance, :limit])
setup do: clear_config([:instance, :max_pinned_statuses]) setup do: clear_config([:instance, :max_pinned_statuses])
describe "unblocking" do
test "it works even without an existing block activity" do
blocked = insert(:user)
blocker = insert(:user)
User.block(blocker, blocked)
assert User.blocks?(blocker, blocked)
assert {:ok, :no_activity} == CommonAPI.unblock(blocker, blocked)
refute User.blocks?(blocker, blocked)
end
end
describe "deletion" do describe "deletion" do
test "it works with pruned objects" do test "it works with pruned objects" do
user = insert(:user) user = insert(:user)