Compare commits

...

24 Commits

Author SHA1 Message Date
Angelina Filippova
73d552d5eb Update settings types that require confirmation when updated 2021-07-12 01:34:31 +03:00
Angelina Filippova
9d56f2717c Update types in mrf config description 2021-07-10 19:08:16 +03:00
Angelina Filippova
fe263d0d00 Make Pleroma.Upload.Filter.Mogrify suggestions strings 2021-07-10 15:28:09 +03:00
Angelina Filippova
07ffce0342 Update :auth setting type, add placeholders 2021-05-19 01:56:22 +03:00
Angelina Filippova
7a91877ee4 Update ip_whitelist type 2021-05-18 20:15:06 +03:00
Angelina Filippova
9411f90398 Remove unused suggestions 2021-05-04 19:08:05 +03:00
Angelina Filippova
921d874187 Update :rate_limit types, add placeholders 2021-05-02 16:06:14 +03:00
Angelina Filippova
7c6de228dd Delete unused suggestions 2021-04-13 02:31:28 +03:00
Angelina Filippova
db699f358f Update type of settings whose values should be reversed 2021-04-06 02:46:54 +03:00
Angelina Filippova
f565854b51 Change [:list, :string] and [:list, :atom] types to :multiple_select 2021-03-30 21:28:55 +03:00
Angelina Filippova
05ef2282d5 Change :crontab type to [:keyword, :string] 2021-03-30 00:26:09 +03:00
Angelina Filippova
567c93a26d Update type of :queues, remove unused suggestions 2021-03-29 22:26:34 +03:00
Angelina Filippova
481f63a9a7 Add textarea type 2021-03-28 01:58:36 +03:00
Angelina Filippova
5835f6d0a4 Add map_keys key to :mascots setting 2021-03-27 00:13:35 +03:00
Angelina Filippova
c425f87717 Update type of :ip setting in group Gopher 2021-03-27 00:12:17 +03:00
Angelina Filippova
67f7822b17 Set type :select to settings that are rendered as single selects 2021-03-27 00:11:04 +03:00
Angelina Filippova
68d3d04274 Update types of settings with type image, remove duplicated suggestions 2021-03-26 00:00:32 +03:00
Angelina Filippova
3f9983ee93 Update types of settings groups that don't have keys 2021-03-24 23:07:29 +03:00
Angelina Filippova
63e412ceb5 Update suggestions for settings with type atom 2021-03-23 01:28:46 +03:00
Angelina Filippova
36d93d691d Update types for settings that are selects and multiple selects with reduced labels 2021-03-22 21:26:48 +03:00
Alexander Strizhakov
957a51058b
adding path field to description tabs 2021-03-04 13:23:48 +03:00
Alexander Strizhakov
f20c1afe46
config descriptions v2 endpoint with tabs field 2021-03-04 13:23:45 +03:00
Alexander Strizhakov
f9d9987df8
added tabs setting to the description.exs 2021-03-04 13:22:30 +03:00
Alexander Strizhakov
8827d7a74f
adding tab & tab_label fields to the descriptions
for top level groups
2021-03-04 13:22:30 +03:00
16 changed files with 418 additions and 261 deletions

View File

@ -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.
### 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)
## [2.3.0] - 2020-03-01

File diff suppressed because it is too large Load Diff

View File

@ -1093,7 +1093,8 @@ config :quack,
## `GET /api/v1/pleroma/admin/config/descriptions`
### Get JSON with config descriptions.
### Get JSON with config descriptions
Loads json generated from `config/descriptions.exs`.
- Params: none
@ -1105,6 +1106,8 @@ Loads json generated from `config/descriptions.exs`.
"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`
@ -1124,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", "path": "activity-pub"}],
"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 moderation log

View File

