fix for db key
authorAlexander Strizhakov <alex.strizhakov@gmail.com>
Tue, 21 Jan 2020 07:14:48 +0000 (10:14 +0300)
committerAlexander Strizhakov <alex.strizhakov@gmail.com>
Tue, 21 Jan 2020 07:14:48 +0000 (10:14 +0300)
lib/pleroma/config/config_db.ex
lib/pleroma/web/admin_api/admin_api_controller.ex
test/web/admin_api/admin_api_controller_test.exs

index 0091f7a1bff2abef2af459183db07bb9ec7fed59..1afe294f46bfbefe43c2a29ff41a2d59e677b6f3 100644 (file)
@@ -205,9 +205,14 @@ defmodule Pleroma.ConfigDB 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}
index 30343a9f1e9732b8b8fe0dfe3b1760ccae3fd04c..d45b1f7a70e21de3d4ce2cc969ad1ea43c4f3acf 100644 (file)
@@ -831,7 +831,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController 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]
index eec1d0796cb4c6defe4e315307d14597c3dd1815..509a6f4f4090d9e3392a2eff3b45ebd3f8172bf1 100644 (file)
@@ -1907,6 +1907,22 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest 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)