forked from AkkomaGang/akkoma
[#1940] Added admin_token
param (as admin_api_params/0
) to existing Admin API OpenAPI operations.
This commit is contained in:
parent
ce314e6fe2
commit
124b4709dc
9 changed files with 38 additions and 7 deletions
|
@ -29,6 +29,10 @@ def request_body(description, schema_ref, opts \\ []) do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def admin_api_params do
|
||||||
|
[Operation.parameter(:admin_token, :query, :string, "Allows authorization via admin token.")]
|
||||||
|
end
|
||||||
|
|
||||||
def pagination_params do
|
def pagination_params do
|
||||||
[
|
[
|
||||||
Operation.parameter(:max_id, :query, :string, "Return items older than this ID"),
|
Operation.parameter(:max_id, :query, :string, "Return items older than this ID"),
|
||||||
|
|
|
@ -26,6 +26,7 @@ def show_operation do
|
||||||
%Schema{type: :boolean, default: false},
|
%Schema{type: :boolean, default: false},
|
||||||
"Get only saved in database settings"
|
"Get only saved in database settings"
|
||||||
)
|
)
|
||||||
|
| admin_api_params()
|
||||||
],
|
],
|
||||||
security: [%{"oAuth" => ["read"]}],
|
security: [%{"oAuth" => ["read"]}],
|
||||||
responses: %{
|
responses: %{
|
||||||
|
@ -41,6 +42,7 @@ def update_operation do
|
||||||
summary: "Update config settings",
|
summary: "Update config settings",
|
||||||
operationId: "AdminAPI.ConfigController.update",
|
operationId: "AdminAPI.ConfigController.update",
|
||||||
security: [%{"oAuth" => ["write"]}],
|
security: [%{"oAuth" => ["write"]}],
|
||||||
|
parameters: admin_api_params(),
|
||||||
requestBody:
|
requestBody:
|
||||||
request_body("Parameters", %Schema{
|
request_body("Parameters", %Schema{
|
||||||
type: :object,
|
type: :object,
|
||||||
|
@ -73,6 +75,7 @@ def descriptions_operation do
|
||||||
summary: "Get JSON with config descriptions.",
|
summary: "Get JSON with config descriptions.",
|
||||||
operationId: "AdminAPI.ConfigController.descriptions",
|
operationId: "AdminAPI.ConfigController.descriptions",
|
||||||
security: [%{"oAuth" => ["read"]}],
|
security: [%{"oAuth" => ["read"]}],
|
||||||
|
parameters: admin_api_params(),
|
||||||
responses: %{
|
responses: %{
|
||||||
200 =>
|
200 =>
|
||||||
Operation.response("Config Descriptions", "application/json", %Schema{
|
Operation.response("Config Descriptions", "application/json", %Schema{
|
||||||
|
|
|
@ -20,6 +20,7 @@ def index_operation do
|
||||||
summary: "Get a list of generated invites",
|
summary: "Get a list of generated invites",
|
||||||
operationId: "AdminAPI.InviteController.index",
|
operationId: "AdminAPI.InviteController.index",
|
||||||
security: [%{"oAuth" => ["read:invites"]}],
|
security: [%{"oAuth" => ["read:invites"]}],
|
||||||
|
parameters: admin_api_params(),
|
||||||
responses: %{
|
responses: %{
|
||||||
200 =>
|
200 =>
|
||||||
Operation.response("Invites", "application/json", %Schema{
|
Operation.response("Invites", "application/json", %Schema{
|
||||||
|
@ -51,6 +52,7 @@ def create_operation do
|
||||||
summary: "Create an account registration invite token",
|
summary: "Create an account registration invite token",
|
||||||
operationId: "AdminAPI.InviteController.create",
|
operationId: "AdminAPI.InviteController.create",
|
||||||
security: [%{"oAuth" => ["write:invites"]}],
|
security: [%{"oAuth" => ["write:invites"]}],
|
||||||
|
parameters: admin_api_params(),
|
||||||
requestBody:
|
requestBody:
|
||||||
request_body("Parameters", %Schema{
|
request_body("Parameters", %Schema{
|
||||||
type: :object,
|
type: :object,
|
||||||
|
@ -71,6 +73,7 @@ def revoke_operation do
|
||||||
summary: "Revoke invite by token",
|
summary: "Revoke invite by token",
|
||||||
operationId: "AdminAPI.InviteController.revoke",
|
operationId: "AdminAPI.InviteController.revoke",
|
||||||
security: [%{"oAuth" => ["write:invites"]}],
|
security: [%{"oAuth" => ["write:invites"]}],
|
||||||
|
parameters: admin_api_params(),
|
||||||
requestBody:
|
requestBody:
|
||||||
request_body(
|
request_body(
|
||||||
"Parameters",
|
"Parameters",
|
||||||
|
@ -97,6 +100,7 @@ def email_operation do
|
||||||
summary: "Sends registration invite via email",
|
summary: "Sends registration invite via email",
|
||||||
operationId: "AdminAPI.InviteController.email",
|
operationId: "AdminAPI.InviteController.email",
|
||||||
security: [%{"oAuth" => ["write:invites"]}],
|
security: [%{"oAuth" => ["write:invites"]}],
|
||||||
|
parameters: admin_api_params(),
|
||||||
requestBody:
|
requestBody:
|
||||||
request_body(
|
request_body(
|
||||||
"Parameters",
|
"Parameters",
|
||||||
|
|
|
@ -33,6 +33,7 @@ def index_operation do
|
||||||
%Schema{type: :integer, default: 50},
|
%Schema{type: :integer, default: 50},
|
||||||
"Number of statuses to return"
|
"Number of statuses to return"
|
||||||
)
|
)
|
||||||
|
| admin_api_params()
|
||||||
],
|
],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => success_response()
|
200 => success_response()
|
||||||
|
@ -46,6 +47,7 @@ def delete_operation do
|
||||||
summary: "Remove a banned MediaProxy URL from Cachex",
|
summary: "Remove a banned MediaProxy URL from Cachex",
|
||||||
operationId: "AdminAPI.MediaProxyCacheController.delete",
|
operationId: "AdminAPI.MediaProxyCacheController.delete",
|
||||||
security: [%{"oAuth" => ["write:media_proxy_caches"]}],
|
security: [%{"oAuth" => ["write:media_proxy_caches"]}],
|
||||||
|
parameters: admin_api_params(),
|
||||||
requestBody:
|
requestBody:
|
||||||
request_body(
|
request_body(
|
||||||
"Parameters",
|
"Parameters",
|
||||||
|
@ -71,6 +73,7 @@ def purge_operation do
|
||||||
summary: "Purge and optionally ban a MediaProxy URL",
|
summary: "Purge and optionally ban a MediaProxy URL",
|
||||||
operationId: "AdminAPI.MediaProxyCacheController.purge",
|
operationId: "AdminAPI.MediaProxyCacheController.purge",
|
||||||
security: [%{"oAuth" => ["write:media_proxy_caches"]}],
|
security: [%{"oAuth" => ["write:media_proxy_caches"]}],
|
||||||
|
parameters: admin_api_params(),
|
||||||
requestBody:
|
requestBody:
|
||||||
request_body(
|
request_body(
|
||||||
"Parameters",
|
"Parameters",
|
||||||
|
|
|
@ -36,6 +36,7 @@ def index_operation do
|
||||||
%Schema{type: :integer, default: 50},
|
%Schema{type: :integer, default: 50},
|
||||||
"Number of apps to return"
|
"Number of apps to return"
|
||||||
)
|
)
|
||||||
|
| admin_api_params()
|
||||||
],
|
],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 =>
|
200 =>
|
||||||
|
@ -72,6 +73,7 @@ def create_operation do
|
||||||
summary: "Create OAuth App",
|
summary: "Create OAuth App",
|
||||||
operationId: "AdminAPI.OAuthAppController.create",
|
operationId: "AdminAPI.OAuthAppController.create",
|
||||||
requestBody: request_body("Parameters", create_request()),
|
requestBody: request_body("Parameters", create_request()),
|
||||||
|
parameters: admin_api_params(),
|
||||||
security: [%{"oAuth" => ["write"]}],
|
security: [%{"oAuth" => ["write"]}],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("App", "application/json", oauth_app()),
|
200 => Operation.response("App", "application/json", oauth_app()),
|
||||||
|
@ -85,7 +87,7 @@ def update_operation do
|
||||||
tags: ["Admin", "oAuth Apps"],
|
tags: ["Admin", "oAuth Apps"],
|
||||||
summary: "Update OAuth App",
|
summary: "Update OAuth App",
|
||||||
operationId: "AdminAPI.OAuthAppController.update",
|
operationId: "AdminAPI.OAuthAppController.update",
|
||||||
parameters: [id_param()],
|
parameters: [id_param() | admin_api_params()],
|
||||||
security: [%{"oAuth" => ["write"]}],
|
security: [%{"oAuth" => ["write"]}],
|
||||||
requestBody: request_body("Parameters", update_request()),
|
requestBody: request_body("Parameters", update_request()),
|
||||||
responses: %{
|
responses: %{
|
||||||
|
@ -103,7 +105,7 @@ def delete_operation do
|
||||||
tags: ["Admin", "oAuth Apps"],
|
tags: ["Admin", "oAuth Apps"],
|
||||||
summary: "Delete OAuth App",
|
summary: "Delete OAuth App",
|
||||||
operationId: "AdminAPI.OAuthAppController.delete",
|
operationId: "AdminAPI.OAuthAppController.delete",
|
||||||
parameters: [id_param()],
|
parameters: [id_param() | admin_api_params()],
|
||||||
security: [%{"oAuth" => ["write"]}],
|
security: [%{"oAuth" => ["write"]}],
|
||||||
responses: %{
|
responses: %{
|
||||||
204 => no_content_response(),
|
204 => no_content_response(),
|
||||||
|
|
|
@ -19,6 +19,7 @@ def index_operation do
|
||||||
summary: "List Relays",
|
summary: "List Relays",
|
||||||
operationId: "AdminAPI.RelayController.index",
|
operationId: "AdminAPI.RelayController.index",
|
||||||
security: [%{"oAuth" => ["read"]}],
|
security: [%{"oAuth" => ["read"]}],
|
||||||
|
parameters: admin_api_params(),
|
||||||
responses: %{
|
responses: %{
|
||||||
200 =>
|
200 =>
|
||||||
Operation.response("Response", "application/json", %Schema{
|
Operation.response("Response", "application/json", %Schema{
|
||||||
|
@ -41,6 +42,7 @@ def follow_operation do
|
||||||
summary: "Follow a Relay",
|
summary: "Follow a Relay",
|
||||||
operationId: "AdminAPI.RelayController.follow",
|
operationId: "AdminAPI.RelayController.follow",
|
||||||
security: [%{"oAuth" => ["write:follows"]}],
|
security: [%{"oAuth" => ["write:follows"]}],
|
||||||
|
parameters: admin_api_params(),
|
||||||
requestBody:
|
requestBody:
|
||||||
request_body("Parameters", %Schema{
|
request_body("Parameters", %Schema{
|
||||||
type: :object,
|
type: :object,
|
||||||
|
@ -64,6 +66,7 @@ def unfollow_operation do
|
||||||
summary: "Unfollow a Relay",
|
summary: "Unfollow a Relay",
|
||||||
operationId: "AdminAPI.RelayController.unfollow",
|
operationId: "AdminAPI.RelayController.unfollow",
|
||||||
security: [%{"oAuth" => ["write:follows"]}],
|
security: [%{"oAuth" => ["write:follows"]}],
|
||||||
|
parameters: admin_api_params(),
|
||||||
requestBody:
|
requestBody:
|
||||||
request_body("Parameters", %Schema{
|
request_body("Parameters", %Schema{
|
||||||
type: :object,
|
type: :object,
|
||||||
|
|
|
@ -48,6 +48,7 @@ def index_operation do
|
||||||
%Schema{type: :integer, default: 50},
|
%Schema{type: :integer, default: 50},
|
||||||
"Number number of log entries per page"
|
"Number number of log entries per page"
|
||||||
)
|
)
|
||||||
|
| admin_api_params()
|
||||||
],
|
],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 =>
|
200 =>
|
||||||
|
@ -71,7 +72,7 @@ def show_operation do
|
||||||
tags: ["Admin", "Reports"],
|
tags: ["Admin", "Reports"],
|
||||||
summary: "Get an individual report",
|
summary: "Get an individual report",
|
||||||
operationId: "AdminAPI.ReportController.show",
|
operationId: "AdminAPI.ReportController.show",
|
||||||
parameters: [id_param()],
|
parameters: [id_param() | admin_api_params()],
|
||||||
security: [%{"oAuth" => ["read:reports"]}],
|
security: [%{"oAuth" => ["read:reports"]}],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Report", "application/json", report()),
|
200 => Operation.response("Report", "application/json", report()),
|
||||||
|
@ -86,6 +87,7 @@ def update_operation do
|
||||||
summary: "Change the state of one or multiple reports",
|
summary: "Change the state of one or multiple reports",
|
||||||
operationId: "AdminAPI.ReportController.update",
|
operationId: "AdminAPI.ReportController.update",
|
||||||
security: [%{"oAuth" => ["write:reports"]}],
|
security: [%{"oAuth" => ["write:reports"]}],
|
||||||
|
parameters: admin_api_params(),
|
||||||
requestBody: request_body("Parameters", update_request(), required: true),
|
requestBody: request_body("Parameters", update_request(), required: true),
|
||||||
responses: %{
|
responses: %{
|
||||||
204 => no_content_response(),
|
204 => no_content_response(),
|
||||||
|
@ -100,7 +102,7 @@ def notes_create_operation do
|
||||||
tags: ["Admin", "Reports"],
|
tags: ["Admin", "Reports"],
|
||||||
summary: "Create report note",
|
summary: "Create report note",
|
||||||
operationId: "AdminAPI.ReportController.notes_create",
|
operationId: "AdminAPI.ReportController.notes_create",
|
||||||
parameters: [id_param()],
|
parameters: [id_param() | admin_api_params()],
|
||||||
requestBody:
|
requestBody:
|
||||||
request_body("Parameters", %Schema{
|
request_body("Parameters", %Schema{
|
||||||
type: :object,
|
type: :object,
|
||||||
|
@ -124,6 +126,7 @@ def notes_delete_operation do
|
||||||
parameters: [
|
parameters: [
|
||||||
Operation.parameter(:report_id, :path, :string, "Report ID"),
|
Operation.parameter(:report_id, :path, :string, "Report ID"),
|
||||||
Operation.parameter(:id, :path, :string, "Note ID")
|
Operation.parameter(:id, :path, :string, "Note ID")
|
||||||
|
| admin_api_params()
|
||||||
],
|
],
|
||||||
security: [%{"oAuth" => ["write:reports"]}],
|
security: [%{"oAuth" => ["write:reports"]}],
|
||||||
responses: %{
|
responses: %{
|
||||||
|
|
|
@ -55,6 +55,7 @@ def index_operation do
|
||||||
%Schema{type: :integer, default: 50},
|
%Schema{type: :integer, default: 50},
|
||||||
"Number of statuses to return"
|
"Number of statuses to return"
|
||||||
)
|
)
|
||||||
|
| admin_api_params()
|
||||||
],
|
],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 =>
|
200 =>
|
||||||
|
@ -71,7 +72,7 @@ def show_operation do
|
||||||
tags: ["Admin", "Statuses"],
|
tags: ["Admin", "Statuses"],
|
||||||
summary: "Show Status",
|
summary: "Show Status",
|
||||||
operationId: "AdminAPI.StatusController.show",
|
operationId: "AdminAPI.StatusController.show",
|
||||||
parameters: [id_param()],
|
parameters: [id_param() | admin_api_params()],
|
||||||
security: [%{"oAuth" => ["read:statuses"]}],
|
security: [%{"oAuth" => ["read:statuses"]}],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Status", "application/json", status()),
|
200 => Operation.response("Status", "application/json", status()),
|
||||||
|
@ -85,7 +86,7 @@ def update_operation do
|
||||||
tags: ["Admin", "Statuses"],
|
tags: ["Admin", "Statuses"],
|
||||||
summary: "Change the scope of an individual reported status",
|
summary: "Change the scope of an individual reported status",
|
||||||
operationId: "AdminAPI.StatusController.update",
|
operationId: "AdminAPI.StatusController.update",
|
||||||
parameters: [id_param()],
|
parameters: [id_param() | admin_api_params()],
|
||||||
security: [%{"oAuth" => ["write:statuses"]}],
|
security: [%{"oAuth" => ["write:statuses"]}],
|
||||||
requestBody: request_body("Parameters", update_request(), required: true),
|
requestBody: request_body("Parameters", update_request(), required: true),
|
||||||
responses: %{
|
responses: %{
|
||||||
|
@ -100,7 +101,7 @@ def delete_operation do
|
||||||
tags: ["Admin", "Statuses"],
|
tags: ["Admin", "Statuses"],
|
||||||
summary: "Delete an individual reported status",
|
summary: "Delete an individual reported status",
|
||||||
operationId: "AdminAPI.StatusController.delete",
|
operationId: "AdminAPI.StatusController.delete",
|
||||||
parameters: [id_param()],
|
parameters: [id_param() | admin_api_params()],
|
||||||
security: [%{"oAuth" => ["write:statuses"]}],
|
security: [%{"oAuth" => ["write:statuses"]}],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => empty_object_response(),
|
200 => empty_object_response(),
|
||||||
|
|
|
@ -152,6 +152,14 @@ test "subkeys with full update right merge", %{conn: conn} do
|
||||||
assert emoji_val[:groups] == [a: 1, b: 2]
|
assert emoji_val[:groups] == [a: 1, b: 2]
|
||||||
assert assets_val[:mascots] == [a: 1, b: 2]
|
assert assets_val[:mascots] == [a: 1, b: 2]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "with valid `admin_token` query parameter, skips OAuth scopes check" do
|
||||||
|
clear_config([:admin_token], "password123")
|
||||||
|
|
||||||
|
build_conn()
|
||||||
|
|> get("/api/pleroma/admin/config?admin_token=password123")
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "POST /api/pleroma/admin/config error", %{conn: conn} do
|
test "POST /api/pleroma/admin/config error", %{conn: conn} do
|
||||||
|
|
Loading…
Reference in a new issue