returning partial chain
authorAlexander Strizhakov <alex.strizhakov@gmail.com>
Fri, 15 May 2020 13:16:02 +0000 (16:16 +0300)
committerAlexander Strizhakov <alex.strizhakov@gmail.com>
Fri, 15 May 2020 13:16:02 +0000 (16:16 +0300)
lib/pleroma/config/config_db.ex
test/config/config_db_test.exs
test/web/admin_api/admin_api_controller_test.exs

index 4097ee5b75cbe7ea6a58a7f00a1e36714f47d952..2b43d4c365f91586b5e0a9b569958fce83048a74 100644 (file)
@@ -278,6 +278,8 @@ defmodule Pleroma.ConfigDB do
     }
   end
 
+  defp do_convert({:partial_chain, entity}), do: %{"tuple" => [":partial_chain", inspect(entity)]}
+
   defp do_convert(entity) when is_tuple(entity) do
     value =
       entity
@@ -321,6 +323,15 @@ defmodule Pleroma.ConfigDB do
     {:proxy_url, {do_transform_string(type), parse_host(host), port}}
   end
 
+  defp do_transform(%{"tuple" => [":partial_chain", entity]}) do
+    {partial_chain, []} =
+      entity
+      |> String.replace(~r/[^\w|^{:,[|^,|^[|^\]^}|^\/|^\.|^"]^\s/, "")
+      |> Code.eval_string()
+
+    {:partial_chain, partial_chain}
+  end
+
   defp do_transform(%{"tuple" => entity}) do
     Enum.reduce(entity, {}, fn val, acc -> Tuple.append(acc, do_transform(val)) end)
   end
index a8e94736597a19cf3d05290a80d09278fec66778..336de735900b12806295cfb2810ae855e97af477 100644 (file)
@@ -476,6 +476,14 @@ defmodule Pleroma.ConfigDBTest do
       assert ConfigDB.from_binary(binary) == [key: "value"]
     end
 
+    test "keyword with partial_chain key" do
+      binary =
+        ConfigDB.transform([%{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]}])
+
+      assert binary == :erlang.term_to_binary(partial_chain: &:hackney_connect.partial_chain/1)
+      assert ConfigDB.from_binary(binary) == [partial_chain: &:hackney_connect.partial_chain/1]
+    end
+
     test "keyword" do
       binary =
         ConfigDB.transform([
index 9b71207124863f5b661bdcb856f0364435736ddf..370d876d0f1a2c564d067ca78654ae5e4976e29a 100644 (file)
@@ -2509,6 +2509,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                 %{"tuple" => [":seconds_valid", 60]},
                 %{"tuple" => [":path", ""]},
                 %{"tuple" => [":key1", nil]},
+                %{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]},
                 %{"tuple" => [":regex1", "~r/https:\/\/example.com/"]},
                 %{"tuple" => [":regex2", "~r/https:\/\/example.com/u"]},
                 %{"tuple" => [":regex3", "~r/https:\/\/example.com/i"]},
@@ -2532,6 +2533,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                      %{"tuple" => [":seconds_valid", 60]},
                      %{"tuple" => [":path", ""]},
                      %{"tuple" => [":key1", nil]},
+                     %{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]},
                      %{"tuple" => [":regex1", "~r/https:\\/\\/example.com/"]},
                      %{"tuple" => [":regex2", "~r/https:\\/\\/example.com/u"]},
                      %{"tuple" => [":regex3", "~r/https:\\/\\/example.com/i"]},
@@ -2544,6 +2546,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                      ":seconds_valid",
                      ":path",
                      ":key1",
+                     ":partial_chain",
                      ":regex1",
                      ":regex2",
                      ":regex3",