Merge branch 'admin-active-filter' into 'develop'

Admin API: Filter out unapproved users when the `active` filter is on

Closes #2037

See merge request pleroma/pleroma!2872
This commit is contained in:
feld 2020-08-10 17:16:38 +00:00
commit 78484fe0ef
2 changed files with 22 additions and 0 deletions

View File

@ -130,6 +130,7 @@ defp compose_query({:external, _}, query), do: location_query(query, false)
defp compose_query({:active, _}, query) do
User.restrict_deactivated(query)
|> where([u], not is_nil(u.nickname))
|> where([u], u.approval_pending == false)
end
defp compose_query({:legacy_active, _}, query) do

View File

@ -1164,6 +1164,27 @@ test "load users with tags list", %{conn: conn} do
}
end
test "`active` filters out users pending approval", %{token: token} do
insert(:user, approval_pending: true)
%{id: user_id} = insert(:user, approval_pending: false)
%{id: admin_id} = token.user
conn =
build_conn()
|> assign(:user, token.user)
|> assign(:token, token)
|> get("/api/pleroma/admin/users?filters=active")
assert %{
"count" => 2,
"page_size" => 50,
"users" => [
%{"id" => ^admin_id},
%{"id" => ^user_id}
]
} = json_response(conn, 200)
end
test "it works with multiple filters" do
admin = insert(:user, nickname: "john", is_admin: true)
token = insert(:oauth_admin_token, user: admin)