From bdfd72630f48bb891af34f1849e87cc5bbd3ff51 Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Mon, 18 Jan 2021 16:28:36 +0100 Subject: [PATCH 1/2] ListController: Fix being unable to add / remove users. --- lib/pleroma/list.ex | 8 ++++++-- .../controllers/list_controller_test.exs | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/list.ex b/lib/pleroma/list.ex index ff975e7a6..fe5721c34 100644 --- a/lib/pleroma/list.ex +++ b/lib/pleroma/list.ex @@ -113,11 +113,15 @@ defmodule Pleroma.List do end end - def follow(%Pleroma.List{following: following} = list, %User{} = followed) do + def follow(%Pleroma.List{id: id}, %User{} = followed) do + list = Repo.get(Pleroma.List, id) + %{following: following} = list update_follows(list, %{following: Enum.uniq([followed.follower_address | following])}) end - def unfollow(%Pleroma.List{following: following} = list, %User{} = unfollowed) do + def unfollow(%Pleroma.List{id: id}, %User{} = unfollowed) do + list = Repo.get(Pleroma.List, id) + %{following: following} = list update_follows(list, %{following: List.delete(following, unfollowed.follower_address)}) end diff --git a/test/pleroma/web/mastodon_api/controllers/list_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/list_controller_test.exs index cc5e1e66d..28099837e 100644 --- a/test/pleroma/web/mastodon_api/controllers/list_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/list_controller_test.exs @@ -55,30 +55,39 @@ defmodule Pleroma.Web.MastodonAPI.ListControllerTest do test "adding users to a list" do %{user: user, conn: conn} = oauth_access(["write:lists"]) other_user = insert(:user) + third_user = insert(:user) {:ok, list} = Pleroma.List.create("name", user) assert %{} == conn |> put_req_header("content-type", "application/json") - |> post("/api/v1/lists/#{list.id}/accounts", %{"account_ids" => [other_user.id]}) + |> post("/api/v1/lists/#{list.id}/accounts", %{ + "account_ids" => [other_user.id, third_user.id] + }) |> json_response_and_validate_schema(:ok) %Pleroma.List{following: following} = Pleroma.List.get(list.id, user) - assert following == [other_user.follower_address] + assert length(following) == 2 + assert other_user.follower_address in following + assert third_user.follower_address in following end test "removing users from a list, body params" do %{user: user, conn: conn} = oauth_access(["write:lists"]) other_user = insert(:user) third_user = insert(:user) + fourth_user = insert(:user) {:ok, list} = Pleroma.List.create("name", user) {:ok, list} = Pleroma.List.follow(list, other_user) {:ok, list} = Pleroma.List.follow(list, third_user) + {:ok, list} = Pleroma.List.follow(list, fourth_user) assert %{} == conn |> put_req_header("content-type", "application/json") - |> delete("/api/v1/lists/#{list.id}/accounts", %{"account_ids" => [other_user.id]}) + |> delete("/api/v1/lists/#{list.id}/accounts", %{ + "account_ids" => [other_user.id, fourth_user.id] + }) |> json_response_and_validate_schema(:ok) %Pleroma.List{following: following} = Pleroma.List.get(list.id, user) From 71166b30a42ad3a8988049992bcab93c7e2ed656 Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Mon, 18 Jan 2021 16:29:29 +0100 Subject: [PATCH 2/2] Changelog: Add list fix. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b8e8d2f4..a14e03b68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). API Changes - Mastodon API: Current user is now included in conversation if it's the only participant. - Mastodon API: Fixed last_status.account being not filled with account data. + - Mastodon API: Fix not being able to add or remove multiple users at once in lists. ## Unreleased (Patch)