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,14 +924,23 @@ def unmute(muter, %{ap_id: ap_id}) do
end
def subscribe(subscriber, %{ap_id: ap_id}) do
with %User{} = user <- get_or_fetch_by_ap_id(ap_id) do
info_cng =
user.info
|> User.Info.add_to_subscribers(subscriber.ap_id)
user_config = Application.get_env(:pleroma, :user)
deny_follow_blocked = Keyword.get(user_config, :deny_follow_blocked)
change(user)
|> put_embed(:info, info_cng)
|> update_and_set_cache()
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 =
subscribed.info
|> User.Info.add_to_subscribers(subscriber.ap_id)
change(subscribed)
|> put_embed(:info, info_cng)
|> update_and_set_cache()
end
end
end
@ -957,6 +966,14 @@ def block(blocker, %User{ap_id: ap_id} = blocked) do
blocker
end
blocker =
if subscribed_to?(blocked, blocker) do
{:ok, blocker} = unsubscribe(blocked, blocker)
blocker
else
blocker
end
if following?(blocked, blocker) do
unfollow(blocked, blocker)
end

View file

@ -146,6 +146,15 @@ test "can't follow a user who blocked us" do
{:error, _} = User.follow(blockee, blocker)
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
follower = 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?(blocked, blocker)
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
describe "domain blocking" do