little cleanup
[akkoma] / lib / pleroma / web / admin_api / admin_api_controller.ex
index 23dcbedbacba8cead7068ae585dd4033de214f58..99fcc080ce69ce161e0baced9d8d3dddc046088e 100644 (file)
@@ -88,7 +88,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
   plug(
     OAuthScopesPlug,
     %{scopes: ["read"], admin: true}
-    when action in [:config_show, :migrate_to_db, :migrate_from_db, :list_log]
+    when action in [:config_show, :migrate_from_db, :list_log]
   )
 
   plug(
@@ -785,7 +785,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
   end
 
   def migrate_from_db(conn, _params) do
-    with :ok <- check_dynamic_configuration(conn) do
+    with :ok <- configurable_from_database(conn) do
       Mix.Tasks.Pleroma.Config.run([
         "migrate_from_db",
         "--env",
@@ -798,11 +798,14 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
   end
 
   def config_show(conn, _params) do
-    with :ok <- check_dynamic_configuration(conn) do
+    with :ok <- configurable_from_database(conn) do
       configs = Pleroma.Repo.all(Config)
 
       if configs == [] do
-        errors(conn, {:error, "To use dynamic configuration migrate your settings to database."})
+        errors(
+          conn,
+          {:error, "To use configuration from database migrate your settings to database."}
+        )
       else
         conn
         |> put_view(ConfigView)
@@ -812,10 +815,10 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
   end
 
   def config_update(conn, %{"configs" => configs}) do
-    with :ok <- check_dynamic_configuration(conn) do
+    with :ok <- configurable_from_database(conn) do
       updated =
         Enum.map(configs, fn
-          %{"group" => group, "key" => key, "delete" => "true"} = params ->
+          %{"group" => group, "key" => key, "delete" => true} = params ->
             with {:ok, config} <-
                    Config.delete(%{group: group, key: key, subkeys: params["subkeys"]}) do
               config
@@ -843,11 +846,14 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
     end
   end
 
-  defp check_dynamic_configuration(conn) do
-    if Pleroma.Config.get([:instance, :dynamic_configuration]) do
+  defp configurable_from_database(conn) do
+    if Pleroma.Config.get(:configurable_from_database) do
       :ok
     else
-      errors(conn, {:error, "To use this endpoint you need to enable dynamic configuration."})
+      errors(
+        conn,
+        {:error, "To use this endpoint you need to enable configuration from database."}
+      )
     end
   end