config descriptions v2 endpoint with tabs field
This commit is contained in:
parent
f9d9987df8
commit
f20c1afe46
@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||||||
|
|
||||||
- The `application` metadata returned with statuses is no longer hardcoded. Apps that want to display these details will now have valid data for new posts after this change.
|
- The `application` metadata returned with statuses is no longer hardcoded. Apps that want to display these details will now have valid data for new posts after this change.
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Admin API: Added `GET /api/v2/pleroma/admin/config/descriptions` endpoint, differs from `/api/v1/pleroma/admin/config/descriptions` in response format and has additional field with the tabs list.
|
||||||
|
|
||||||
## Unreleased (Patch)
|
## Unreleased (Patch)
|
||||||
|
|
||||||
## [2.3.0] - 2020-03-01
|
## [2.3.0] - 2020-03-01
|
||||||
|
@ -1107,6 +1107,7 @@ Loads json generated from `config/descriptions.exs`.
|
|||||||
"type": "group", // string or list with possible values,
|
"type": "group", // string or list with possible values,
|
||||||
"description": "Upload general settings", // string
|
"description": "Upload general settings", // string
|
||||||
"tab": "mrf",
|
"tab": "mrf",
|
||||||
|
"label": "MRF",
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"key": ":uploader", // string or module name `Pleroma.Upload`
|
"key": ":uploader", // string or module name `Pleroma.Upload`
|
||||||
@ -1126,6 +1127,47 @@ Loads json generated from `config/descriptions.exs`.
|
|||||||
}]
|
}]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## `GET /api/v2/pleroma/admin/config/descriptions`
|
||||||
|
|
||||||
|
### Get tabs and config descriptions
|
||||||
|
|
||||||
|
Loads json generated from `config/descriptions.exs`.
|
||||||
|
|
||||||
|
- Params: none
|
||||||
|
- Response:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"tabs": [{"tab": "activity_pub", "label": "ActivityPub"}],
|
||||||
|
"descriptions": [
|
||||||
|
{
|
||||||
|
"group": ":pleroma", // string
|
||||||
|
"key": "ModuleName", // string
|
||||||
|
"type": "group", // string or list with possible values,
|
||||||
|
"description": "Upload general settings", // string
|
||||||
|
"tab": "mrf",
|
||||||
|
"label": "MRF",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"key": ":uploader", // string or module name `Pleroma.Upload`
|
||||||
|
"type": "module",
|
||||||
|
"description": "Module which will be used for uploads",
|
||||||
|
"suggestions": ["module1", "module2"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": ":filters",
|
||||||
|
"type": ["list", "module"],
|
||||||
|
"description": "List of filter modules for uploads",
|
||||||
|
"suggestions": [
|
||||||
|
"module1", "module2", "module3"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## `GET /api/v1/pleroma/admin/moderation_log`
|
## `GET /api/v1/pleroma/admin/moderation_log`
|
||||||
|
|
||||||
### Get moderation log
|
### Get moderation log
|
||||||
|
@ -7,7 +7,9 @@ defmodule Pleroma.Docs.JSON do
|
|||||||
@external_resource "config/description.exs"
|
@external_resource "config/description.exs"
|
||||||
@raw_config Pleroma.Config.Loader.read("config/description.exs")
|
@raw_config Pleroma.Config.Loader.read("config/description.exs")
|
||||||
@raw_descriptions @raw_config[:pleroma][:config_description]
|
@raw_descriptions @raw_config[:pleroma][:config_description]
|
||||||
|
@raw_tabs @raw_config[:pleroma][:tabs]
|
||||||
@term __MODULE__.Compiled
|
@term __MODULE__.Compiled
|
||||||
|
@tabs __MODULE__.CompiledTabs
|
||||||
|
|
||||||
@spec compile :: :ok
|
@spec compile :: :ok
|
||||||
def compile do
|
def compile do
|
||||||
@ -16,13 +18,17 @@ defmodule Pleroma.Docs.JSON do
|
|||||||
|> Enum.reduce(@raw_descriptions, fn description, acc -> [description | acc] end)
|
|> Enum.reduce(@raw_descriptions, fn description, acc -> [description | acc] end)
|
||||||
|
|
||||||
:persistent_term.put(@term, Pleroma.Docs.Generator.convert_to_strings(descriptions))
|
:persistent_term.put(@term, Pleroma.Docs.Generator.convert_to_strings(descriptions))
|
||||||
|
:persistent_term.put(@tabs, @raw_tabs)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec compiled_descriptions :: Map.t()
|
@spec compiled_descriptions :: [map()]
|
||||||
def compiled_descriptions do
|
def compiled_descriptions do
|
||||||
:persistent_term.get(@term)
|
:persistent_term.get(@term)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec compiled_tabs() :: [map()]
|
||||||
|
def compiled_tabs, do: :persistent_term.get(@tabs)
|
||||||
|
|
||||||
@spec process(keyword()) :: {:ok, String.t()}
|
@spec process(keyword()) :: {:ok, String.t()}
|
||||||
def process(descriptions) do
|
def process(descriptions) do
|
||||||
with path <- "docs/generated_config.json",
|
with path <- "docs/generated_config.json",
|
||||||
|
@ -12,7 +12,6 @@ defmodule Pleroma.Web.ActivityPub.MRF do
|
|||||||
group: :pleroma,
|
group: :pleroma,
|
||||||
key: :mrf,
|
key: :mrf,
|
||||||
tab: :mrf,
|
tab: :mrf,
|
||||||
tab_label: "MRF",
|
|
||||||
label: "MRF",
|
label: "MRF",
|
||||||
type: :group,
|
type: :group,
|
||||||
description: "General MRF settings",
|
description: "General MRF settings",
|
||||||
@ -154,7 +153,6 @@ defmodule Pleroma.Web.ActivityPub.MRF do
|
|||||||
|> Map.merge(policy.config_description)
|
|> Map.merge(policy.config_description)
|
||||||
|> Map.put(:group, :pleroma)
|
|> Map.put(:group, :pleroma)
|
||||||
|> Map.put(:tab, :mrf)
|
|> Map.put(:tab, :mrf)
|
||||||
|> Map.put(:tab_label, "MRF")
|
|
||||||
|> Map.put(:type, :group)
|
|> Map.put(:type, :group)
|
||||||
|
|
||||||
if Enum.all?(@required_description_keys, &Map.has_key?(description, &1)) do
|
if Enum.all?(@required_description_keys, &Map.has_key?(description, &1)) do
|
||||||
|
@ -15,19 +15,34 @@ defmodule Pleroma.Web.AdminAPI.ConfigController do
|
|||||||
plug(
|
plug(
|
||||||
OAuthScopesPlug,
|
OAuthScopesPlug,
|
||||||
%{scopes: ["admin:read"]}
|
%{scopes: ["admin:read"]}
|
||||||
when action in [:show, :descriptions]
|
when action in [:show, :descriptions, :descriptions2]
|
||||||
)
|
)
|
||||||
|
|
||||||
action_fallback(Pleroma.Web.AdminAPI.FallbackController)
|
action_fallback(Pleroma.Web.AdminAPI.FallbackController)
|
||||||
|
|
||||||
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.Admin.ConfigOperation
|
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.Admin.ConfigOperation
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
GET /api/v1/pleroma/admin/config/descriptions
|
||||||
|
"""
|
||||||
def descriptions(conn, _params) do
|
def descriptions(conn, _params) do
|
||||||
descriptions = Enum.filter(Pleroma.Docs.JSON.compiled_descriptions(), &whitelisted_config?/1)
|
descriptions =
|
||||||
|
whitelisted_descriptions()
|
||||||
|
|> Enum.map(&Map.delete(&1, "tab"))
|
||||||
|
|
||||||
json(conn, descriptions)
|
json(conn, descriptions)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
GET /api/v2/pleroma/admin/config/descriptions
|
||||||
|
"""
|
||||||
|
def descriptions2(conn, _params) do
|
||||||
|
json(conn, %{
|
||||||
|
tabs: Pleroma.Docs.JSON.compiled_tabs(),
|
||||||
|
descriptions: whitelisted_descriptions()
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
def show(conn, %{only_db: true}) do
|
def show(conn, %{only_db: true}) do
|
||||||
with :ok <- configurable_from_database() do
|
with :ok <- configurable_from_database() do
|
||||||
configs = Pleroma.Repo.all(ConfigDB)
|
configs = Pleroma.Repo.all(ConfigDB)
|
||||||
@ -126,6 +141,10 @@ defmodule Pleroma.Web.AdminAPI.ConfigController do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp whitelisted_descriptions do
|
||||||
|
Enum.filter(Pleroma.Docs.JSON.compiled_descriptions(), &whitelisted_config?/1)
|
||||||
|
end
|
||||||
|
|
||||||
defp whitelisted_config?(group, key) do
|
defp whitelisted_config?(group, key) do
|
||||||
if whitelisted_configs = Config.get(:database_config_whitelist) do
|
if whitelisted_configs = Config.get(:database_config_whitelist) do
|
||||||
Enum.any?(whitelisted_configs, fn
|
Enum.any?(whitelisted_configs, fn
|
||||||
|
@ -78,31 +78,64 @@ defmodule Pleroma.Web.ApiSpec.Admin.ConfigOperation do
|
|||||||
parameters: admin_api_params(),
|
parameters: admin_api_params(),
|
||||||
responses: %{
|
responses: %{
|
||||||
200 =>
|
200 =>
|
||||||
|
Operation.response("Config Descriptions", "application/json", descriptions_schema()),
|
||||||
|
400 => Operation.response("Bad Request", "application/json", ApiError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def descriptions2_operation do
|
||||||
|
%Operation{
|
||||||
|
tags: ["Instance configuration"],
|
||||||
|
summary: "Retrieve config description",
|
||||||
|
operationId: "AdminAPI.ConfigController.descriptions2",
|
||||||
|
security: [%{"oAuth" => ["admin:read"]}],
|
||||||
|
parameters: admin_api_params(),
|
||||||
|
responses: %{
|
||||||
|
200 =>
|
||||||
Operation.response("Config Descriptions", "application/json", %Schema{
|
Operation.response("Config Descriptions", "application/json", %Schema{
|
||||||
|
type: :object,
|
||||||
|
properties: %{
|
||||||
|
tabs: %Schema{
|
||||||
|
type: :array,
|
||||||
|
items: %Schema{
|
||||||
|
type: :object,
|
||||||
|
properties: %{tab: %Schema{type: :string}, label: %Schema{type: :string}}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
descriptions: descriptions_schema()
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
400 => Operation.response("Bad Request", "application/json", ApiError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp descriptions_schema do
|
||||||
|
%Schema{
|
||||||
|
type: :array,
|
||||||
|
items: %Schema{
|
||||||
|
type: :object,
|
||||||
|
properties: %{
|
||||||
|
group: %Schema{type: :string},
|
||||||
|
key: %Schema{type: :string},
|
||||||
|
tab: %Schema{type: :string},
|
||||||
|
label: %Schema{type: :string},
|
||||||
|
type: %Schema{oneOf: [%Schema{type: :string}, %Schema{type: :array}]},
|
||||||
|
description: %Schema{type: :string},
|
||||||
|
children: %Schema{
|
||||||
type: :array,
|
type: :array,
|
||||||
items: %Schema{
|
items: %Schema{
|
||||||
type: :object,
|
type: :object,
|
||||||
properties: %{
|
properties: %{
|
||||||
group: %Schema{type: :string},
|
|
||||||
key: %Schema{type: :string},
|
key: %Schema{type: :string},
|
||||||
type: %Schema{oneOf: [%Schema{type: :string}, %Schema{type: :array}]},
|
type: %Schema{oneOf: [%Schema{type: :string}, %Schema{type: :array}]},
|
||||||
description: %Schema{type: :string},
|
description: %Schema{type: :string},
|
||||||
children: %Schema{
|
suggestions: %Schema{type: :array}
|
||||||
type: :array,
|
|
||||||
items: %Schema{
|
|
||||||
type: :object,
|
|
||||||
properties: %{
|
|
||||||
key: %Schema{type: :string},
|
|
||||||
type: %Schema{oneOf: [%Schema{type: :string}, %Schema{type: :array}]},
|
|
||||||
description: %Schema{type: :string},
|
|
||||||
suggestions: %Schema{type: :array}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}
|
||||||
400 => Operation.response("Bad Request", "application/json", ApiError)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -155,6 +155,11 @@ defmodule Pleroma.Web.Router do
|
|||||||
post("/uploader_callback/:upload_path", UploaderController, :callback)
|
post("/uploader_callback/:upload_path", UploaderController, :callback)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scope "/api/v2/pleroma/admin", Pleroma.Web.AdminAPI do
|
||||||
|
pipe_through(:admin_api)
|
||||||
|
get("/config/descriptions", ConfigController, :descriptions2)
|
||||||
|
end
|
||||||
|
|
||||||
scope "/api/v1/pleroma/admin", Pleroma.Web.AdminAPI do
|
scope "/api/v1/pleroma/admin", Pleroma.Web.AdminAPI do
|
||||||
pipe_through(:admin_api)
|
pipe_through(:admin_api)
|
||||||
|
|
||||||
|
@ -100,7 +100,6 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||||||
description: "Some description",
|
description: "Some description",
|
||||||
group: :pleroma,
|
group: :pleroma,
|
||||||
tab: :mrf,
|
tab: :mrf,
|
||||||
tab_label: "MRF",
|
|
||||||
type: :group
|
type: :group
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -1412,8 +1412,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET /api/pleroma/admin/config/descriptions" do
|
describe "config descriptions" do
|
||||||
test "structure", %{conn: conn} do
|
test "api v1 structure", %{conn: conn} do
|
||||||
conn = get(conn, "/api/pleroma/admin/config/descriptions")
|
conn = get(conn, "/api/pleroma/admin/config/descriptions")
|
||||||
|
|
||||||
assert [child | _others] = json_response_and_validate_schema(conn, 200)
|
assert [child | _others] = json_response_and_validate_schema(conn, 200)
|
||||||
@ -1424,6 +1424,22 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||||||
assert child["description"]
|
assert child["description"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "api v2 structure", %{conn: conn} do
|
||||||
|
conn = get(conn, "/api/v2/pleroma/admin/config/descriptions")
|
||||||
|
|
||||||
|
assert %{"tabs" => tabs, "descriptions" => [child | _others]} =
|
||||||
|
json_response_and_validate_schema(conn, 200)
|
||||||
|
|
||||||
|
assert Enum.all?(tabs, fn tab ->
|
||||||
|
Map.has_key?(tab, "tab") and Map.has_key?(tab, "label")
|
||||||
|
end)
|
||||||
|
|
||||||
|
assert child["children"]
|
||||||
|
assert child["key"]
|
||||||
|
assert String.starts_with?(child["group"], ":")
|
||||||
|
assert child["description"]
|
||||||
|
end
|
||||||
|
|
||||||
test "filters by database configuration whitelist", %{conn: conn} do
|
test "filters by database configuration whitelist", %{conn: conn} do
|
||||||
clear_config(:database_config_whitelist, [
|
clear_config(:database_config_whitelist, [
|
||||||
{:pleroma, :instance},
|
{:pleroma, :instance},
|
||||||
|
Loading…
Reference in New Issue
Block a user