Pleroma.Web.AdminAPI.UserController: fix dialyzer errors with replace_params: false
This commit is contained in:
parent
dd916e0b4c
commit
f400224a00
|
@ -18,7 +18,7 @@ defmodule Pleroma.Web.AdminAPI.UserController do
|
||||||
|
|
||||||
@users_page_size 50
|
@users_page_size 50
|
||||||
|
|
||||||
plug(Pleroma.Web.ApiSpec.CastAndValidate)
|
plug(Pleroma.Web.ApiSpec.CastAndValidate, replace_params: false)
|
||||||
|
|
||||||
plug(
|
plug(
|
||||||
OAuthScopesPlug,
|
OAuthScopesPlug,
|
||||||
|
@ -51,13 +51,22 @@ defmodule Pleroma.Web.AdminAPI.UserController do
|
||||||
|
|
||||||
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.Admin.UserOperation
|
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.Admin.UserOperation
|
||||||
|
|
||||||
def delete(conn, %{nickname: nickname}) do
|
def delete(%{private: %{open_api_spex: %{params: %{nickname: nickname}}}} = conn, _) do
|
||||||
conn
|
conn
|
||||||
|> Map.put(:body_params, %{nicknames: [nickname]})
|
|> do_deletes([nickname])
|
||||||
|> delete(%{})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete(%{assigns: %{user: admin}, body_params: %{nicknames: nicknames}} = conn, _) do
|
def delete(
|
||||||
|
%{
|
||||||
|
private: %{open_api_spex: %{body_params: %{nicknames: nicknames}}}
|
||||||
|
} = conn,
|
||||||
|
_
|
||||||
|
) do
|
||||||
|
conn
|
||||||
|
|> do_deletes(nicknames)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp do_deletes(%{assigns: %{user: admin}} = conn, nicknames) when is_list(nicknames) do
|
||||||
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
|
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
|
||||||
|
|
||||||
Enum.each(users, fn user ->
|
Enum.each(users, fn user ->
|
||||||
|
@ -77,10 +86,14 @@ def delete(%{assigns: %{user: admin}, body_params: %{nicknames: nicknames}} = co
|
||||||
def follow(
|
def follow(
|
||||||
%{
|
%{
|
||||||
assigns: %{user: admin},
|
assigns: %{user: admin},
|
||||||
|
private: %{
|
||||||
|
open_api_spex: %{
|
||||||
body_params: %{
|
body_params: %{
|
||||||
follower: follower_nick,
|
follower: follower_nick,
|
||||||
followed: followed_nick
|
followed: followed_nick
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} = conn,
|
} = conn,
|
||||||
_
|
_
|
||||||
) do
|
) do
|
||||||
|
@ -102,10 +115,14 @@ def follow(
|
||||||
def unfollow(
|
def unfollow(
|
||||||
%{
|
%{
|
||||||
assigns: %{user: admin},
|
assigns: %{user: admin},
|
||||||
|
private: %{
|
||||||
|
open_api_spex: %{
|
||||||
body_params: %{
|
body_params: %{
|
||||||
follower: follower_nick,
|
follower: follower_nick,
|
||||||
followed: followed_nick
|
followed: followed_nick
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} = conn,
|
} = conn,
|
||||||
_
|
_
|
||||||
) do
|
) do
|
||||||
|
@ -124,7 +141,13 @@ def unfollow(
|
||||||
json(conn, "ok")
|
json(conn, "ok")
|
||||||
end
|
end
|
||||||
|
|
||||||
def create(%{assigns: %{user: admin}, body_params: %{users: users}} = conn, _) do
|
def create(
|
||||||
|
%{
|
||||||
|
assigns: %{user: admin},
|
||||||
|
private: %{open_api_spex: %{body_params: %{users: users}}}
|
||||||
|
} = conn,
|
||||||
|
_
|
||||||
|
) do
|
||||||
changesets =
|
changesets =
|
||||||
users
|
users
|
||||||
|> Enum.map(fn %{nickname: nickname, email: email, password: password} ->
|
|> Enum.map(fn %{nickname: nickname, email: email, password: password} ->
|
||||||
|
@ -178,7 +201,13 @@ def create(%{assigns: %{user: admin}, body_params: %{users: users}} = conn, _) d
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def show(%{assigns: %{user: admin}} = conn, %{nickname: nickname}) do
|
def show(
|
||||||
|
%{
|
||||||
|
assigns: %{user: admin},
|
||||||
|
private: %{open_api_spex: %{params: %{nickname: nickname}}}
|
||||||
|
} = conn,
|
||||||
|
_
|
||||||
|
) do
|
||||||
with %User{} = user <- User.get_cached_by_nickname_or_id(nickname, for: admin) do
|
with %User{} = user <- User.get_cached_by_nickname_or_id(nickname, for: admin) do
|
||||||
render(conn, "show.json", %{user: user})
|
render(conn, "show.json", %{user: user})
|
||||||
else
|
else
|
||||||
|
@ -186,7 +215,11 @@ def show(%{assigns: %{user: admin}} = conn, %{nickname: nickname}) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def toggle_activation(%{assigns: %{user: admin}} = conn, %{nickname: nickname}) do
|
def toggle_activation(
|
||||||
|
%{assigns: %{user: admin}, private: %{open_api_spex: %{params: %{nickname: nickname}}}} =
|
||||||
|
conn,
|
||||||
|
_
|
||||||
|
) do
|
||||||
user = User.get_cached_by_nickname(nickname)
|
user = User.get_cached_by_nickname(nickname)
|
||||||
|
|
||||||
{:ok, updated_user} = User.set_activation(user, !user.is_active)
|
{:ok, updated_user} = User.set_activation(user, !user.is_active)
|
||||||
|
@ -202,7 +235,13 @@ def toggle_activation(%{assigns: %{user: admin}} = conn, %{nickname: nickname})
|
||||||
render(conn, "show.json", user: updated_user)
|
render(conn, "show.json", user: updated_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def activate(%{assigns: %{user: admin}, body_params: %{nicknames: nicknames}} = conn, _) do
|
def activate(
|
||||||
|
%{
|
||||||
|
assigns: %{user: admin},
|
||||||
|
private: %{open_api_spex: %{body_params: %{nicknames: nicknames}}}
|
||||||
|
} = conn,
|
||||||
|
_
|
||||||
|
) do
|
||||||
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
|
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
|
||||||
{:ok, updated_users} = User.set_activation(users, true)
|
{:ok, updated_users} = User.set_activation(users, true)
|
||||||
|
|
||||||
|
@ -215,7 +254,13 @@ def activate(%{assigns: %{user: admin}, body_params: %{nicknames: nicknames}} =
|
||||||
render(conn, "index.json", users: updated_users)
|
render(conn, "index.json", users: updated_users)
|
||||||
end
|
end
|
||||||
|
|
||||||
def deactivate(%{assigns: %{user: admin}, body_params: %{nicknames: nicknames}} = conn, _) do
|
def deactivate(
|
||||||
|
%{
|
||||||
|
assigns: %{user: admin},
|
||||||
|
private: %{open_api_spex: %{body_params: %{nicknames: nicknames}}}
|
||||||
|
} = conn,
|
||||||
|
_
|
||||||
|
) do
|
||||||
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
|
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
|
||||||
{:ok, updated_users} = User.set_activation(users, false)
|
{:ok, updated_users} = User.set_activation(users, false)
|
||||||
|
|
||||||
|
@ -228,7 +273,13 @@ def deactivate(%{assigns: %{user: admin}, body_params: %{nicknames: nicknames}}
|
||||||
render(conn, "index.json", users: updated_users)
|
render(conn, "index.json", users: updated_users)
|
||||||
end
|
end
|
||||||
|
|
||||||
def approve(%{assigns: %{user: admin}, body_params: %{nicknames: nicknames}} = conn, _) do
|
def approve(
|
||||||
|
%{
|
||||||
|
assigns: %{user: admin},
|
||||||
|
private: %{open_api_spex: %{body_params: %{nicknames: nicknames}}}
|
||||||
|
} = conn,
|
||||||
|
_
|
||||||
|
) do
|
||||||
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
|
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
|
||||||
{:ok, updated_users} = User.approve(users)
|
{:ok, updated_users} = User.approve(users)
|
||||||
|
|
||||||
|
@ -241,7 +292,13 @@ def approve(%{assigns: %{user: admin}, body_params: %{nicknames: nicknames}} = c
|
||||||
render(conn, "index.json", users: updated_users)
|
render(conn, "index.json", users: updated_users)
|
||||||
end
|
end
|
||||||
|
|
||||||
def suggest(%{assigns: %{user: admin}, body_params: %{nicknames: nicknames}} = conn, _) do
|
def suggest(
|
||||||
|
%{
|
||||||
|
assigns: %{user: admin},
|
||||||
|
private: %{open_api_spex: %{body_params: %{nicknames: nicknames}}}
|
||||||
|
} = conn,
|
||||||
|
_
|
||||||
|
) do
|
||||||
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
|
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
|
||||||
{:ok, updated_users} = User.set_suggestion(users, true)
|
{:ok, updated_users} = User.set_suggestion(users, true)
|
||||||
|
|
||||||
|
@ -254,7 +311,13 @@ def suggest(%{assigns: %{user: admin}, body_params: %{nicknames: nicknames}} = c
|
||||||
render(conn, "index.json", users: updated_users)
|
render(conn, "index.json", users: updated_users)
|
||||||
end
|
end
|
||||||
|
|
||||||
def unsuggest(%{assigns: %{user: admin}, body_params: %{nicknames: nicknames}} = conn, _) do
|
def unsuggest(
|
||||||
|
%{
|
||||||
|
assigns: %{user: admin},
|
||||||
|
private: %{open_api_spex: %{body_params: %{nicknames: nicknames}}}
|
||||||
|
} = conn,
|
||||||
|
_
|
||||||
|
) do
|
||||||
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
|
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
|
||||||
{:ok, updated_users} = User.set_suggestion(users, false)
|
{:ok, updated_users} = User.set_suggestion(users, false)
|
||||||
|
|
||||||
|
@ -267,7 +330,7 @@ def unsuggest(%{assigns: %{user: admin}, body_params: %{nicknames: nicknames}} =
|
||||||
render(conn, "index.json", users: updated_users)
|
render(conn, "index.json", users: updated_users)
|
||||||
end
|
end
|
||||||
|
|
||||||
def index(conn, params) do
|
def index(%{private: %{open_api_spex: %{params: params}}} = conn, _) do
|
||||||
{page, page_size} = page_params(params)
|
{page, page_size} = page_params(params)
|
||||||
filters = maybe_parse_filters(params[:filters])
|
filters = maybe_parse_filters(params[:filters])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue