From ea60c4e7097c69df2023f23f60451f69668394f8 Mon Sep 17 00:00:00 2001 From: Tusooa Zhu Date: Wed, 14 Sep 2022 20:24:04 -0400 Subject: [PATCH] Fix wrong relationship direction --- .../controllers/account_controller.ex | 2 +- .../controllers/account_controller_test.exs | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex index 50dd0e4c2..2b736e5a3 100644 --- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex @@ -481,7 +481,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do def remove_from_followers(%{assigns: %{user: followed, account: follower}} = conn, _params) do with {:ok, follower} <- CommonAPI.reject_follow_request(follower, followed) do - render(conn, "relationship.json", user: follower, target: followed) + render(conn, "relationship.json", user: followed, target: follower) else nil -> render_error(conn, :not_found, "Record not found") diff --git a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs index 8311ebff9..b4e2a3081 100644 --- a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs @@ -1985,7 +1985,22 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do CommonAPI.follow(other_user, user) - assert %{"id" => other_user_id, "followed_by" => false} = + assert %{"id" => ^other_user_id, "followed_by" => false} = + conn + |> post("/api/v1/accounts/#{other_user_id}/remove_from_followers") + |> json_response_and_validate_schema(200) + + refute User.following?(other_user, user) + end + + test "removing remote user from followers", %{conn: conn, user: user} do + %{id: other_user_id} = other_user = insert(:user, local: false) + + CommonAPI.follow(other_user, user) + + assert User.following?(other_user, user) + + assert %{"id" => ^other_user_id, "followed_by" => false} = conn |> post("/api/v1/accounts/#{other_user_id}/remove_from_followers") |> json_response_and_validate_schema(200)