Sever subscription in case of block

This commit is contained in:
Sadposter 2019-04-08 12:46:12 +01:00
parent 76fdfd1c7f
commit 13ff312c48
No known key found for this signature in database
GPG Key ID: 6F3BAD60DE190290
2 changed files with 49 additions and 7 deletions

View File

@ -924,16 +924,25 @@ def unmute(muter, %{ap_id: ap_id}) do
end end
def subscribe(subscriber, %{ap_id: ap_id}) do def subscribe(subscriber, %{ap_id: ap_id}) do
with %User{} = user <- get_or_fetch_by_ap_id(ap_id) do user_config = Application.get_env(:pleroma, :user)
deny_follow_blocked = Keyword.get(user_config, :deny_follow_blocked)
with %User{} = subscribed <- get_or_fetch_by_ap_id(ap_id) do
blocked = blocks?(subscribed, subscriber) and deny_follow_blocked
if blocked do
{:error, "Could not subscribe: #{subscribed.nickname} is blocking you"}
else
info_cng = info_cng =
user.info subscribed.info
|> User.Info.add_to_subscribers(subscriber.ap_id) |> User.Info.add_to_subscribers(subscriber.ap_id)
change(user) change(subscribed)
|> put_embed(:info, info_cng) |> put_embed(:info, info_cng)
|> update_and_set_cache() |> update_and_set_cache()
end end
end end
end
def unsubscribe(unsubscriber, %{ap_id: ap_id}) do def unsubscribe(unsubscriber, %{ap_id: ap_id}) do
with %User{} = user <- get_or_fetch_by_ap_id(ap_id) do with %User{} = user <- get_or_fetch_by_ap_id(ap_id) do
@ -957,6 +966,14 @@ def block(blocker, %User{ap_id: ap_id} = blocked) do
blocker blocker
end end
blocker =
if subscribed_to?(blocked, blocker) do
{:ok, blocker} = unsubscribe(blocked, blocker)
blocker
else
blocker
end
if following?(blocked, blocker) do if following?(blocked, blocker) do
unfollow(blocked, blocker) unfollow(blocked, blocker)
end end

View File

@ -146,6 +146,15 @@ test "can't follow a user who blocked us" do
{:error, _} = User.follow(blockee, blocker) {:error, _} = User.follow(blockee, blocker)
end end
test "can't subscribe to a user who blocked us" do
blocker = insert(:user)
blocked = insert(:user)
{:ok, blocker} = User.block(blocker, blocked)
{:error, _} = User.subscribe(blocked, blocker)
end
test "local users do not automatically follow local locked accounts" do test "local users do not automatically follow local locked accounts" do
follower = insert(:user, info: %{locked: true}) follower = insert(:user, info: %{locked: true})
followed = insert(:user, info: %{locked: true}) followed = insert(:user, info: %{locked: true})
@ -729,6 +738,22 @@ test "blocks tear down blocked->blocker follow relationships" do
refute User.following?(blocker, blocked) refute User.following?(blocker, blocked)
refute User.following?(blocked, blocker) refute User.following?(blocked, blocker)
end end
test "blocks tear down blocked->blocker subscription relationships" do
blocker = insert(:user)
blocked = insert(:user)
{:ok, blocker} = User.subscribe(blocked, blocker)
assert User.subscribed_to?(blocked, blocker)
refute User.subscribed_to?(blocker, blocked)
{:ok, blocker} = User.block(blocker, blocked)
assert User.blocks?(blocker, blocked)
refute User.subscribed_to?(blocker, blocked)
refute User.subscribed_to?(blocked, blocker)
end
end end
describe "domain blocking" do describe "domain blocking" do