Pleroma.Web.MastodonAPI.ListController: fix dialyzer errors with replace_params: false

This commit is contained in:
Mark Felder 2024-01-30 18:05:12 -05:00
parent 14de8376ad
commit 9741f045e4
1 changed files with 39 additions and 13 deletions

View File

@ -11,7 +11,7 @@ defmodule Pleroma.Web.MastodonAPI.ListController do
@oauth_read_actions [:index, :show, :list_accounts] @oauth_read_actions [:index, :show, :list_accounts]
plug(Pleroma.Web.ApiSpec.CastAndValidate) plug(Pleroma.Web.ApiSpec.CastAndValidate, replace_params: false)
plug(:list_by_id_and_user when action not in [:index, :create]) plug(:list_by_id_and_user when action not in [:index, :create])
plug(OAuthScopesPlug, %{scopes: ["read:lists"]} when action in @oauth_read_actions) plug(OAuthScopesPlug, %{scopes: ["read:lists"]} when action in @oauth_read_actions)
plug(OAuthScopesPlug, %{scopes: ["write:lists"]} when action not in @oauth_read_actions) plug(OAuthScopesPlug, %{scopes: ["write:lists"]} when action not in @oauth_read_actions)
@ -21,25 +21,33 @@ defmodule Pleroma.Web.MastodonAPI.ListController do
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.ListOperation defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.ListOperation
# GET /api/v1/lists # GET /api/v1/lists
def index(%{assigns: %{user: user}} = conn, opts) do def index(%{assigns: %{user: user}, private: %{open_api_spex: %{params: params}}} = conn, _) do
lists = Pleroma.List.for_user(user, opts) lists = Pleroma.List.for_user(user, params)
render(conn, "index.json", lists: lists) render(conn, "index.json", lists: lists)
end end
# POST /api/v1/lists # POST /api/v1/lists
def create(%{assigns: %{user: user}, body_params: %{title: title}} = conn, _) do def create(
%{assigns: %{user: user}, private: %{open_api_spex: %{body_params: %{title: title}}}} =
conn,
_
) do
with {:ok, %Pleroma.List{} = list} <- Pleroma.List.create(title, user) do with {:ok, %Pleroma.List{} = list} <- Pleroma.List.create(title, user) do
render(conn, "show.json", list: list) render(conn, "show.json", list: list)
end end
end end
# GET /api/v1/lists/:id # GET /api/v1/lists/:idOB
def show(%{assigns: %{list: list}} = conn, _) do def show(%{assigns: %{list: list}} = conn, _) do
render(conn, "show.json", list: list) render(conn, "show.json", list: list)
end end
# PUT /api/v1/lists/:id # PUT /api/v1/lists/:id
def update(%{assigns: %{list: list}, body_params: %{title: title}} = conn, _) do def update(
%{assigns: %{list: list}, private: %{open_api_spex: %{body_params: %{title: title}}}} =
conn,
_
) do
with {:ok, list} <- Pleroma.List.rename(list, title) do with {:ok, list} <- Pleroma.List.rename(list, title) do
render(conn, "show.json", list: list) render(conn, "show.json", list: list)
end end
@ -62,7 +70,13 @@ def list_accounts(%{assigns: %{user: user, list: list}} = conn, _) do
end end
# POST /api/v1/lists/:id/accounts # POST /api/v1/lists/:id/accounts
def add_to_list(%{assigns: %{list: list}, body_params: %{account_ids: account_ids}} = conn, _) do def add_to_list(
%{
assigns: %{list: list},
private: %{open_api_spex: %{body_params: %{account_ids: account_ids}}}
} = conn,
_
) do
Enum.each(account_ids, fn account_id -> Enum.each(account_ids, fn account_id ->
with %User{} = followed <- User.get_cached_by_id(account_id) do with %User{} = followed <- User.get_cached_by_id(account_id) do
Pleroma.List.follow(list, followed) Pleroma.List.follow(list, followed)
@ -74,9 +88,22 @@ def add_to_list(%{assigns: %{list: list}, body_params: %{account_ids: account_id
# DELETE /api/v1/lists/:id/accounts # DELETE /api/v1/lists/:id/accounts
def remove_from_list( def remove_from_list(
%{assigns: %{list: list}, params: %{account_ids: account_ids}} = conn, %{
private: %{open_api_spex: %{params: %{account_ids: account_ids}}}
} = conn,
_ _
) do ) do
do_remove_from_list(conn, account_ids)
end
def remove_from_list(
%{private: %{open_api_spex: %{body_params: %{account_ids: account_ids}}}} = conn,
_
) do
do_remove_from_list(conn, account_ids)
end
defp do_remove_from_list(%{assigns: %{list: list}} = conn, account_ids) do
Enum.each(account_ids, fn account_id -> Enum.each(account_ids, fn account_id ->
with %User{} = followed <- User.get_cached_by_id(account_id) do with %User{} = followed <- User.get_cached_by_id(account_id) do
Pleroma.List.unfollow(list, followed) Pleroma.List.unfollow(list, followed)
@ -86,11 +113,10 @@ def remove_from_list(
json(conn, %{}) json(conn, %{})
end end
def remove_from_list(%{body_params: params} = conn, _) do defp list_by_id_and_user(
remove_from_list(%{conn | params: params}, %{}) %{assigns: %{user: user}, private: %{open_api_spex: %{params: %{id: id}}}} = conn,
end _
) 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)
nil -> conn |> render_error(:not_found, "List not found") |> halt() nil -> conn |> render_error(:not_found, "List not found") |> halt()