@ -7,7 +7,9 @@ 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_tabs @raw_config[:pleroma][:tabs]
@term __MODULE__.Compiled
@tabs __MODULE__.CompiledTabs
@spec compile :: :ok
def compile do
@ -16,13 +18,17 @@ defmodule Pleroma.Docs.JSON do
|> Enum.reduce(@raw_descriptions, fn description, acc -> [description | acc] end)
:persistent_term.put(@term, Pleroma.Docs.Generator.convert_to_strings(descriptions))
:persistent_term.put(@tabs, @raw_tabs)
end
@spec compiled_descriptions :: Map.t()
@spec compiled_descriptions :: [map()]
def compiled_descriptions do
:persistent_term.get(@term)
end
@spec compiled_tabs() :: [map()]
def compiled_tabs, do: :persistent_term.get(@tabs)
@spec process(keyword()) :: {:ok, String.t()}
def process(descriptions) do
with path <- "docs/generated_config.json",

View File

@ -18,7 +18,7 @@ defmodule Pleroma.Web.ActivityPub.MRF do
children: [
%{
key: :policies,
type: [:module, {:list, :module}],
type: {:multiple_select, :reduced_labels},
description:
"A list of MRF policies enabled. Module names are shortened (removed leading `Pleroma.Web.ActivityPub.MRF.` part), but on adding custom module you need to use full name.",
suggestions: {:list_behaviour_implementations, Pleroma.Web.ActivityPub.MRF}
@ -33,7 +33,7 @@ defmodule Pleroma.Web.ActivityPub.MRF do
%{
key: :transparency_exclusions,
label: "MRF transparency exclusions",
type: {:list, :string},
type: :multiple_select,
description:
"Exclude specific instance names from MRF transparency. The use of the exclusions feature will be disclosed in nodeinfo as a boolean value.",
suggestions: [

View File

@ -138,7 +138,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do
children: [
%{
key: :reject,
type: {:list, :string},
type: :multiple_select,
description: """
A list of patterns which result in message being rejected.
@ -148,7 +148,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do
},
%{
key: :federated_timeline_removal,
type: {:list, :string},
type: :multiple_select,
description: """
A list of patterns which result in message being removed from federated timelines (a.k.a unlisted).
@ -158,7 +158,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicy do
},
%{
key: :replace,
type: {:list, :tuple},
type: {:keyword, :string},
description: """
**Pattern**: a string or [Regex](https://hexdocs.pm/elixir/Regex.html) in the format of `~r/PATTERN/`.

View File

@ -36,7 +36,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicy do
children: [
%{
key: :actors,
type: {:list, :string},
type: :multiple_select,
description: "A list of actors for which any post mentioning them will be dropped",
suggestions: ["actor1", "actor2"]
}

View File

@ -36,7 +36,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkup do
children: [
%{
key: :scrub_policy,
type: :module,
type: :select,
suggestions: [Pleroma.HTML.Scrubber.Default]
}
]

View File

@ -124,7 +124,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy do
},
%{
key: :actions,
type: {:list, :atom},
type: :multiple_select,
description:
"A list of actions to apply to the post. `:delist` removes the post from public timelines; " <>
"`:strip_followers` removes followers from the ActivityPub recipient list ensuring they won't be delivered to home timelines; " <>

View File

@ -255,63 +255,63 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
children: [
%{
key: :media_removal,
type: {:list, :string},
type: :multiple_select,
description: "List of instances to strip media attachments from",
suggestions: ["example.com", "*.example.com"]
},
%{
key: :media_nsfw,
label: "Media NSFW",
type: {:list, :string},
type: :multiple_select,
description: "List of instances to tag all media as NSFW (sensitive) from",
suggestions: ["example.com", "*.example.com"]
},
%{
key: :federated_timeline_removal,
type: {:list, :string},
type: :multiple_select,
description:
"List of instances to remove from the Federated (aka The Whole Known Network) Timeline",
suggestions: ["example.com", "*.example.com"]
},
%{
key: :reject,
type: {:list, :string},
type: :multiple_select,
description: "List of instances to reject activities from (except deletes)",
suggestions: ["example.com", "*.example.com"]
},
%{
key: :accept,
type: {:list, :string},
type: :multiple_select,
description: "List of instances to only accept activities from (except deletes)",
suggestions: ["example.com", "*.example.com"]
},
%{
key: :followers_only,
type: {:list, :string},
type: :multiple_select,
description: "Force posts from the given instances to be visible by followers only",
suggestions: ["example.com", "*.example.com"]
},
%{
key: :report_removal,
type: {:list, :string},
type: :multiple_select,
description: "List of instances to reject reports from",
suggestions: ["example.com", "*.example.com"]
},
%{
key: :avatar_removal,
type: {:list, :string},
type: :multiple_select,
description: "List of instances to strip avatars from",
suggestions: ["example.com", "*.example.com"]
},
%{
key: :banner_removal,
type: {:list, :string},
type: :multiple_select,
description: "List of instances to strip banners from",
suggestions: ["example.com", "*.example.com"]
},
%{
key: :reject_deletes,
type: {:list, :string},
type: :multiple_select,
description: "List of instances to reject deletions from",
suggestions: ["example.com", "*.example.com"]
}

View File

@ -52,7 +52,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SubchainPolicy do
children: [
%{
key: :match_actor,
type: {:map, {:list, :string}},
type: {:map, :multiple_select},
description: "Matches a series of regular expressions against the actor field",
suggestions: [
%{

View File

@ -51,14 +51,14 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicy do
children: [
%{
key: :accept,
type: {:list, :string},
type: :multiple_select,
description:
"A list of ActivityStreams terms to accept. If empty, all supported messages are accepted.",
suggestions: ["Create", "Follow", "Mention", "Announce", "Like"]
},
%{
key: :reject,
type: {:list, :string},
type: :multiple_select,
description:
"A list of ActivityStreams terms to reject. If empty, no messages are rejected.",
suggestions: ["Create", "Follow", "Mention", "Announce", "Like"]

View File

@ -15,17 +15,28 @@ defmodule Pleroma.Web.AdminAPI.ConfigController do
plug(
OAuthScopesPlug,
%{scopes: ["admin:read"]}
when action in [:show, :descriptions]
when action in [:show, :descriptions, :descriptions2]
)
action_fallback(Pleroma.Web.AdminAPI.FallbackController)
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.Admin.ConfigOperation
@doc """
GET /api/v1/pleroma/admin/config/descriptions
"""
def descriptions(conn, _params) do
descriptions = Enum.filter(Pleroma.Docs.JSON.compiled_descriptions(), &whitelisted_config?/1)
json(conn, whitelisted_descriptions())
end
json(conn, descriptions)
@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
@ -126,6 +137,10 @@ defmodule Pleroma.Web.AdminAPI.ConfigController do
end
end
defp whitelisted_descriptions do
Enum.filter(Pleroma.Docs.JSON.compiled_descriptions(), &whitelisted_config?/1)
end
defp whitelisted_config?(group, key) do
if whitelisted_configs = Config.get(:database_config_whitelist) do
Enum.any?(whitelisted_configs, fn

View File

@ -78,13 +78,53 @@ defmodule Pleroma.Web.ApiSpec.Admin.ConfigOperation do
parameters: admin_api_params(),
responses: %{
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{
type: :object,
properties: %{
tabs: %Schema{
type: :array,
items: %Schema{
type: :object,
properties: %{
tab: %Schema{type: :string},
label: %Schema{type: :string},
path: %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{
@ -101,9 +141,6 @@ defmodule Pleroma.Web.ApiSpec.Admin.ConfigOperation do
}
}
}
}),
400 => Operation.response("Bad Request", "application/json", ApiError)
}
}
end

View File

@ -155,6 +155,11 @@ defmodule Pleroma.Web.Router do
post("/uploader_callback/:upload_path", UploaderController, :callback)
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
pipe_through(:admin_api)

View File

@ -1412,8 +1412,8 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
end
end
describe "GET /api/pleroma/admin/config/descriptions" do
test "structure", %{conn: conn} do
describe "config descriptions" do
test "api v1 structure", %{conn: conn} do
conn = get(conn, "/api/pleroma/admin/config/descriptions")
assert [child | _others] = json_response_and_validate_schema(conn, 200)
@ -1424,6 +1424,23 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
assert child["description"]
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") and
Map.has_key?(tab, "path")
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
clear_config(:database_config_whitelist, [
{:pleroma, :instance},