tesla adapter can't be changed in adminFE
authorAlexander Strizhakov <alex.strizhakov@gmail.com>
Tue, 10 Mar 2020 12:31:44 +0000 (15:31 +0300)
committerAlexander Strizhakov <alex.strizhakov@gmail.com>
Tue, 10 Mar 2020 12:31:44 +0000 (15:31 +0300)
lib/pleroma/config/transfer_task.ex
test/web/admin_api/admin_api_controller_test.exs

index bf1b943d8c90155eed60bc8435734c9571344a4c..4a4c022f06750b3f4f8724c37e2adc09075c8fa1 100644 (file)
@@ -20,8 +20,7 @@ defmodule Pleroma.Config.TransferTask do
     {:pleroma, :markup},
     {:pleroma, :streamer},
     {:pleroma, :pools},
-    {:pleroma, :connections_pool},
-    {:tesla, :adapter}
+    {:pleroma, :connections_pool}
   ]
 
   @reboot_time_subkeys [
@@ -35,8 +34,6 @@ defmodule Pleroma.Config.TransferTask do
     {:pleroma, :gopher, [:enabled]}
   ]
 
-  @reject [nil, :prometheus]
-
   def start_link(_) do
     load_and_update_env()
     if Pleroma.Config.get(:env) == :test, do: Ecto.Adapters.SQL.Sandbox.checkin(Repo)
@@ -45,35 +42,30 @@ defmodule Pleroma.Config.TransferTask do
 
   @spec load_and_update_env([ConfigDB.t()]) :: :ok | false
   def load_and_update_env(deleted \\ [], restart_pleroma? \\ true) do
-    with {:configurable, true} <-
-           {:configurable, Pleroma.Config.get(:configurable_from_database)},
-         true <- Ecto.Adapters.SQL.table_exists?(Repo, "config"),
-         started_applications <- Application.started_applications() do
+    with {_, true} <- {:configurable, Pleroma.Config.get(:configurable_from_database)} do
       # We need to restart applications for loaded settings take effect
-
       in_db = Repo.all(ConfigDB)
 
       with_deleted = in_db ++ deleted
 
-      reject_for_restart = if restart_pleroma?, do: @reject, else: [:pleroma | @reject]
-
-      applications =
-        with_deleted
-        |> Enum.map(&merge_and_update(&1))
-        |> Enum.uniq()
-        # TODO: some problem with prometheus after restart!
-        |> Enum.reject(&(&1 in reject_for_restart))
+      # TODO: some problem with prometheus after restart!
+      reject = [nil, :prometheus]
 
-      # to be ensured that pleroma will be restarted last
-      applications =
-        if :pleroma in applications do
-          List.delete(applications, :pleroma) ++ [:pleroma]
+      reject_for_restart =
+        if restart_pleroma? do
+          reject
         else
-          Restarter.Pleroma.rebooted()
-          applications
+          [:pleroma | reject]
         end
 
-      Enum.each(applications, &restart(started_applications, &1, Pleroma.Config.get(:env)))
+      started_applications = Application.started_applications()
+
+      with_deleted
+      |> Enum.map(&merge_and_update(&1))
+      |> Enum.uniq()
+      |> Enum.reject(&(&1 in reject_for_restart))
+      |> maybe_set_pleroma_last()
+      |> Enum.each(&restart(started_applications, &1, Pleroma.Config.get(:env)))
 
       :ok
     else
@@ -81,6 +73,18 @@ defmodule Pleroma.Config.TransferTask do
     end
   end
 
+  defp maybe_set_pleroma_last(apps) do
+    # to be ensured that pleroma will be restarted last
+    if :pleroma in apps do
+      apps
+      |> List.delete(:pleroma)
+      |> List.insert_at(-1, :pleroma)
+    else
+      Restarter.Pleroma.rebooted()
+      apps
+    end
+  end
+
   defp group_for_restart(:logger, key, _, merged_value) do
     # change logger configuration in runtime, without restart
     if Keyword.keyword?(merged_value) and
@@ -93,14 +97,10 @@ defmodule Pleroma.Config.TransferTask do
     nil
   end
 
-  defp group_for_restart(:tesla, _, _, _), do: :pleroma
-
   defp group_for_restart(group, _, _, _) when group != :pleroma, do: group
 
   defp group_for_restart(group, key, value, _) do
-    if pleroma_need_restart?(group, key, value) do
-      group
-    end
+    if pleroma_need_restart?(group, key, value), do: group
   end
 
   defp merge_and_update(setting) do
index d6b8399480b200b8ccc70b5bb4b5cb362a64cc05..76240e5bcb57fb92e34c36318635ebcf56090b9a 100644 (file)
@@ -2513,8 +2513,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                    "value" => "Tesla.Adapter.Httpc",
                    "db" => [":adapter"]
                  }
-               ],
-               "need_reboot" => true
+               ]
              }
     end
 
@@ -2586,9 +2585,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
     end
 
     test "common config example", %{conn: conn} do
-      adapter = Application.get_env(:tesla, :adapter)
-      on_exit(fn -> Application.put_env(:tesla, :adapter, adapter) end)
-
       conn =
         post(conn, "/api/pleroma/admin/config", %{
           configs: [
@@ -2607,16 +2603,10 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                 %{"tuple" => [":regex4", "~r/https:\/\/example.com/s"]},
                 %{"tuple" => [":name", "Pleroma"]}
               ]
-            },
-            %{
-              "group" => ":tesla",
-              "key" => ":adapter",
-              "value" => "Tesla.Adapter.Httpc"
             }
           ]
         })
 
-      assert Application.get_env(:tesla, :adapter) == Tesla.Adapter.Httpc
       assert Config.get([Pleroma.Captcha.NotReal, :name]) == "Pleroma"
 
       assert json_response(conn, 200) == %{
@@ -2648,15 +2638,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
                      ":regex4",
                      ":name"
                    ]
-                 },
-                 %{
-                   "group" => ":tesla",
-                   "key" => ":adapter",
-                   "value" => "Tesla.Adapter.Httpc",
-                   "db" => [":adapter"]
                  }
-               ],
-               "need_reboot" => true
+               ]
              }
     end