Merge branch 'fix/configdb-migration-with-deprecated' into 'develop'
Deny ConfigDB migration when deprecated settings found Closes #2148 See merge request pleroma/pleroma!3005
This commit is contained in:
commit
6b9bfc9e86
@ -32,7 +32,8 @@ defmodule Mix.Tasks.Pleroma.Config do
|
|||||||
|
|
||||||
@spec migrate_to_db(Path.t() | nil) :: any()
|
@spec migrate_to_db(Path.t() | nil) :: any()
|
||||||
def migrate_to_db(file_path \\ nil) do
|
def migrate_to_db(file_path \\ nil) do
|
||||||
if Pleroma.Config.get([:configurable_from_database]) do
|
with true <- Pleroma.Config.get([:configurable_from_database]),
|
||||||
|
:ok <- Pleroma.Config.DeprecationWarnings.warn() do
|
||||||
config_file =
|
config_file =
|
||||||
if file_path do
|
if file_path do
|
||||||
file_path
|
file_path
|
||||||
@ -46,7 +47,8 @@ defmodule Mix.Tasks.Pleroma.Config do
|
|||||||
|
|
||||||
do_migrate_to_db(config_file)
|
do_migrate_to_db(config_file)
|
||||||
else
|
else
|
||||||
migration_error()
|
:error -> deprecation_error()
|
||||||
|
_ -> migration_error()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -120,6 +122,10 @@ defmodule Mix.Tasks.Pleroma.Config do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp deprecation_error do
|
||||||
|
shell_error("Migration is not allowed until all deprecation warnings have been resolved.")
|
||||||
|
end
|
||||||
|
|
||||||
if Code.ensure_loaded?(Config.Reader) do
|
if Code.ensure_loaded?(Config.Reader) do
|
||||||
defp config_header, do: "import Config\r\n\r\n"
|
defp config_header, do: "import Config\r\n\r\n"
|
||||||
defp read_file(config_file), do: Config.Reader.read_imports!(config_file)
|
defp read_file(config_file), do: Config.Reader.read_imports!(config_file)
|
||||||
|
@ -26,6 +26,10 @@ defmodule Pleroma.Config.DeprecationWarnings do
|
|||||||
!!!DEPRECATION WARNING!!!
|
!!!DEPRECATION WARNING!!!
|
||||||
You are using the old configuration mechanism for the hellthread filter. Please check config.md.
|
You are using the old configuration mechanism for the hellthread filter. Please check config.md.
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
:error
|
||||||
|
else
|
||||||
|
:ok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -47,17 +51,26 @@ defmodule Pleroma.Config.DeprecationWarnings do
|
|||||||
|
|
||||||
config :pleroma, :mrf_user_allowlist, #{inspect(rewritten, pretty: true)}
|
config :pleroma, :mrf_user_allowlist, #{inspect(rewritten, pretty: true)}
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
:error
|
||||||
|
else
|
||||||
|
:ok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def warn do
|
def warn do
|
||||||
check_hellthread_threshold()
|
with :ok <- check_hellthread_threshold(),
|
||||||
mrf_user_allowlist()
|
:ok <- mrf_user_allowlist(),
|
||||||
check_old_mrf_config()
|
:ok <- check_old_mrf_config(),
|
||||||
check_media_proxy_whitelist_config()
|
:ok <- check_media_proxy_whitelist_config(),
|
||||||
check_welcome_message_config()
|
:ok <- check_welcome_message_config(),
|
||||||
check_gun_pool_options()
|
:ok <- check_gun_pool_options(),
|
||||||
check_activity_expiration_config()
|
:ok <- check_activity_expiration_config() do
|
||||||
|
:ok
|
||||||
|
else
|
||||||
|
_ ->
|
||||||
|
:error
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_welcome_message_config do
|
def check_welcome_message_config do
|
||||||
@ -74,6 +87,10 @@ defmodule Pleroma.Config.DeprecationWarnings do
|
|||||||
\n* `config :pleroma, :instance, welcome_user_nickname` is now `config :pleroma, :welcome, :direct_message, :sender_nickname`
|
\n* `config :pleroma, :instance, welcome_user_nickname` is now `config :pleroma, :welcome, :direct_message, :sender_nickname`
|
||||||
\n* `config :pleroma, :instance, welcome_message` is now `config :pleroma, :welcome, :direct_message, :message`
|
\n* `config :pleroma, :instance, welcome_message` is now `config :pleroma, :welcome, :direct_message, :message`
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
:error
|
||||||
|
else
|
||||||
|
:ok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -101,8 +118,11 @@ defmodule Pleroma.Config.DeprecationWarnings do
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if warning != "" do
|
if warning == "" do
|
||||||
|
:ok
|
||||||
|
else
|
||||||
Logger.warn(warning_preface <> warning)
|
Logger.warn(warning_preface <> warning)
|
||||||
|
:error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -115,6 +135,10 @@ defmodule Pleroma.Config.DeprecationWarnings do
|
|||||||
!!!DEPRECATION WARNING!!!
|
!!!DEPRECATION WARNING!!!
|
||||||
Your config is using old format (only domain) for MediaProxy whitelist option. Setting should work for now, but you are advised to change format to scheme with port to prevent possible issues later.
|
Your config is using old format (only domain) for MediaProxy whitelist option. Setting should work for now, but you are advised to change format to scheme with port to prevent possible issues later.
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
:error
|
||||||
|
else
|
||||||
|
:ok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -157,6 +181,9 @@ defmodule Pleroma.Config.DeprecationWarnings do
|
|||||||
Logger.warn(Enum.join([warning_preface | pool_warnings]))
|
Logger.warn(Enum.join([warning_preface | pool_warnings]))
|
||||||
|
|
||||||
Config.put(:pools, updated_config)
|
Config.put(:pools, updated_config)
|
||||||
|
:error
|
||||||
|
else
|
||||||
|
:ok
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -40,6 +40,19 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||||||
on_exit(fn -> Application.put_env(:quack, :level, initial) end)
|
on_exit(fn -> Application.put_env(:quack, :level, initial) end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@tag capture_log: true
|
||||||
|
test "config migration refused when deprecated settings are found" do
|
||||||
|
clear_config([:media_proxy, :whitelist], ["domain_without_scheme.com"])
|
||||||
|
assert Repo.all(ConfigDB) == []
|
||||||
|
|
||||||
|
Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs")
|
||||||
|
|
||||||
|
assert_received {:mix_shell, :error, [message]}
|
||||||
|
|
||||||
|
assert message =~
|
||||||
|
"Migration is not allowed until all deprecation warnings have been resolved."
|
||||||
|
end
|
||||||
|
|
||||||
test "filtered settings are migrated to db" do
|
test "filtered settings are migrated to db" do
|
||||||
assert Repo.all(ConfigDB) == []
|
assert Repo.all(ConfigDB) == []
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user