Enum.uniq_by(fts_results ++ trigram_results, & &1.id)
end
- def all_except_one(user) do
- query = from(u in User, where: u.id != ^user.id)
+ def all_except_one(user, page, page_size) do
+ from(
+ u in User,
+ where: u.id != ^user.id,
+ limit: ^page_size,
+ offset: ^((page - 1) * page_size),
+ order_by: u.id
+ )
+ |> Repo.all()
+ end
- Repo.all(query)
+ def count_all_except_one(user) do
+ query =
+ from(
+ u in User,
+ where: u.id != ^user.id
+ )
+
+ Repo.aggregate(query, :count, :id)
end
defp do_search(subquery, for_user, options \\ []) do
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.AdminAPIController do
+ @users_page_size 50
+
use Pleroma.Web, :controller
alias Pleroma.User
alias Pleroma.Web.ActivityPub.Relay
do: json_response(conn, :no_content, "")
end
- def list_users(%{assigns: %{user: admin}} = conn, _data) do
- users = User.all_except_one(admin)
-
- conn
- |> json(UserView.render("index_for_admin.json", %{users: users}))
+ def list_users(%{assigns: %{user: admin}} = conn, %{"page" => page_string}) do
+ with {page, _} <- Integer.parse(page_string),
+ users <- User.all_except_one(admin, page, @users_page_size),
+ count <- User.count_all_except_one(admin),
+ do:
+ conn
+ |> json(
+ UserView.render("index_for_admin.json", %{
+ users: users,
+ count: count,
+ page_size: @users_page_size
+ })
+ )
end
def right_add(conn, %{"permission_group" => permission_group, "nickname" => nickname})
else: %{}
end
- def render("index_for_admin.json", %{users: users} = opts) do
- users
- |> render_many(UserView, "show_for_admin.json", opts)
+ def render("index_for_admin.json", %{users: users, count: count, page_size: page_size} = opts) do
+ %{
+ users: render_many(users, UserView, "show_for_admin.json", opts),
+ count: count,
+ page_size: page_size
+ }
end
def render("show_for_admin.json", %{user: user}) do
conn =
build_conn()
|> assign(:user, admin)
- |> get("/api/pleroma/admin/users")
-
- assert json_response(conn, 200) == [
- %{
- "deactivated" => user.info.deactivated,
- "id" => user.id,
- "nickname" => user.nickname
- }
- ]
+ |> get("/api/pleroma/admin/users?page=1")
+
+ assert json_response(conn, 200) == %{
+ "count" => 1,
+ "page_size" => 50,
+ "users" => [
+ %{
+ "deactivated" => user.info.deactivated,
+ "id" => user.id,
+ "nickname" => user.nickname
+ }
+ ]
+ }
end
test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation" do