From dcae5914d1f7d540e3c20be5988d5e3547a349cd Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Tue, 21 Jan 2020 10:14:48 +0300 Subject: [PATCH] fix for db key --- lib/pleroma/config/config_db.ex | 7 ++++++- .../web/admin_api/admin_api_controller.ex | 2 +- test/web/admin_api/admin_api_controller_test.exs | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/config/config_db.ex b/lib/pleroma/config/config_db.ex index 0091f7a1b..1afe294f4 100644 --- a/lib/pleroma/config/config_db.ex +++ b/lib/pleroma/config/config_db.ex @@ -205,9 +205,14 @@ def delete(params) do {config, sub_keys} when is_list(sub_keys) <- {config, params[:subkeys]}, old_value <- from_binary(config.value), keys <- Enum.map(sub_keys, &do_transform_string(&1)), - new_value <- Keyword.drop(old_value, keys) do + {:partial_remove, config, new_value} when new_value != [] <- + {:partial_remove, config, Keyword.drop(old_value, keys)} do ConfigDB.update(config, %{value: new_value}) else + {:partial_remove, config, []} -> + Repo.delete(config) + {:ok, nil} + {config, nil} -> Repo.delete(config) {:ok, nil} diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex index 30343a9f1..d45b1f7a7 100644 --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@ -831,7 +831,7 @@ def config_show(conn, _params) do Enum.map(values, fn {key, value} -> db = if configs[group][key] do - ConfigDB.get_db_keys(value, key) + ConfigDB.get_db_keys(configs[group][key], key) end db_value = configs[group][key] diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index eec1d0796..509a6f4f4 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -1907,6 +1907,22 @@ test "with settings only in db", %{conn: conn} do assert key2 == config2.key end + test "db is added to settings that are in db", %{conn: conn} do + _config = insert(:config, key: ":instance", value: ConfigDB.to_binary(name: "Some name")) + + %{"configs" => configs} = + conn + |> get("/api/pleroma/admin/config") + |> json_response(200) + + [instance_config] = + Enum.filter(configs, fn %{"group" => group, "key" => key} -> + group == ":pleroma" and key == ":instance" + end) + + assert instance_config["db"] == [":name"] + end + test "merged default setting with db settings", %{conn: conn} do config1 = insert(:config) config2 = insert(:config)