remote_post_retention_days: 90,
skip_thread_containment: true,
limit_to_local_content: :unauthenticated,
- dynamic_configuration: false,
user_bio_length: 5000,
user_name_length: 100,
max_account_fields: 10,
config :pleroma, :modules, runtime_dir: "instance/modules"
+config :pleroma, configurable_from_database: false
+
config :swarm, node_blacklist: [~r/myhtml_.*$/]
# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
false
]
},
- %{
- key: :dynamic_configuration,
- type: :boolean,
- description:
- "Allow transferring configuration to DB with the subsequent customization from Admin api. Defaults to `false`"
- },
%{
key: :max_account_fields,
type: :integer,
description: "A path to custom Elixir modules (such as MRF policies)."
}
]
+ },
+ %{
+ group: :pleroma,
+ type: :group,
+ description: "Allow instance configuration from database.",
+ children: [
+ %{
+ key: :configurable_from_database,
+ type: :boolean,
+ description:
+ "Allow transferring configuration to DB with the subsequent customization from Admin api. Defaults to `false`"
+ }
+ ]
}
]
### Get saved config settings
-**Only works when `:dynamic_configuration` is `true`.**
+**Only works when configuration from database is enabled.**
- Params: none
- Response:
### Update config settings
-**Only works when `:dynamic_configuration` is `true`.**
+**Only works when configuration from database is enabled.**
Some modifications are necessary to save the config settings correctly:
# Configuring instance
-You can configure your instance from admin interface. You need account with admin rights and little change in config file, which will allow settings dynamic configuration from database.
+You can configure your instance from admin interface. You need account with admin rights and little change in config file, which will allow settings configuration from database.
```elixir
-config :pleroma, :instance,
- dynamic_configuration: true
+config :pleroma, configurable_from_database: true
```
## How it works
```
*If you don't want to backup settings, you can skip step with `cp` command.*
-3. Set dynamic configuration to `false`.
+3. Set configurable_from_database to `false`.
```elixir
-config :pleroma, :instance,
- dynamic_configuration: false
+config :pleroma, configurable_from_database: false
```
4. Restart pleroma instance
```bash
* `account_field_value_length`: An account field value maximum length (default: `2048`).
* `external_user_synchronization`: Enabling following/followers counters synchronization for external users.
-!!! danger
- This is a Work In Progress, not usable just yet
-
-* `dynamic_configuration`: Allow transferring configuration to DB with the subsequent customization from Admin api.
-
## Federation
### MRF policies
## Custom Runtime Modules (`:modules`)
* `runtime_dir`: A path to custom Elixir modules (such as MRF policies).
+
+
+## :configurable_from_database
+Enable/disable configuration from database.
def run(["migrate_to_db"]) do
start_pleroma()
- if Pleroma.Config.get([:instance, :dynamic_configuration]) do
+ if Pleroma.Config.get([:configurable_from_database]) do
Enum.each(@groups, &load_and_create(&1))
else
Mix.shell().info(
aliases: [d: :delete_from_db]
)
- with {:active?, true} <- {:active?, Pleroma.Config.get([:instance, :dynamic_configuration])},
+ with {:active?, true} <-
+ {:active?, Pleroma.Config.get([:configurable_from_database])},
env_path when is_binary(env_path) <- opts[:env],
config_path <- "config/#{env_path}.exported_from_db.secret.exs",
{:ok, file} <- File.open(config_path, [:write, :utf8]) do
end
def load_and_update_env do
- with true <- Pleroma.Config.get([:instance, :dynamic_configuration]),
+ with true <- Pleroma.Config.get([:configurable_from_database]),
true <- Ecto.Adapters.SQL.table_exists?(Repo, "config"),
started_applications <- Application.started_applications() do
# We need to restart applications for loaded settings take effect
end
def migrate_from_db(conn, _params) do
- with :ok <- check_dynamic_configuration(conn) do
+ with :ok <- configurable_from_database(conn) do
Mix.Tasks.Pleroma.Config.run([
"migrate_from_db",
"--env",
end
def config_show(conn, _params) do
- with :ok <- check_dynamic_configuration(conn) do
+ with :ok <- configurable_from_database(conn) do
configs = Pleroma.Repo.all(Config)
if configs == [] do
end
def config_update(conn, %{"configs" => configs}) do
- with :ok <- check_dynamic_configuration(conn) do
+ with :ok <- configurable_from_database(conn) do
updated =
Enum.map(configs, fn
%{"group" => group, "key" => key, "delete" => true} = params ->
end
end
- defp check_dynamic_configuration(conn) do
- if Pleroma.Config.get([:instance, :dynamic_configuration]) do
+ defp configurable_from_database(conn) do
+ if Pleroma.Config.get([:configurable_from_database]) do
:ok
else
errors(conn, {:error, "To use this endpoint you need to enable dynamic configuration."})
email: "<%= email %>",
notify_email: "<%= notify_email %>",
limit: 5000,
- registrations_open: true,
- dynamic_configuration: <%= db_configurable? %>
+ registrations_open: true
config :pleroma, :media_proxy,
enabled: false,
# host: "s3.wasabisys.com"
config :joken, default_signer: "<%= jwt_secret %>"
+
+config :pleroma, configurable_from_database: <%= db_configurable? %>
alias Pleroma.Web.AdminAPI.Config
- clear_config([:instance, :dynamic_configuration]) do
- Pleroma.Config.put([:instance, :dynamic_configuration], true)
+ clear_config([:configurable_from_database]) do
+ Pleroma.Config.put([:configurable_from_database], true)
end
test "transfer config values from db to env" do
:ok
end
- clear_config_all([:instance, :dynamic_configuration]) do
- Pleroma.Config.put([:instance, :dynamic_configuration], true)
+ clear_config_all([:configurable_from_database]) do
+ Pleroma.Config.put([:configurable_from_database], true)
end
test "settings are migrated to db" do
remote_post_retention_days: 90,
skip_thread_containment: true,
limit_to_local_content: :unauthenticated,
- dynamic_configuration: false,
user_bio_length: 5000,
user_name_length: 100,
max_account_fields: 10,
{:ok, file} = File.read(temp_file)
assert file ==
- "use Mix.Config\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n allow_relay: true,\n rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n mrf_transparency: true,\n mrf_transparency_exclusions: [],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n no_attachment_links: true,\n welcome_user_nickname: nil,\n welcome_message: nil,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n dynamic_configuration: false,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n"
+ "use Mix.Config\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n allow_relay: true,\n rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n mrf_transparency: true,\n mrf_transparency_exclusions: [],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n no_attachment_links: true,\n welcome_user_nickname: nil,\n welcome_message: nil,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n"
end
end
end
assert generated_config =~ "database: \"dbname\""
assert generated_config =~ "username: \"dbuser\""
assert generated_config =~ "password: \"dbpass\""
- assert generated_config =~ "dynamic_configuration: true"
+ assert generated_config =~ "configurable_from_database: true"
assert generated_config =~ "http: [ip: {127, 0, 0, 1}, port: 4000]"
assert File.read!(tmp_path() <> "setup.psql") == generated_setup_psql()
end
assert json_response(conn, :no_content)
- token_record = List.last(Pleroma.Repo.all(Pleroma.UserInviteToken))
+ token_record = List.last(Repo.all(Pleroma.UserInviteToken))
assert token_record
refute token_record.used
end
describe "GET /api/pleroma/admin/config" do
- clear_config([:instance, :dynamic_configuration]) do
- Pleroma.Config.put([:instance, :dynamic_configuration], true)
+ clear_config([:configurable_from_database]) do
+ Pleroma.Config.put([:configurable_from_database], true)
end
setup %{conn: conn} do
end
test "when dynamic configuration is off", %{conn: conn} do
- initial = Pleroma.Config.get([:instance, :dynamic_configuration])
- Pleroma.Config.put([:instance, :dynamic_configuration], false)
- on_exit(fn -> Pleroma.Config.put([:instance, :dynamic_configuration], initial) end)
+ initial = Pleroma.Config.get([:configurable_from_database])
+ Pleroma.Config.put([:configurable_from_database], false)
+ on_exit(fn -> Pleroma.Config.put([:configurable_from_database], initial) end)
conn = get(conn, "/api/pleroma/admin/config")
assert json_response(conn, 400) ==
%{conn: assign(conn, :user, admin)}
end
- clear_config([:instance, :dynamic_configuration]) do
- Pleroma.Config.put([:instance, :dynamic_configuration], true)
+ clear_config([:configurable_from_database]) do
+ Pleroma.Config.put([:configurable_from_database], true)
end
@tag capture_log: true
%{conn: assign(conn, :user, admin)}
end
- clear_config([:instance, :dynamic_configuration]) do
- Pleroma.Config.put([:instance, :dynamic_configuration], true)
+ clear_config([:configurable_from_database]) do
+ Pleroma.Config.put([:configurable_from_database], true)
end
clear_config([:feed, :post_title]) do
test "transfer settings to DB and to file", %{conn: conn} do
on_exit(fn -> :ok = File.rm("config/test.exported_from_db.secret.exs") end)
- assert Pleroma.Repo.all(Pleroma.Web.AdminAPI.Config) == []
+ assert Repo.all(Pleroma.Web.AdminAPI.Config) == []
Mix.Tasks.Pleroma.Config.run(["migrate_to_db"])
- assert Pleroma.Repo.all(Pleroma.Web.AdminAPI.Config) > 0
+ assert Repo.aggregate(Pleroma.Web.AdminAPI.Config, :count, :id) > 0
conn = get(conn, "/api/pleroma/admin/config/migrate_from_db")
assert json_response(conn, 200) == %{}
- assert Pleroma.Repo.all(Pleroma.Web.AdminAPI.Config) == []
+ assert Repo.all(Pleroma.Web.AdminAPI.Config) == []
end
test "returns error if dynamic configuration is off", %{conn: conn} do
- initial = Pleroma.Config.get([:instance, :dynamic_configuration])
- on_exit(fn -> Pleroma.Config.put([:instance, :dynamic_configuration], initial) end)
- Pleroma.Config.put([:instance, :dynamic_configuration], false)
+ initial = Pleroma.Config.get([:configurable_from_database])
+ on_exit(fn -> Pleroma.Config.put([:configurable_from_database], initial) end)
+ Pleroma.Config.put([:configurable_from_database], false)
conn = get(conn, "/api/pleroma/admin/config/migrate_from_db")