Compare commits

...

4 Commits

Author SHA1 Message Date
Mark Felder
55b1430dab Test the output of the endpoint 2021-02-18 15:09:14 -06:00
Mark Felder
beb7d4dcf0 Document the new endpoint 2021-02-18 14:47:50 -06:00
Mark Felder
8d7d6d85b4 Format 2021-02-18 14:34:01 -06:00
Mark Felder
2fb44f012d Add AdminAPI endpoint for retrieving a list of tabs to be rendered in AdminFE for ConfigDB Settings 2021-02-18 14:21:49 -06:00
8 changed files with 98 additions and 3 deletions

View File

@ -63,6 +63,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
<details>
<summary>API Changes</summary>
- Admin API: (`GET /api/pleroma/admin/users`) filter users by `unconfirmed` status and `actor_type`.
- Admin API: Add endpoint to provide a list of tabs for rendering the AdminFE Settings config section (`GET /api/pleroma/admin/config/tabs`)
- Pleroma API: `GET /api/v2/pleroma/chats` added. It is exactly like `GET /api/v1/pleroma/chats` except supports pagination.
- Pleroma API: Add `idempotency_key` to the chat message entity that can be used for optimistic message sending.
- Pleroma API: (`GET /api/v1/pleroma/federation_status`) Add a way to get a list of unreachable instances.

View File

@ -69,6 +69,30 @@ frontend_options = [
}
]
config :pleroma, :config_tablist, [
%{label: "ActivityPub", path: "activity-pub"},
%{label: "Authentication", path: "authentication"},
%{label: "Captcha", path: "captcha"},
%{label: "BBS / SSH access", path: "esshd"},
%{label: "Emoji", path: "emoji"},
%{label: "Frontend", path: "frontend"},
%{label: "Gopher", path: "gopher"},
%{label: "HTTP", path: "http"},
%{label: "Instance", path: "instance"},
%{label: "Job queue", path: "job-queue"},
%{label: "Link Formatter", path: "link-formatter"},
%{label: "Logger", path: "logger"},
%{label: "Mailer", path: "mailer"},
%{label: "Media Proxy", path: "media-proxy"},
%{label: "Metadata", path: "metadata"},
%{label: "MRF", path: "mrf"},
%{label: "Rate limiters", path: "rate-limiters"},
%{label: "Relays", path: "relays"},
%{label: "Web push encryption", path: "web-push"},
%{label: "Upload", path: "upload"},
%{label: "Other", path: "other"}
]
config :pleroma, :config_description, [
%{
group: :pleroma,

View File

@ -1122,6 +1122,30 @@ Loads json generated from `config/descriptions.exs`.
}]
```
## ` GET /api/pleroma/admin/config/tabs`
### Get JSON formatted list of ConfigDB setting routes for AdminFE
Also generated from `config/descriptions.exs`.
- Params: none
- Response:
```json
[
{
"label": "ActivityPub", // Text label of the setting
"path": "activity-pub" // URL path for rendering that group of settings
},
{
"label": "Authentication",
"path": "authentication"
},
{
"label": "Captcha",
"path": "captcha"
}
```
## `GET /api/pleroma/admin/moderation_log`
### Get moderation log

View File

@ -7,6 +7,7 @@ defmodule Pleroma.Docs.JSON do
@external_resource "config/description.exs"
@raw_config Pleroma.Config.Loader.read("config/description.exs")
@raw_descriptions @raw_config[:pleroma][:config_description]
@raw_tablist @raw_config[:pleroma][:config_tablist]
@term __MODULE__.Compiled
@spec compile :: :ok
@ -15,7 +16,12 @@ defmodule Pleroma.Docs.JSON do
Pleroma.Web.ActivityPub.MRF.config_descriptions()
|> Enum.reduce(@raw_descriptions, fn description, acc -> [description | acc] end)
:persistent_term.put(@term, Pleroma.Docs.Generator.convert_to_strings(descriptions))
data = %{
tabs: @raw_tablist,
descriptions: Pleroma.Docs.Generator.convert_to_strings(descriptions)
}
:persistent_term.put(@term, data)
end
@spec compiled_descriptions :: Map.t()

View File

@ -15,7 +15,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigController do
plug(
OAuthScopesPlug,
%{scopes: ["admin:read"]}
when action in [:show, :descriptions]
when action in [:show, :descriptions, :tabs]
)
action_fallback(Pleroma.Web.AdminAPI.FallbackController)
@ -23,11 +23,18 @@ defmodule Pleroma.Web.AdminAPI.ConfigController do
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.Admin.ConfigOperation
def descriptions(conn, _params) do
descriptions = Enum.filter(Pleroma.Docs.JSON.compiled_descriptions(), &whitelisted_config?/1)
%{tabs: _, descriptions: descriptions} = Pleroma.Docs.JSON.compiled_descriptions()
descriptions = Enum.filter(descriptions, &whitelisted_config?/1)
json(conn, descriptions)
end
def tabs(conn, _params) do
%{tabs: tabs, descriptions: _} = Pleroma.Docs.JSON.compiled_descriptions()
json(conn, tabs)
end
def show(conn, %{only_db: true}) do
with :ok <- configurable_from_database() do
configs = Pleroma.Repo.all(ConfigDB)

View File

@ -107,6 +107,30 @@ defmodule Pleroma.Web.ApiSpec.Admin.ConfigOperation do
}
end
def tabs_operation do
%Operation{
tags: ["Instance configuration"],
summary: "Retrieve config tabs for AdminFE",
operationId: "AdminAPI.ConfigController.tabs",
security: [%{"oAuth" => ["admin:read"]}],
parameters: admin_api_params(),
responses: %{
200 =>
Operation.response("Config Tab List", "application/json", %Schema{
type: :array,
items: %Schema{
type: :object,
properties: %{
label: %Schema{type: :string},
path: %Schema{type: :string}
}
}
}),
400 => Operation.response("Bad Request", "application/json", ApiError)
}
}
end
defp any do
%Schema{
oneOf: [

View File

@ -232,6 +232,7 @@ defmodule Pleroma.Web.Router do
get("/config", ConfigController, :show)
post("/config", ConfigController, :update)
get("/config/descriptions", ConfigController, :descriptions)
get("/config/tabs", ConfigController, :tabs)
get("/need_reboot", AdminAPIController, :need_reboot)
get("/restart", AdminAPIController, :restart)

View File

@ -1453,4 +1453,12 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
assert esshd["children"]
end
end
test "GET /api/pleroma/admin/config/tabs", %{conn: conn} do
result = get(conn, "/api/pleroma/admin/config/tabs") |> json_response_and_validate_schema(200)
assert length(result) > 0
assert Enum.any?(result, fn tab -> tab["label"] == "Instance" end)
end
end