From c85aa6e87f8887ad532580ec3f84811abace05f2 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Wed, 5 Feb 2020 17:06:01 +0300 Subject: [PATCH 1/3] removing confusing error --- docs/API/admin_api.md | 1 - .../web/admin_api/admin_api_controller.ex | 72 ++++++++----------- .../admin_api/admin_api_controller_test.exs | 7 -- 3 files changed, 29 insertions(+), 51 deletions(-) diff --git a/docs/API/admin_api.md b/docs/API/admin_api.md index e445583cb..fb6dfcb08 100644 --- a/docs/API/admin_api.md +++ b/docs/API/admin_api.md @@ -689,7 +689,6 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret - Response: - On failure: - 400 Bad Request `"To use this endpoint you need to enable configuration from database."` - - 400 Bad Request `"To use configuration from database migrate your settings to database."` ```json { diff --git a/lib/pleroma/web/admin_api/admin_api_controller.ex b/lib/pleroma/web/admin_api/admin_api_controller.ex index 293f1befc..c95cd182d 100644 --- a/lib/pleroma/web/admin_api/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/admin_api_controller.ex @@ -797,16 +797,9 @@ def config_show(conn, %{"only_db" => true}) do with :ok <- configurable_from_database(conn) do configs = Pleroma.Repo.all(ConfigDB) - if configs == [] do - errors( - conn, - {:error, "To use configuration from database migrate your settings to database."} - ) - else - conn - |> put_view(ConfigView) - |> render("index.json", %{configs: configs}) - end + conn + |> put_view(ConfigView) + |> render("index.json", %{configs: configs}) end end @@ -814,45 +807,38 @@ def config_show(conn, _params) do with :ok <- configurable_from_database(conn) do configs = ConfigDB.get_all_as_keyword() - if configs == [] do - errors( - conn, - {:error, "To use configuration from database migrate your settings to database."} - ) - else - merged = - Pleroma.Config.Holder.config() - |> ConfigDB.merge(configs) - |> Enum.map(fn {group, values} -> - Enum.map(values, fn {key, value} -> - db = - if configs[group][key] do - ConfigDB.get_db_keys(configs[group][key], key) - end + merged = + Pleroma.Config.Holder.config() + |> ConfigDB.merge(configs) + |> Enum.map(fn {group, values} -> + Enum.map(values, fn {key, value} -> + db = + if configs[group][key] do + ConfigDB.get_db_keys(configs[group][key], key) + end - db_value = configs[group][key] + db_value = configs[group][key] - merged_value = - if !is_nil(db_value) and Keyword.keyword?(db_value) and - ConfigDB.sub_key_full_update?(group, key, Keyword.keys(db_value)) do - ConfigDB.merge_group(group, key, value, db_value) - else - value - end + merged_value = + if !is_nil(db_value) and Keyword.keyword?(db_value) and + ConfigDB.sub_key_full_update?(group, key, Keyword.keys(db_value)) do + ConfigDB.merge_group(group, key, value, db_value) + else + value + end - setting = %{ - group: ConfigDB.convert(group), - key: ConfigDB.convert(key), - value: ConfigDB.convert(merged_value) - } + setting = %{ + group: ConfigDB.convert(group), + key: ConfigDB.convert(key), + value: ConfigDB.convert(merged_value) + } - if db, do: Map.put(setting, :db, db), else: setting - end) + if db, do: Map.put(setting, :db, db), else: setting end) - |> List.flatten() + end) + |> List.flatten() - json(conn, %{configs: merged}) - end + json(conn, %{configs: merged}) end end diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index 87f1366a4..5fbdf96f6 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -1899,13 +1899,6 @@ test "when configuration from database is off", %{conn: conn} do "To use this endpoint you need to enable configuration from database." end - test "without any settings in db", %{conn: conn} do - conn = get(conn, "/api/pleroma/admin/config") - - assert json_response(conn, 400) == - "To use configuration from database migrate your settings to database." - end - test "with settings only in db", %{conn: conn} do config1 = insert(:config) config2 = insert(:config) From bdf0a87be95f311b094273d67244914173ee9dac Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Wed, 5 Feb 2020 19:05:20 +0300 Subject: [PATCH 2/3] dropdown type --- config/description.exs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/config/description.exs b/config/description.exs index a4d1a74a7..0ac1f4d8d 100644 --- a/config/description.exs +++ b/config/description.exs @@ -871,7 +871,7 @@ }, %{ key: :limit_to_local_content, - type: [:atom, false], + type: {:dropdown, :atom}, description: "Limit unauthenticated users to search for local statutes and users only. Default: `:unauthenticated`.", suggestions: [ @@ -942,7 +942,7 @@ children: [ %{ key: :level, - type: :atom, + type: {:dropdown, :atom}, description: "Log level", suggestions: [:debug, :info, :warn, :error] }, @@ -974,7 +974,7 @@ children: [ %{ key: :level, - type: :atom, + type: {:dropdown, :atom}, description: "Log level", suggestions: [:debug, :info, :warn, :error] }, @@ -998,7 +998,7 @@ children: [ %{ key: :level, - type: :atom, + type: {:dropdown, :atom}, description: "Log level", suggestions: [:debug, :info, :warn, :error] }, @@ -1969,7 +1969,7 @@ }, %{ key: :verbose, - type: [:atom, false], + type: {:dropdown, :atom}, description: "Logs verbose mode", suggestions: [false, :error, :warn, :info, :debug] }, From 7a2e153a8dec4337f16aeacab534f26f720cb5eb Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Thu, 6 Feb 2020 13:15:23 +0300 Subject: [PATCH 3/3] description change --- config/description.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/description.exs b/config/description.exs index 0ac1f4d8d..6b912a07e 100644 --- a/config/description.exs +++ b/config/description.exs @@ -2178,7 +2178,7 @@ %{ key: :new_window, type: :boolean, - description: "Set to `false` to remove target='_blank' attribute" + description: "Link urls will open in new window/tab" }, %{ key: :truncate,