From 1b560d547a88474559e099c28321a83348f322f6 Mon Sep 17 00:00:00 2001 From: XxXCertifiedForkliftDriverXxX Date: Sun, 28 May 2023 21:42:27 +0000 Subject: [PATCH] Stop exposing if a user blocks you over the API. --- .../api_spec/operations/account_operation.ex | 4 ++-- .../api_spec/schemas/account_relationship.ex | 5 ++++- .../web/mastodon_api/views/account_view.ex | 9 +-------- .../mastodon_api/views/account_view_test.exs | 17 ++++++++++++++++- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/lib/pleroma/web/api_spec/operations/account_operation.ex b/lib/pleroma/web/api_spec/operations/account_operation.ex index 8a6851d52..00a591298 100644 --- a/lib/pleroma/web/api_spec/operations/account_operation.ex +++ b/lib/pleroma/web/api_spec/operations/account_operation.ex @@ -767,7 +767,7 @@ defp array_of_relationships do "showing_reblogs" => true, "followed_by" => true, "blocking" => false, - "blocked_by" => true, + "blocked_by" => false, "muting" => false, "muting_notifications" => false, "note" => "", @@ -783,7 +783,7 @@ defp array_of_relationships do "showing_reblogs" => true, "followed_by" => true, "blocking" => false, - "blocked_by" => true, + "blocked_by" => false, "muting" => true, "muting_notifications" => false, "note" => "", diff --git a/lib/pleroma/web/api_spec/schemas/account_relationship.ex b/lib/pleroma/web/api_spec/schemas/account_relationship.ex index 5d9e3b56e..58751b261 100644 --- a/lib/pleroma/web/api_spec/schemas/account_relationship.ex +++ b/lib/pleroma/web/api_spec/schemas/account_relationship.ex @@ -13,7 +13,10 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationship do description: "Relationship between current account and requested account", type: :object, properties: %{ - blocked_by: %Schema{type: :boolean}, + blocked_by: %Schema{ + type: :boolean, + description: "Represents being blocked by this user. Always false." + }, blocking: %Schema{type: :boolean}, domain_blocking: %Schema{type: :boolean}, endorsed: %Schema{type: :boolean}, diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index e0fa3b033..e3f91a4e3 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -124,14 +124,7 @@ def render( target, &User.blocks_user?(&1, &2) ), - blocked_by: - UserRelationship.exists?( - user_relationships, - :block, - target, - reading_user, - &User.blocks_user?(&1, &2) - ), + blocked_by: false, muting: UserRelationship.exists?( user_relationships, diff --git a/test/pleroma/web/mastodon_api/views/account_view_test.exs b/test/pleroma/web/mastodon_api/views/account_view_test.exs index 6ef89f799..a4f5f1f63 100644 --- a/test/pleroma/web/mastodon_api/views/account_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/account_view_test.exs @@ -397,7 +397,22 @@ test "represent a relationship for the blocking and blocked user" do expected = Map.merge( @blank_response, - %{following: false, blocking: true, blocked_by: true, id: to_string(other_user.id)} + %{following: false, blocking: true, blocked_by: false, id: to_string(other_user.id)} + ) + + test_relationship_rendering(user, other_user, expected) + end + + test "blocks are not visible to the blocked user" do + user = insert(:user) + other_user = insert(:user) + + {:ok, _user_relationship} = User.block(other_user, user) + + expected = + Map.merge( + @blank_response, + %{following: false, blocking: false, blocked_by: false, id: to_string(other_user.id)} ) test_relationship_rendering(user, other_user, expected)