mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2025-04-12 14:04:08 +00:00
/api/v2/admin/accounts (needs a test)
Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
parent
f0d98c8cb7
commit
6ada4b6cba
3 changed files with 155 additions and 17 deletions
|
@ -19,7 +19,7 @@ defmodule Pleroma.Web.ApiSpec.MastodonAdmin.AccountOperation do
|
|||
def index_operation do
|
||||
%Operation{
|
||||
tags: ["User administration (Mastodon API)"],
|
||||
summary: "View accounts by criteria",
|
||||
summary: "View accounts by criteria (v1)",
|
||||
operationId: "MastodonAdmin.AccountController.index",
|
||||
description: "View accounts matching certain criteria for filtering, up to 40 at a time.",
|
||||
security: [%{"oAuth" => ["admin:read:accounts"]}],
|
||||
|
@ -27,12 +27,6 @@ defmodule Pleroma.Web.ApiSpec.MastodonAdmin.AccountOperation do
|
|||
[
|
||||
Operation.parameter(:local, :query, :boolean, "Filter for local accounts?"),
|
||||
Operation.parameter(:remote, :query, :boolean, "Filter for remote accounts?"),
|
||||
Operation.parameter(
|
||||
:by_domain,
|
||||
:query,
|
||||
:string,
|
||||
"Filter by the given domain (not implemented yet)"
|
||||
),
|
||||
Operation.parameter(
|
||||
:active,
|
||||
:query,
|
||||
|
@ -51,12 +45,6 @@ defmodule Pleroma.Web.ApiSpec.MastodonAdmin.AccountOperation do
|
|||
:boolean,
|
||||
"Filter for currently disabled accounts?"
|
||||
),
|
||||
Operation.parameter(
|
||||
:sensitized,
|
||||
:query,
|
||||
:boolean,
|
||||
"Filter for currently sensitized accounts? (not implemented yet)"
|
||||
),
|
||||
Operation.parameter(
|
||||
:silenced,
|
||||
:query,
|
||||
|
@ -69,14 +57,31 @@ defmodule Pleroma.Web.ApiSpec.MastodonAdmin.AccountOperation do
|
|||
:boolean,
|
||||
"Filter for currently suspended accounts? (not implemented yet)"
|
||||
),
|
||||
Operation.parameter(:username, :query, :string, "Username to search for"),
|
||||
Operation.parameter(:display_name, :query, :string, "Display name to search for"),
|
||||
Operation.parameter(
|
||||
:sensitized,
|
||||
:query,
|
||||
:boolean,
|
||||
"Filter for accounts force-marked as sensitive? (not implemented yet)"
|
||||
),
|
||||
Operation.parameter(:username, :query, :string, "Search for the given username"),
|
||||
Operation.parameter(
|
||||
:display_name,
|
||||
:query,
|
||||
:string,
|
||||
"Search for the given display name"
|
||||
),
|
||||
Operation.parameter(
|
||||
:by_domain,
|
||||
:query,
|
||||
:string,
|
||||
"Filter by the given domain (not implemented yet)"
|
||||
),
|
||||
Operation.parameter(:email, :query, :string, "Lookup a user with this email"),
|
||||
Operation.parameter(
|
||||
:ip,
|
||||
:query,
|
||||
:string,
|
||||
"Lookup users by this IP address (not implemented yet)"
|
||||
"Lookup users with this IP address (not implemented yet)"
|
||||
),
|
||||
Operation.parameter(:staff, :query, :boolean, "Filter for staff accounts?")
|
||||
] ++
|
||||
|
@ -93,6 +98,87 @@ defmodule Pleroma.Web.ApiSpec.MastodonAdmin.AccountOperation do
|
|||
}
|
||||
end
|
||||
|
||||
def index2_operation do
|
||||
%Operation{
|
||||
tags: ["User administration (Mastodon API)"],
|
||||
summary: "View accounts by criteria (v2)",
|
||||
operationId: "MastodonAdmin.AccountController.index2",
|
||||
description: "View accounts matching certain criteria for filtering, up to 40 at a time.",
|
||||
security: [%{"oAuth" => ["admin:read:accounts"]}],
|
||||
parameters:
|
||||
[
|
||||
Operation.parameter(
|
||||
:origin,
|
||||
:query,
|
||||
%Schema{type: :string, enum: ["local", "remote"]},
|
||||
"Filter for local or remote accounts"
|
||||
),
|
||||
Operation.parameter(
|
||||
:status,
|
||||
:query,
|
||||
%Schema{
|
||||
type: :string,
|
||||
enum: ["active", "inactive", "pending", "disabled", "silenced", "suspended"]
|
||||
},
|
||||
"Filter for active, pending, disabled, silenced or suspended accounts"
|
||||
),
|
||||
Operation.parameter(
|
||||
:permissions,
|
||||
:query,
|
||||
:string,
|
||||
"Filter for accounts with staff permissions (users that can manage reports). (not implemented yet)"
|
||||
),
|
||||
Operation.parameter(
|
||||
:role_ids,
|
||||
:query,
|
||||
%Schema{
|
||||
oneOf: [
|
||||
%Schema{type: :array, items: %Schema{type: :string}},
|
||||
%Schema{type: :string}
|
||||
]
|
||||
},
|
||||
"Filter for users with these roles. (not implemented yet)"
|
||||
),
|
||||
Operation.parameter(
|
||||
:invited_by,
|
||||
:query,
|
||||
:string,
|
||||
"Lookup users invited by the account with this ID. (not implemented yet)"
|
||||
),
|
||||
Operation.parameter(:username, :query, :string, "Search for the given username"),
|
||||
Operation.parameter(
|
||||
:display_name,
|
||||
:query,
|
||||
:string,
|
||||
"Search for the given display name"
|
||||
),
|
||||
Operation.parameter(
|
||||
:by_domain,
|
||||
:query,
|
||||
:string,
|
||||
"Filter by the given domain (not implemented yet)"
|
||||
),
|
||||
Operation.parameter(:email, :query, :string, "Lookup a user with this email"),
|
||||
Operation.parameter(
|
||||
:ip,
|
||||
:query,
|
||||
:string,
|
||||
"Lookup users with this IP address (not implemented yet)"
|
||||
)
|
||||
] ++
|
||||
pagination_params(),
|
||||
responses: %{
|
||||
200 =>
|
||||
Operation.response("Account", "application/json", %Schema{
|
||||
title: "ArrayOfAccounts",
|
||||
type: :array,
|
||||
items: account()
|
||||
}),
|
||||
401 => Operation.response("Error", "application/json", ApiError)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def show_operation do
|
||||
%Operation{
|
||||
tags: ["User administration (Mastodon API)"],
|
||||
|
|
|
@ -30,7 +30,7 @@ defmodule Pleroma.Web.MastodonAPI.Admin.AccountController do
|
|||
plug(
|
||||
OAuthScopesPlug,
|
||||
%{scopes: ["admin:read:accounts"]}
|
||||
when action in [:index, :show]
|
||||
when action in [:index, :index2, :show]
|
||||
)
|
||||
|
||||
plug(
|
||||
|
@ -71,6 +71,18 @@ defmodule Pleroma.Web.MastodonAPI.Admin.AccountController do
|
|||
|> render("index.json", users: users)
|
||||
end
|
||||
|
||||
def index2(conn, params) do
|
||||
users =
|
||||
params
|
||||
|> build_criteria_v2()
|
||||
|> User.Query.build()
|
||||
|> Pagination.fetch_paginated(params)
|
||||
|
||||
conn
|
||||
|> add_link_headers(users)
|
||||
|> render("index.json", users: users)
|
||||
end
|
||||
|
||||
def show(%{assigns: %{user: _admin, account: user}} = conn, _params) do
|
||||
render(conn, "show.json", user: user)
|
||||
end
|
||||
|
@ -166,18 +178,39 @@ defmodule Pleroma.Web.MastodonAPI.Admin.AccountController do
|
|||
|> maybe_filter_staff(params)
|
||||
end
|
||||
|
||||
defp build_criteria_v2(params) do
|
||||
%{}
|
||||
|> maybe_filter_origin(params)
|
||||
|> maybe_filter_status(params)
|
||||
|> maybe_filter_nickname(params)
|
||||
|> maybe_filter_name(params)
|
||||
|> maybe_filter_email(params)
|
||||
end
|
||||
|
||||
defp maybe_filter_local(criteria, %{local: true} = _params),
|
||||
do: Map.put(criteria, :local, true)
|
||||
|
||||
defp maybe_filter_local(criteria, %{local: false} = _params),
|
||||
do: Map.put(criteria, :external, true)
|
||||
|
||||
defp maybe_filter_local(criteria, _), do: criteria
|
||||
|
||||
defp maybe_filter_external(criteria, %{remote: true} = _params),
|
||||
do: Map.put(criteria, :external, true)
|
||||
|
||||
defp maybe_filter_external(criteria, %{remote: false} = _params),
|
||||
do: Map.put(criteria, :local, true)
|
||||
|
||||
defp maybe_filter_external(criteria, _), do: criteria
|
||||
|
||||
defp maybe_filter_origin(criteria, %{origin: "local"} = _params),
|
||||
do: Map.put(criteria, :local, true)
|
||||
|
||||
defp maybe_filter_origin(criteria, %{origin: "remote"} = _params),
|
||||
do: Map.put(criteria, :external, true)
|
||||
|
||||
defp maybe_filter_origin(criteria, _params), do: criteria
|
||||
|
||||
defp maybe_filter_active(criteria, %{active: active} = _params),
|
||||
do: Map.put(criteria, :active, active)
|
||||
|
||||
|
@ -187,6 +220,18 @@ defmodule Pleroma.Web.MastodonAPI.Admin.AccountController do
|
|||
defp maybe_filter_deactivated(criteria, %{disabled: deactivated} = _params),
|
||||
do: Map.put(criteria, :deactivated, deactivated)
|
||||
|
||||
defp maybe_filter_status(criteria, %{status: "active"} = _params),
|
||||
do: Map.put(criteria, :active, true)
|
||||
|
||||
defp maybe_filter_status(criteria, %{status: "inactive"} = _params),
|
||||
do: Map.put(criteria, :active, false)
|
||||
|
||||
defp maybe_filter_status(criteria, %{status: "pending"} = _params),
|
||||
do: Map.put(criteria, :need_approval, true)
|
||||
|
||||
defp maybe_filter_status(criteria, %{status: "disabled"} = _params),
|
||||
do: Map.put(criteria, :deactivated, true)
|
||||
|
||||
defp maybe_filter_nickname(criteria, %{username: nickname} = _params),
|
||||
do: Map.put(criteria, :nickname, nickname)
|
||||
|
||||
|
|
|
@ -456,6 +456,13 @@ defmodule Pleroma.Web.Router do
|
|||
post("/reports/:id/reopen", ReportController, :reopen)
|
||||
end
|
||||
|
||||
# Mastodon AdminAPI: admins and mods (staff) can perform these actions (if privileged by role)
|
||||
scope "/api/v2/admin", Pleroma.Web.MastodonAPI.Admin do
|
||||
pipe_through([:require_privileged_role_users_read])
|
||||
|
||||
get("/accounts", AccountController, :index2)
|
||||
end
|
||||
|
||||
# AdminAPI: admins and mods (staff) can perform these actions (if privileged by role)
|
||||
scope "/api/v1/pleroma/admin", Pleroma.Web.AdminAPI do
|
||||
pipe_through(:require_privileged_role_emoji_manage_emoji)
|
||||
|
|
Loading…
Reference in a new issue