forked from AkkomaGang/akkoma
Merge branch 'admin-configure-atom-keys' into 'develop'
admin configure - atom keys with leading : See merge request pleroma/pleroma!1424
This commit is contained in:
commit
03c4ea44ad
4 changed files with 59 additions and 20 deletions
|
@ -28,6 +28,14 @@ def run(["migrate_to_db"]) do
|
||||||
|> Enum.reject(fn {k, _v} -> k in [Pleroma.Repo, :env] end)
|
|> Enum.reject(fn {k, _v} -> k in [Pleroma.Repo, :env] end)
|
||||||
|> Enum.each(fn {k, v} ->
|
|> Enum.each(fn {k, v} ->
|
||||||
key = to_string(k) |> String.replace("Elixir.", "")
|
key = to_string(k) |> String.replace("Elixir.", "")
|
||||||
|
|
||||||
|
key =
|
||||||
|
if String.starts_with?(key, "Pleroma.") do
|
||||||
|
key
|
||||||
|
else
|
||||||
|
":" <> key
|
||||||
|
end
|
||||||
|
|
||||||
{:ok, _} = Config.update_or_create(%{group: "pleroma", key: key, value: v})
|
{:ok, _} = Config.update_or_create(%{group: "pleroma", key: key, value: v})
|
||||||
Mix.shell().info("#{key} is migrated.")
|
Mix.shell().info("#{key} is migrated.")
|
||||||
end)
|
end)
|
||||||
|
@ -53,17 +61,9 @@ def run(["migrate_from_db", env, delete?]) do
|
||||||
|
|
||||||
Repo.all(Config)
|
Repo.all(Config)
|
||||||
|> Enum.each(fn config ->
|
|> Enum.each(fn config ->
|
||||||
mark =
|
|
||||||
if String.starts_with?(config.key, "Pleroma.") or
|
|
||||||
String.starts_with?(config.key, "Ueberauth"),
|
|
||||||
do: ",",
|
|
||||||
else: ":"
|
|
||||||
|
|
||||||
IO.write(
|
IO.write(
|
||||||
file,
|
file,
|
||||||
"config :#{config.group}, #{config.key}#{mark} #{
|
"config :#{config.group}, #{config.key}, #{inspect(Config.from_binary(config.value))}\r\n\r\n"
|
||||||
inspect(Config.from_binary(config.value))
|
|
||||||
}\r\n"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if delete? do
|
if delete? do
|
||||||
|
|
|
@ -35,7 +35,7 @@ defp update_env(setting) do
|
||||||
if String.starts_with?(setting.key, "Pleroma.") do
|
if String.starts_with?(setting.key, "Pleroma.") do
|
||||||
"Elixir." <> setting.key
|
"Elixir." <> setting.key
|
||||||
else
|
else
|
||||||
setting.key
|
String.trim_leading(setting.key, ":")
|
||||||
end
|
end
|
||||||
|
|
||||||
group = String.to_existing_atom(setting.group)
|
group = String.to_existing_atom(setting.group)
|
||||||
|
|
|
@ -34,8 +34,8 @@ test "settings are migrated to db" do
|
||||||
|
|
||||||
Mix.Tasks.Pleroma.Config.run(["migrate_to_db"])
|
Mix.Tasks.Pleroma.Config.run(["migrate_to_db"])
|
||||||
|
|
||||||
first_db = Config.get_by_params(%{group: "pleroma", key: "first_setting"})
|
first_db = Config.get_by_params(%{group: "pleroma", key: ":first_setting"})
|
||||||
second_db = Config.get_by_params(%{group: "pleroma", key: "second_setting"})
|
second_db = Config.get_by_params(%{group: "pleroma", key: ":second_setting"})
|
||||||
refute Config.get_by_params(%{group: "pleroma", key: "Pleroma.Repo"})
|
refute Config.get_by_params(%{group: "pleroma", key: "Pleroma.Repo"})
|
||||||
|
|
||||||
assert Config.from_binary(first_db.value) == [key: "value", key2: [Pleroma.Repo]]
|
assert Config.from_binary(first_db.value) == [key: "value", key2: [Pleroma.Repo]]
|
||||||
|
@ -45,13 +45,13 @@ test "settings are migrated to db" do
|
||||||
test "settings are migrated to file and deleted from db", %{temp_file: temp_file} do
|
test "settings are migrated to file and deleted from db", %{temp_file: temp_file} do
|
||||||
Config.create(%{
|
Config.create(%{
|
||||||
group: "pleroma",
|
group: "pleroma",
|
||||||
key: "setting_first",
|
key: ":setting_first",
|
||||||
value: [key: "value", key2: [Pleroma.Activity]]
|
value: [key: "value", key2: [Pleroma.Activity]]
|
||||||
})
|
})
|
||||||
|
|
||||||
Config.create(%{
|
Config.create(%{
|
||||||
group: "pleroma",
|
group: "pleroma",
|
||||||
key: "setting_second",
|
key: ":setting_second",
|
||||||
value: [key: "valu2", key2: [Pleroma.Repo]]
|
value: [key: "valu2", key2: [Pleroma.Repo]]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ test "settings are migrated to file and deleted from db", %{temp_file: temp_file
|
||||||
assert File.exists?(temp_file)
|
assert File.exists?(temp_file)
|
||||||
{:ok, file} = File.read(temp_file)
|
{:ok, file} = File.read(temp_file)
|
||||||
|
|
||||||
assert file =~ "config :pleroma, setting_first:"
|
assert file =~ "config :pleroma, :setting_first,"
|
||||||
assert file =~ "config :pleroma, setting_second:"
|
assert file =~ "config :pleroma, :setting_second,"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1720,7 +1720,7 @@ test "settings with nesting map", %{conn: conn} do
|
||||||
configs: [
|
configs: [
|
||||||
%{
|
%{
|
||||||
"group" => "pleroma",
|
"group" => "pleroma",
|
||||||
"key" => "key1",
|
"key" => ":key1",
|
||||||
"value" => [
|
"value" => [
|
||||||
%{"tuple" => [":key2", "some_val"]},
|
%{"tuple" => [":key2", "some_val"]},
|
||||||
%{
|
%{
|
||||||
|
@ -1750,7 +1750,7 @@ test "settings with nesting map", %{conn: conn} do
|
||||||
"configs" => [
|
"configs" => [
|
||||||
%{
|
%{
|
||||||
"group" => "pleroma",
|
"group" => "pleroma",
|
||||||
"key" => "key1",
|
"key" => ":key1",
|
||||||
"value" => [
|
"value" => [
|
||||||
%{"tuple" => [":key2", "some_val"]},
|
%{"tuple" => [":key2", "some_val"]},
|
||||||
%{
|
%{
|
||||||
|
@ -1782,7 +1782,7 @@ test "value as map", %{conn: conn} do
|
||||||
configs: [
|
configs: [
|
||||||
%{
|
%{
|
||||||
"group" => "pleroma",
|
"group" => "pleroma",
|
||||||
"key" => "key1",
|
"key" => ":key1",
|
||||||
"value" => %{"key" => "some_val"}
|
"value" => %{"key" => "some_val"}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -1793,7 +1793,7 @@ test "value as map", %{conn: conn} do
|
||||||
"configs" => [
|
"configs" => [
|
||||||
%{
|
%{
|
||||||
"group" => "pleroma",
|
"group" => "pleroma",
|
||||||
"key" => "key1",
|
"key" => ":key1",
|
||||||
"value" => %{"key" => "some_val"}
|
"value" => %{"key" => "some_val"}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -1862,6 +1862,45 @@ test "dispatch setting", %{conn: conn} do
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "queues key as atom", %{conn: conn} do
|
||||||
|
conn =
|
||||||
|
post(conn, "/api/pleroma/admin/config", %{
|
||||||
|
configs: [
|
||||||
|
%{
|
||||||
|
"group" => "pleroma_job_queue",
|
||||||
|
"key" => ":queues",
|
||||||
|
"value" => [
|
||||||
|
%{"tuple" => [":federator_incoming", 50]},
|
||||||
|
%{"tuple" => [":federator_outgoing", 50]},
|
||||||
|
%{"tuple" => [":web_push", 50]},
|
||||||
|
%{"tuple" => [":mailer", 10]},
|
||||||
|
%{"tuple" => [":transmogrifier", 20]},
|
||||||
|
%{"tuple" => [":scheduled_activities", 10]},
|
||||||
|
%{"tuple" => [":background", 5]}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
assert json_response(conn, 200) == %{
|
||||||
|
"configs" => [
|
||||||
|
%{
|
||||||
|
"group" => "pleroma_job_queue",
|
||||||
|
"key" => ":queues",
|
||||||
|
"value" => [
|
||||||
|
%{"tuple" => [":federator_incoming", 50]},
|
||||||
|
%{"tuple" => [":federator_outgoing", 50]},
|
||||||
|
%{"tuple" => [":web_push", 50]},
|
||||||
|
%{"tuple" => [":mailer", 10]},
|
||||||
|
%{"tuple" => [":transmogrifier", 20]},
|
||||||
|
%{"tuple" => [":scheduled_activities", 10]},
|
||||||
|
%{"tuple" => [":background", 5]}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue