Add AdminAPI endpoint for retrieving a list of tabs to be rendered in AdminFE for ConfigDB Settings
This commit is contained in:
parent
8829a408ec
commit
2fb44f012d
@ -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,
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -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: [
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user