Allow whitelisting whole groups
authorStephanie Wilde-Hobbs <steph@rx14.co.uk>
Thu, 14 May 2020 11:34:46 +0000 (12:34 +0100)
committerStephanie Wilde-Hobbs <steph@rx14.co.uk>
Thu, 14 May 2020 11:43:53 +0000 (12:43 +0100)
docs/configuration/cheatsheet.md
lib/pleroma/web/admin_api/admin_api_controller.ex
test/web/admin_api/admin_api_controller_test.exs

index 7b7a332c7e975a5c91eeeff49a72aea130da67d2..f0ecebc99c5000932b7f8e091dabbdc559a5d41a 100644 (file)
@@ -919,7 +919,8 @@ Example:
 ```elixir
 config :pleroma, :database_config_whitelist, [
   {:pleroma, :instance},
-  {:pleroma, Pleroma.Web.Metadata}
+  {:pleroma, Pleroma.Web.Metadata},
+  {:auto_linker}
 ]
 ```
 
index 3053f57a18d44eb398dbfb84d686ebbdf5bbf6e5..c996a2a5a64b52edc6838956b802b6375c843c94 100644 (file)
@@ -1015,8 +1015,12 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
 
   defp whitelisted_config?(group, key) do
     if whitelisted_configs = Config.get(:database_config_whitelist) do
-      Enum.any?(whitelisted_configs, fn {whitelisted_group, whitelisted_key} ->
-        group == inspect(whitelisted_group) && key == inspect(whitelisted_key)
+      Enum.any?(whitelisted_configs, fn
+        {whitelisted_group} ->
+          group == inspect(whitelisted_group)
+
+        {whitelisted_group, whitelisted_key} ->
+          group == inspect(whitelisted_group) && key == inspect(whitelisted_key)
       end)
     else
       true
index 7d42a400c3c46774206e25f366592091c29d1382..e573220ba3deeab2b6a93bed01db2456eca143c6 100644 (file)
@@ -2948,7 +2948,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
       clear_config(:database_config_whitelist, [
         {:pleroma, :key1},
         {:pleroma, :key2},
-        {:pleroma, Pleroma.Captcha.NotReal}
+        {:pleroma, Pleroma.Captcha.NotReal},
+        {:not_real}
       ])
 
       post(conn, "/api/pleroma/admin/config", %{
@@ -2957,7 +2958,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
           %{group: ":pleroma", key: ":key2", value: "value2"},
           %{group: ":pleroma", key: ":key3", value: "value3"},
           %{group: ":pleroma", key: "Pleroma.Web.Endpoint.NotReal", value: "value4"},
-          %{group: ":pleroma", key: "Pleroma.Captcha.NotReal", value: "value5"}
+          %{group: ":pleroma", key: "Pleroma.Captcha.NotReal", value: "value5"},
+          %{group: ":not_real", key: ":anything", value: "value6"}
         ]
       })
 
@@ -2966,6 +2968,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
       assert Application.get_env(:pleroma, :key3) == nil
       assert Application.get_env(:pleroma, Pleroma.Web.Endpoint.NotReal) == nil
       assert Application.get_env(:pleroma, Pleroma.Captcha.NotReal) == "value5"
+      assert Application.get_env(:not_real, :anything) == "value6"
     end
   end
 
@@ -3624,7 +3627,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
       clear_config(:database_config_whitelist, [
         {:pleroma, :instance},
         {:pleroma, :activitypub},
-        {:pleroma, Pleroma.Upload}
+        {:pleroma, Pleroma.Upload},
+        {:esshd}
       ])
 
       admin = insert(:user, is_admin: true)
@@ -3635,9 +3639,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
 
       children = json_response(conn, 200)
 
-      assert length(children) == 3
+      assert length(children) == 4
 
-      assert Enum.all?(children, fn c -> c["group"] == ":pleroma" end)
+      assert Enum.count(children, fn c -> c["group"] == ":pleroma" end) == 3
 
       instance = Enum.find(children, fn c -> c["key"] == ":instance" end)
       assert instance["children"]
@@ -3647,6 +3651,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
 
       web_endpoint = Enum.find(children, fn c -> c["key"] == "Pleroma.Upload" end)
       assert web_endpoint["children"]
+
+      esshd = Enum.find(children, fn c -> c["group"] == ":esshd" end)
+      assert esshd["children"]
     end
   end