AdminAPI: Filter users by `need_approval`
This commit is contained in:
parent
b750129da1
commit
33f1b29b2c
|
@ -19,6 +19,7 @@ Configuration options:
|
||||||
- `local`: only local users
|
- `local`: only local users
|
||||||
- `external`: only external users
|
- `external`: only external users
|
||||||
- `active`: only active users
|
- `active`: only active users
|
||||||
|
- `need_approval`: only unapproved users
|
||||||
- `deactivated`: only deactivated users
|
- `deactivated`: only deactivated users
|
||||||
- `is_admin`: users with admin role
|
- `is_admin`: users with admin role
|
||||||
- `is_moderator`: users with moderator role
|
- `is_moderator`: users with moderator role
|
||||||
|
|
|
@ -42,6 +42,7 @@ defmodule Pleroma.User.Query do
|
||||||
external: boolean(),
|
external: boolean(),
|
||||||
active: boolean(),
|
active: boolean(),
|
||||||
deactivated: boolean(),
|
deactivated: boolean(),
|
||||||
|
need_approval: boolean(),
|
||||||
is_admin: boolean(),
|
is_admin: boolean(),
|
||||||
is_moderator: boolean(),
|
is_moderator: boolean(),
|
||||||
super_users: boolean(),
|
super_users: boolean(),
|
||||||
|
@ -146,6 +147,10 @@ defp compose_query({:deactivated, true}, query) do
|
||||||
|> where([u], not is_nil(u.nickname))
|
|> where([u], not is_nil(u.nickname))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp compose_query({:need_approval, _}, query) do
|
||||||
|
where(query, [u], u.approval_pending)
|
||||||
|
end
|
||||||
|
|
||||||
defp compose_query({:followers, %User{id: id}}, query) do
|
defp compose_query({:followers, %User{id: id}}, query) do
|
||||||
query
|
query
|
||||||
|> where([u], u.id != ^id)
|
|> where([u], u.id != ^id)
|
||||||
|
|
|
@ -350,7 +350,7 @@ def list_users(conn, params) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@filters ~w(local external active deactivated is_admin is_moderator)
|
@filters ~w(local external active deactivated need_approval is_admin is_moderator)
|
||||||
|
|
||||||
@spec maybe_parse_filters(String.t()) :: %{required(String.t()) => true} | %{}
|
@spec maybe_parse_filters(String.t()) :: %{required(String.t()) => true} | %{}
|
||||||
defp maybe_parse_filters(filters) when is_nil(filters) or filters == "", do: %{}
|
defp maybe_parse_filters(filters) when is_nil(filters) or filters == "", do: %{}
|
||||||
|
|
|
@ -991,6 +991,44 @@ test "only local users with no query", %{conn: conn, admin: old_admin} do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "only unapproved users", %{conn: conn} do
|
||||||
|
user =
|
||||||
|
insert(:user,
|
||||||
|
nickname: "sadboy",
|
||||||
|
approval_pending: true,
|
||||||
|
registration_reason: "Plz let me in!"
|
||||||
|
)
|
||||||
|
|
||||||
|
insert(:user, nickname: "happyboy", approval_pending: false)
|
||||||
|
|
||||||
|
conn = get(conn, "/api/pleroma/admin/users?filters=need_approval")
|
||||||
|
|
||||||
|
users =
|
||||||
|
[
|
||||||
|
%{
|
||||||
|
"deactivated" => user.deactivated,
|
||||||
|
"id" => user.id,
|
||||||
|
"nickname" => user.nickname,
|
||||||
|
"roles" => %{"admin" => false, "moderator" => false},
|
||||||
|
"local" => true,
|
||||||
|
"tags" => [],
|
||||||
|
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
||||||
|
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
||||||
|
"confirmation_pending" => false,
|
||||||
|
"approval_pending" => true,
|
||||||
|
"url" => user.ap_id,
|
||||||
|
"registration_reason" => "Plz let me in!"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|> Enum.sort_by(& &1["nickname"])
|
||||||
|
|
||||||
|
assert json_response(conn, 200) == %{
|
||||||
|
"count" => 1,
|
||||||
|
"page_size" => 50,
|
||||||
|
"users" => users
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
test "load only admins", %{conn: conn, admin: admin} do
|
test "load only admins", %{conn: conn, admin: admin} do
|
||||||
second_admin = insert(:user, is_admin: true)
|
second_admin = insert(:user, is_admin: true)
|
||||||
insert(:user)
|
insert(:user)
|
||||||
|
|
|
@ -166,5 +166,16 @@ test "it returns user by email" do
|
||||||
assert total == 3
|
assert total == 3
|
||||||
assert count == 1
|
assert count == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it returns unapproved user" do
|
||||||
|
unapproved = insert(:user, approval_pending: true)
|
||||||
|
insert(:user)
|
||||||
|
insert(:user)
|
||||||
|
|
||||||
|
{:ok, _results, total} = Search.user()
|
||||||
|
{:ok, [^unapproved], count} = Search.user(%{need_approval: true})
|
||||||
|
assert total == 3
|
||||||
|
assert count == 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue