MastoAPI: /api/v2/admin/accounts
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
parent
0e0931a3c2
commit
2c14121389
5 changed files with 164 additions and 26 deletions
|
|
@ -302,6 +302,11 @@ defmodule Pleroma.User.Query do
|
||||||
where(query, [u], u.is_admin == true or u.is_moderator == true)
|
where(query, [u], u.is_admin == true or u.is_moderator == true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp compose_query({:domain, domain}, query) do
|
||||||
|
query
|
||||||
|
|> where([u], like(u.nickname, ^"%@#{domain}"))
|
||||||
|
end
|
||||||
|
|
||||||
defp compose_query(_unsupported_param, query), do: query
|
defp compose_query(_unsupported_param, query), do: query
|
||||||
|
|
||||||
defp location_query(query, local) do
|
defp location_query(query, local) do
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ defmodule Pleroma.Web.ApiSpec.MastodonAdmin.AccountOperation do
|
||||||
def index_operation do
|
def index_operation do
|
||||||
%Operation{
|
%Operation{
|
||||||
tags: ["User administration (Mastodon API)"],
|
tags: ["User administration (Mastodon API)"],
|
||||||
summary: "View accounts by criteria",
|
summary: "View accounts by criteria (v1)",
|
||||||
operationId: "MastodonAdmin.AccountController.index",
|
operationId: "MastodonAdmin.AccountController.index",
|
||||||
description: "View accounts matching certain criteria for filtering, up to 40 at a time.",
|
description: "View accounts matching certain criteria for filtering, up to 40 at a time.",
|
||||||
security: [%{"oAuth" => ["admin:read:accounts"]}],
|
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(:local, :query, :boolean, "Filter for local accounts?"),
|
||||||
Operation.parameter(:remote, :query, :boolean, "Filter for remote 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(
|
Operation.parameter(
|
||||||
:active,
|
:active,
|
||||||
:query,
|
:query,
|
||||||
|
|
@ -51,12 +45,6 @@ defmodule Pleroma.Web.ApiSpec.MastodonAdmin.AccountOperation do
|
||||||
:boolean,
|
:boolean,
|
||||||
"Filter for currently disabled accounts?"
|
"Filter for currently disabled accounts?"
|
||||||
),
|
),
|
||||||
Operation.parameter(
|
|
||||||
:sensitized,
|
|
||||||
:query,
|
|
||||||
:boolean,
|
|
||||||
"Filter for currently sensitized accounts? (not implemented yet)"
|
|
||||||
),
|
|
||||||
Operation.parameter(
|
Operation.parameter(
|
||||||
:silenced,
|
:silenced,
|
||||||
:query,
|
:query,
|
||||||
|
|
@ -69,14 +57,31 @@ defmodule Pleroma.Web.ApiSpec.MastodonAdmin.AccountOperation do
|
||||||
:boolean,
|
:boolean,
|
||||||
"Filter for currently suspended accounts? (not implemented yet)"
|
"Filter for currently suspended accounts? (not implemented yet)"
|
||||||
),
|
),
|
||||||
Operation.parameter(:username, :query, :string, "Username to search for"),
|
Operation.parameter(
|
||||||
Operation.parameter(:display_name, :query, :string, "Display name to search for"),
|
: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"
|
||||||
|
),
|
||||||
Operation.parameter(:email, :query, :string, "Lookup a user with this email"),
|
Operation.parameter(:email, :query, :string, "Lookup a user with this email"),
|
||||||
Operation.parameter(
|
Operation.parameter(
|
||||||
:ip,
|
:ip,
|
||||||
:query,
|
:query,
|
||||||
:string,
|
: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?")
|
Operation.parameter(:staff, :query, :boolean, "Filter for staff accounts?")
|
||||||
] ++
|
] ++
|
||||||
|
|
@ -93,6 +98,87 @@ defmodule Pleroma.Web.ApiSpec.MastodonAdmin.AccountOperation do
|
||||||
}
|
}
|
||||||
end
|
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"
|
||||||
|
),
|
||||||
|
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
|
def show_operation do
|
||||||
%Operation{
|
%Operation{
|
||||||
tags: ["User administration (Mastodon API)"],
|
tags: ["User administration (Mastodon API)"],
|
||||||
|
|
|
||||||
|
|
@ -119,16 +119,12 @@ defmodule Pleroma.Web.ApiSpec.MastodonAdmin.ReportOperation do
|
||||||
account: AccountOperation.account(),
|
account: AccountOperation.account(),
|
||||||
target_account: AccountOperation.account(),
|
target_account: AccountOperation.account(),
|
||||||
assigned_account: %Schema{
|
assigned_account: %Schema{
|
||||||
oneOf: [
|
type: AccountOperation.account(),
|
||||||
AccountOperation.account(),
|
nullable: true
|
||||||
%Schema{type: :null}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
action_taken_by_account: %Schema{
|
action_taken_by_account: %Schema{
|
||||||
oneOf: [
|
type: AccountOperation.account(),
|
||||||
AccountOperation.account(),
|
nullable: true
|
||||||
%Schema{type: :null}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
statuses: %Schema{
|
statuses: %Schema{
|
||||||
type: :array,
|
type: :array,
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ defmodule Pleroma.Web.MastodonAPI.Admin.AccountController do
|
||||||
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
||||||
|
|
||||||
@filter_params ~W(
|
@filter_params ~W(
|
||||||
local external active needing_approval deactivated nickname name email staff
|
local external active needing_approval deactivated nickname name domain email staff origin status
|
||||||
)
|
)
|
||||||
|
|
||||||
plug(Pleroma.Web.ApiSpec.CastAndValidate)
|
plug(Pleroma.Web.ApiSpec.CastAndValidate)
|
||||||
|
|
@ -30,7 +30,7 @@ defmodule Pleroma.Web.MastodonAPI.Admin.AccountController do
|
||||||
plug(
|
plug(
|
||||||
OAuthScopesPlug,
|
OAuthScopesPlug,
|
||||||
%{scopes: ["admin:read:accounts"]}
|
%{scopes: ["admin:read:accounts"]}
|
||||||
when action in [:index, :show]
|
when action in [:index, :index2, :show]
|
||||||
)
|
)
|
||||||
|
|
||||||
plug(
|
plug(
|
||||||
|
|
@ -71,6 +71,18 @@ defmodule Pleroma.Web.MastodonAPI.Admin.AccountController do
|
||||||
|> render("index.json", users: users)
|
|> render("index.json", users: users)
|
||||||
end
|
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
|
def show(%{assigns: %{user: _admin, account: user}} = conn, _params) do
|
||||||
render(conn, "show.json", user: user)
|
render(conn, "show.json", user: user)
|
||||||
end
|
end
|
||||||
|
|
@ -162,10 +174,21 @@ defmodule Pleroma.Web.MastodonAPI.Admin.AccountController do
|
||||||
|> maybe_filter_deactivated(params)
|
|> maybe_filter_deactivated(params)
|
||||||
|> maybe_filter_nickname(params)
|
|> maybe_filter_nickname(params)
|
||||||
|> maybe_filter_name(params)
|
|> maybe_filter_name(params)
|
||||||
|
|> maybe_filter_domain(params)
|
||||||
|> maybe_filter_email(params)
|
|> maybe_filter_email(params)
|
||||||
|> maybe_filter_staff(params)
|
|> maybe_filter_staff(params)
|
||||||
end
|
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_domain(params)
|
||||||
|
|> maybe_filter_email(params)
|
||||||
|
end
|
||||||
|
|
||||||
defp maybe_filter_local(criteria, %{local: true} = _params),
|
defp maybe_filter_local(criteria, %{local: true} = _params),
|
||||||
do: Map.put(criteria, :local, true)
|
do: Map.put(criteria, :local, true)
|
||||||
|
|
||||||
|
|
@ -178,6 +201,12 @@ defmodule Pleroma.Web.MastodonAPI.Admin.AccountController do
|
||||||
defp maybe_filter_external(criteria, %{remote: false} = _params),
|
defp maybe_filter_external(criteria, %{remote: false} = _params),
|
||||||
do: Map.put(criteria, :local, true)
|
do: Map.put(criteria, :local, true)
|
||||||
|
|
||||||
|
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_active(criteria, %{active: active} = _params),
|
defp maybe_filter_active(criteria, %{active: active} = _params),
|
||||||
do: Map.put(criteria, :active, active)
|
do: Map.put(criteria, :active, active)
|
||||||
|
|
||||||
|
|
@ -187,12 +216,27 @@ defmodule Pleroma.Web.MastodonAPI.Admin.AccountController do
|
||||||
defp maybe_filter_deactivated(criteria, %{disabled: deactivated} = _params),
|
defp maybe_filter_deactivated(criteria, %{disabled: deactivated} = _params),
|
||||||
do: Map.put(criteria, :deactivated, deactivated)
|
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),
|
defp maybe_filter_nickname(criteria, %{username: nickname} = _params),
|
||||||
do: Map.put(criteria, :nickname, nickname)
|
do: Map.put(criteria, :nickname, nickname)
|
||||||
|
|
||||||
defp maybe_filter_name(criteria, %{display_name: name} = _params),
|
defp maybe_filter_name(criteria, %{display_name: name} = _params),
|
||||||
do: Map.put(criteria, :name, name)
|
do: Map.put(criteria, :name, name)
|
||||||
|
|
||||||
|
defp maybe_filter_domain(criteria, %{by_domain: domain} = _params),
|
||||||
|
do: Map.put(criteria, :domain, domain)
|
||||||
|
|
||||||
defp maybe_filter_email(criteria, %{email: email} = _params),
|
defp maybe_filter_email(criteria, %{email: email} = _params),
|
||||||
do: Map.put(criteria, :email, email)
|
do: Map.put(criteria, :email, email)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -458,6 +458,13 @@ defmodule Pleroma.Web.Router do
|
||||||
post("/reports/:id/reopen", ReportController, :reopen)
|
post("/reports/:id/reopen", ReportController, :reopen)
|
||||||
end
|
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)
|
# AdminAPI: admins and mods (staff) can perform these actions (if privileged by role)
|
||||||
scope "/api/v1/pleroma/admin", Pleroma.Web.AdminAPI do
|
scope "/api/v1/pleroma/admin", Pleroma.Web.AdminAPI do
|
||||||
pipe_through(:require_privileged_role_emoji_manage_emoji)
|
pipe_through(:require_privileged_role_emoji_manage_emoji)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue