tesla adapter can't be changed in adminFE

This commit is contained in:
Alexander Strizhakov 2020-03-10 15:31:44 +03:00
parent d9f8941dac
commit 426f5ee48a
No known key found for this signature in database
GPG key ID: 022896A53AEF1381
2 changed files with 31 additions and 48 deletions

View file

@ -20,8 +20,7 @@ defmodule Pleroma.Config.TransferTask do
{:pleroma, :markup}, {:pleroma, :markup},
{:pleroma, :streamer}, {:pleroma, :streamer},
{:pleroma, :pools}, {:pleroma, :pools},
{:pleroma, :connections_pool}, {:pleroma, :connections_pool}
{:tesla, :adapter}
] ]
@reboot_time_subkeys [ @reboot_time_subkeys [
@ -35,8 +34,6 @@ defmodule Pleroma.Config.TransferTask do
{:pleroma, :gopher, [:enabled]} {:pleroma, :gopher, [:enabled]}
] ]
@reject [nil, :prometheus]
def start_link(_) do def start_link(_) do
load_and_update_env() load_and_update_env()
if Pleroma.Config.get(:env) == :test, do: Ecto.Adapters.SQL.Sandbox.checkin(Repo) if Pleroma.Config.get(:env) == :test, do: Ecto.Adapters.SQL.Sandbox.checkin(Repo)
@ -45,35 +42,30 @@ def start_link(_) do
@spec load_and_update_env([ConfigDB.t()]) :: :ok | false @spec load_and_update_env([ConfigDB.t()]) :: :ok | false
def load_and_update_env(deleted \\ [], restart_pleroma? \\ true) do def load_and_update_env(deleted \\ [], restart_pleroma? \\ true) do
with {:configurable, true} <- with {_, true} <- {:configurable, Pleroma.Config.get(:configurable_from_database)} do
{:configurable, Pleroma.Config.get(:configurable_from_database)},
true <- Ecto.Adapters.SQL.table_exists?(Repo, "config"),
started_applications <- Application.started_applications() do
# We need to restart applications for loaded settings take effect # We need to restart applications for loaded settings take effect
in_db = Repo.all(ConfigDB) in_db = Repo.all(ConfigDB)
with_deleted = in_db ++ deleted with_deleted = in_db ++ deleted
reject_for_restart = if restart_pleroma?, do: @reject, else: [:pleroma | @reject] # TODO: some problem with prometheus after restart!
reject = [nil, :prometheus]
reject_for_restart =
if restart_pleroma? do
reject
else
[:pleroma | reject]
end
started_applications = Application.started_applications()
applications =
with_deleted with_deleted
|> Enum.map(&merge_and_update(&1)) |> Enum.map(&merge_and_update(&1))
|> Enum.uniq() |> Enum.uniq()
# TODO: some problem with prometheus after restart!
|> Enum.reject(&(&1 in reject_for_restart)) |> Enum.reject(&(&1 in reject_for_restart))
|> maybe_set_pleroma_last()
# to be ensured that pleroma will be restarted last |> Enum.each(&restart(started_applications, &1, Pleroma.Config.get(:env)))
applications =
if :pleroma in applications do
List.delete(applications, :pleroma) ++ [:pleroma]
else
Restarter.Pleroma.rebooted()
applications
end
Enum.each(applications, &restart(started_applications, &1, Pleroma.Config.get(:env)))
:ok :ok
else else
@ -81,6 +73,18 @@ def load_and_update_env(deleted \\ [], restart_pleroma? \\ true) do
end end
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 defp group_for_restart(:logger, key, _, merged_value) do
# change logger configuration in runtime, without restart # change logger configuration in runtime, without restart
if Keyword.keyword?(merged_value) and if Keyword.keyword?(merged_value) and
@ -93,14 +97,10 @@ defp group_for_restart(:logger, key, _, merged_value) do
nil nil
end end
defp group_for_restart(:tesla, _, _, _), do: :pleroma
defp group_for_restart(group, _, _, _) when group != :pleroma, do: group defp group_for_restart(group, _, _, _) when group != :pleroma, do: group
defp group_for_restart(group, key, value, _) do defp group_for_restart(group, key, value, _) do
if pleroma_need_restart?(group, key, value) do if pleroma_need_restart?(group, key, value), do: group
group
end
end end
defp merge_and_update(setting) do defp merge_and_update(setting) do

View file

@ -2513,8 +2513,7 @@ test "saving full setting if value is not keyword", %{conn: conn} do
"value" => "Tesla.Adapter.Httpc", "value" => "Tesla.Adapter.Httpc",
"db" => [":adapter"] "db" => [":adapter"]
} }
], ]
"need_reboot" => true
} }
end end
@ -2586,9 +2585,6 @@ test "update config setting & delete with fallback to default value", %{
end end
test "common config example", %{conn: conn} do test "common config example", %{conn: conn} do
adapter = Application.get_env(:tesla, :adapter)
on_exit(fn -> Application.put_env(:tesla, :adapter, adapter) end)
conn = conn =
post(conn, "/api/pleroma/admin/config", %{ post(conn, "/api/pleroma/admin/config", %{
configs: [ configs: [
@ -2607,16 +2603,10 @@ test "common config example", %{conn: conn} do
%{"tuple" => [":regex4", "~r/https:\/\/example.com/s"]}, %{"tuple" => [":regex4", "~r/https:\/\/example.com/s"]},
%{"tuple" => [":name", "Pleroma"]} %{"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 Config.get([Pleroma.Captcha.NotReal, :name]) == "Pleroma"
assert json_response(conn, 200) == %{ assert json_response(conn, 200) == %{
@ -2648,15 +2638,8 @@ test "common config example", %{conn: conn} do
":regex4", ":regex4",
":name" ":name"
] ]
},
%{
"group" => ":tesla",
"key" => ":adapter",
"value" => "Tesla.Adapter.Httpc",
"db" => [":adapter"]
} }
], ]
"need_reboot" => true
} }
end end