Fix removing an account from a list
Mastodon (Frontend) changed a different method for deletes, keeping old format as mastodon documentation is too loose
This commit is contained in:
parent
d48755791d
commit
d872858046
3 changed files with 46 additions and 7 deletions
|
@ -114,7 +114,7 @@ def add_to_list_operation do
|
||||||
description: "Add accounts to the given list.",
|
description: "Add accounts to the given list.",
|
||||||
operationId: "ListController.add_to_list",
|
operationId: "ListController.add_to_list",
|
||||||
parameters: [id_param()],
|
parameters: [id_param()],
|
||||||
requestBody: add_remove_accounts_request(),
|
requestBody: add_remove_accounts_request(true),
|
||||||
security: [%{"oAuth" => ["write:lists"]}],
|
security: [%{"oAuth" => ["write:lists"]}],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Empty object", "application/json", %Schema{type: :object})
|
200 => Operation.response("Empty object", "application/json", %Schema{type: :object})
|
||||||
|
@ -127,8 +127,16 @@ def remove_from_list_operation do
|
||||||
tags: ["Lists"],
|
tags: ["Lists"],
|
||||||
summary: "Remove accounts from list",
|
summary: "Remove accounts from list",
|
||||||
operationId: "ListController.remove_from_list",
|
operationId: "ListController.remove_from_list",
|
||||||
parameters: [id_param()],
|
parameters: [
|
||||||
requestBody: add_remove_accounts_request(),
|
id_param(),
|
||||||
|
Operation.parameter(
|
||||||
|
:account_ids,
|
||||||
|
:query,
|
||||||
|
%Schema{type: :array, items: %Schema{type: :string}},
|
||||||
|
"Array of account IDs"
|
||||||
|
)
|
||||||
|
],
|
||||||
|
requestBody: add_remove_accounts_request(false),
|
||||||
security: [%{"oAuth" => ["write:lists"]}],
|
security: [%{"oAuth" => ["write:lists"]}],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Empty object", "application/json", %Schema{type: :object})
|
200 => Operation.response("Empty object", "application/json", %Schema{type: :object})
|
||||||
|
@ -171,7 +179,7 @@ defp create_update_request do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp add_remove_accounts_request do
|
defp add_remove_accounts_request(required) when is_boolean(required) do
|
||||||
request_body(
|
request_body(
|
||||||
"Parameters",
|
"Parameters",
|
||||||
%Schema{
|
%Schema{
|
||||||
|
@ -180,9 +188,9 @@ defp add_remove_accounts_request do
|
||||||
properties: %{
|
properties: %{
|
||||||
account_ids: %Schema{type: :array, description: "Array of account IDs", items: FlakeID}
|
account_ids: %Schema{type: :array, description: "Array of account IDs", items: FlakeID}
|
||||||
},
|
},
|
||||||
required: [:account_ids]
|
required: required && [:account_ids]
|
||||||
},
|
},
|
||||||
required: true
|
required: required
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -86,6 +86,19 @@ def remove_from_list(
|
||||||
json(conn, %{})
|
json(conn, %{})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def remove_from_list(
|
||||||
|
%{assigns: %{list: list}, params: %{account_ids: account_ids}} = conn,
|
||||||
|
_
|
||||||
|
) do
|
||||||
|
Enum.each(account_ids, fn account_id ->
|
||||||
|
with %User{} = followed <- User.get_cached_by_id(account_id) do
|
||||||
|
Pleroma.List.unfollow(list, followed)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
json(conn, %{})
|
||||||
|
end
|
||||||
|
|
||||||
defp list_by_id_and_user(%{assigns: %{user: user}, params: %{id: id}} = conn, _) do
|
defp list_by_id_and_user(%{assigns: %{user: user}, params: %{id: id}} = conn, _) do
|
||||||
case Pleroma.List.get(id, user) do
|
case Pleroma.List.get(id, user) do
|
||||||
%Pleroma.List{} = list -> assign(conn, :list, list)
|
%Pleroma.List{} = list -> assign(conn, :list, list)
|
||||||
|
|
|
@ -67,7 +67,7 @@ test "adding users to a list" do
|
||||||
assert following == [other_user.follower_address]
|
assert following == [other_user.follower_address]
|
||||||
end
|
end
|
||||||
|
|
||||||
test "removing users from a list" do
|
test "removing users from a list, body params" do
|
||||||
%{user: user, conn: conn} = oauth_access(["write:lists"])
|
%{user: user, conn: conn} = oauth_access(["write:lists"])
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
third_user = insert(:user)
|
third_user = insert(:user)
|
||||||
|
@ -85,6 +85,24 @@ test "removing users from a list" do
|
||||||
assert following == [third_user.follower_address]
|
assert following == [third_user.follower_address]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "removing users from a list, query params" do
|
||||||
|
%{user: user, conn: conn} = oauth_access(["write:lists"])
|
||||||
|
other_user = insert(:user)
|
||||||
|
third_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)
|
||||||
|
|
||||||
|
assert %{} ==
|
||||||
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> delete("/api/v1/lists/#{list.id}/accounts?account_ids[]=#{other_user.id}")
|
||||||
|
|> json_response_and_validate_schema(:ok)
|
||||||
|
|
||||||
|
%Pleroma.List{following: following} = Pleroma.List.get(list.id, user)
|
||||||
|
assert following == [third_user.follower_address]
|
||||||
|
end
|
||||||
|
|
||||||
test "listing users in a list" do
|
test "listing users in a list" do
|
||||||
%{user: user, conn: conn} = oauth_access(["read:lists"])
|
%{user: user, conn: conn} = oauth_access(["read:lists"])
|
||||||
other_user = insert(:user)
|
other_user = insert(:user)
|
||||||
|
|
Loading…
Reference in a new issue