fix for int and modules
authorAlex S <alex.strizhakov@gmail.com>
Sat, 22 Jun 2019 06:01:30 +0000 (09:01 +0300)
committerAlex S <alex.strizhakov@gmail.com>
Sat, 22 Jun 2019 06:01:30 +0000 (09:01 +0300)
lib/pleroma/web/admin_api/config.ex
test/web/admin_api/admin_api_controller_test.exs

index b7072f050cfcdb5fa17a80e67bb8f28bb7b23dd1..ddcfc87d5cbaabb716dc86b64e2bc2fdba958f89 100644 (file)
@@ -77,8 +77,15 @@ defmodule Pleroma.Web.AdminAPI.Config do
   defp do_convert({k, v} = value) when is_tuple(value),
     do: %{k => do_convert(v)}
 
-  defp do_convert(value) when is_binary(value) or is_atom(value) or is_map(value),
-    do: value
+  defp do_convert(value) when is_binary(value) or is_map(value) or is_number(value), do: value
+
+  defp do_convert(value) when is_atom(value) do
+    string = to_string(value)
+
+    if String.starts_with?(string, "Elixir."),
+      do: String.trim_leading(string, "Elixir."),
+      else: value
+  end
 
   @spec transform(any()) :: binary()
   def transform(entity) when is_map(entity) do
index 2a591264597061644a23df51ab11da43cc1e892a..17a872b217f77d2d3c58ad5dcc2f61daea0f03a4 100644 (file)
@@ -1463,5 +1463,34 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
       assert Application.get_env(:pleroma, :keyaa1) == "another_value"
       refute Application.get_env(:pleroma, :keyaa2)
     end
+
+    test "common config example", %{conn: conn} do
+      conn =
+        post(conn, "/api/pleroma/admin/config", %{
+          configs: [
+            %{
+              "key" => "Pleroma.Captcha",
+              "value" => %{
+                "enabled" => ":false",
+                "method" => "Pleroma.Captcha.Kocaptcha",
+                "seconds_valid" => "i:60"
+              }
+            }
+          ]
+        })
+
+      assert json_response(conn, 200) == %{
+               "configs" => [
+                 %{
+                   "key" => "Pleroma.Captcha",
+                   "value" => [
+                     %{"enabled" => false},
+                     %{"method" => "Pleroma.Captcha.Kocaptcha"},
+                     %{"seconds_valid" => 60}
+                   ]
+                 }
+               ]
+             }
+    end
   end
 end