From c6705144a2758c76943ad7967da412572efcbc2d Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Thu, 27 Jun 2019 04:19:44 +0000 Subject: [PATCH] don't delete config settings on admin update --- docs/api/admin_api.md | 2 +- lib/mix/tasks/pleroma/config.ex | 16 ++++++++++++---- .../web/admin_api/admin_api_controller.ex | 2 +- test/tasks/config_test.exs | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/docs/api/admin_api.md b/docs/api/admin_api.md index c05a353d7..4be0ab0f8 100644 --- a/docs/api/admin_api.md +++ b/docs/api/admin_api.md @@ -579,7 +579,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret ## `/api/pleroma/admin/config` ### Update config settings Module name can be passed as string, which starts with `Pleroma`, e.g. `"Pleroma.Upload"`. -Atom or boolean value can be passed with `:` in the beginning, e.g. `":true"`, `":upload"`. +Atom or boolean value can be passed with `:` in the beginning, e.g. `":true"`, `":upload"`. For keys it is not needed. Integer with `i:`, e.g. `"i:150"`. Tuple with more than 2 values with `{"tuple": ["first_val", Pleroma.Module, []]}`. `{"tuple": ["some_string", "Pleroma.Some.Module", []]}` will be converted to `{"some_string", Pleroma.Some.Module, []}`. diff --git a/lib/mix/tasks/pleroma/config.ex b/lib/mix/tasks/pleroma/config.ex index 4ed2c9789..faa605d9b 100644 --- a/lib/mix/tasks/pleroma/config.ex +++ b/lib/mix/tasks/pleroma/config.ex @@ -36,9 +36,11 @@ def run(["migrate_to_db"]) do end end - def run(["migrate_from_db", env]) do + def run(["migrate_from_db", env, delete?]) do start_pleroma() + delete? = if delete? == "true", do: true, else: false + if Pleroma.Config.get([:instance, :dynamic_configuration]) do config_path = "config/#{env}.exported_from_db.secret.exs" @@ -47,7 +49,11 @@ def run(["migrate_from_db", env]) do Repo.all(Config) |> Enum.each(fn config -> - mark = if String.starts_with?(config.key, "Pleroma."), do: ",", else: ":" + mark = + if String.starts_with?(config.key, "Pleroma.") or + String.starts_with?(config.key, "Ueberauth"), + do: ",", + else: ":" IO.write( file, @@ -56,8 +62,10 @@ def run(["migrate_from_db", env]) do }\r\n" ) - {:ok, _} = Repo.delete(config) - Mix.shell().info("#{config.key} deleted from DB.") + if delete? do + {:ok, _} = Repo.delete(config) + Mix.shell().info("#{config.key} deleted from DB.") + end end) File.close(file) diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex index 953a22ea0..498beb56a 100644 --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@ -388,7 +388,7 @@ def config_update(conn, %{"configs" => configs}) do |> Enum.reject(&is_nil(&1)) Pleroma.Config.TransferTask.load_and_update_env() - Mix.Tasks.Pleroma.Config.run(["migrate_from_db", Pleroma.Config.get(:env)]) + Mix.Tasks.Pleroma.Config.run(["migrate_from_db", Pleroma.Config.get(:env), "false"]) updated else [] diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs index 9c9a31bf4..83a363356 100644 --- a/test/tasks/config_test.exs +++ b/test/tasks/config_test.exs @@ -51,7 +51,7 @@ test "settings are migrated to file and deleted from db", %{temp_file: temp_file value: [key: "valu2", key2: [Pleroma.Repo]] }) - Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "temp"]) + Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "temp", "true"]) assert Repo.all(Config) == [] assert File.exists?(temp_file)