Pleroma.Web.AdminAPI.Config -> Pleroma.ConfigDB
This commit is contained in:
Alexander Strizhakov 2020-01-16 08:50:27 +03:00
parent 59ba5c80b9
commit 29155137fd
No known key found for this signature in database
GPG Key ID: 022896A53AEF1381
10 changed files with 173 additions and 171 deletions

View File

@ -5,8 +5,8 @@
defmodule Mix.Tasks.Pleroma.Config do defmodule Mix.Tasks.Pleroma.Config do
use Mix.Task use Mix.Task
import Mix.Pleroma import Mix.Pleroma
alias Pleroma.ConfigDB
alias Pleroma.Repo alias Pleroma.Repo
alias Pleroma.Web.AdminAPI.Config
@shortdoc "Manages the location of the config" @shortdoc "Manages the location of the config"
@moduledoc File.read!("docs/administration/CLI_tasks/config.md") @moduledoc File.read!("docs/administration/CLI_tasks/config.md")
@ -55,7 +55,7 @@ defmodule Mix.Tasks.Pleroma.Config do
{:ok, file} <- File.open(config_path, [:write, :utf8]) do {:ok, file} <- File.open(config_path, [:write, :utf8]) do
IO.write(file, "use Mix.Config\r\n") IO.write(file, "use Mix.Config\r\n")
Config ConfigDB
|> Repo.all() |> Repo.all()
|> Enum.each(&write_to_file_with_deletion(&1, file, opts[:delete_from_db])) |> Enum.each(&write_to_file_with_deletion(&1, file, opts[:delete_from_db]))
@ -81,7 +81,7 @@ defmodule Mix.Tasks.Pleroma.Config do
end) end)
|> Enum.each(fn {key, value} -> |> Enum.each(fn {key, value} ->
key = inspect(key) key = inspect(key)
{:ok, _} = Config.update_or_create(%{group: inspect(group), key: key, value: value}) {:ok, _} = ConfigDB.update_or_create(%{group: inspect(group), key: key, value: value})
Mix.shell().info("settings for key #{key} migrated.") Mix.shell().info("settings for key #{key} migrated.")
end) end)
@ -93,7 +93,7 @@ defmodule Mix.Tasks.Pleroma.Config do
IO.write( IO.write(
file, file,
"config #{config.group}, #{config.key}, #{ "config #{config.group}, #{config.key}, #{
inspect(Config.from_binary(config.value), limit: :infinity) inspect(ConfigDB.from_binary(config.value), limit: :infinity)
}\r\n\r\n" }\r\n\r\n"
) )

View File

@ -2,7 +2,7 @@
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/> # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.Config do defmodule Pleroma.ConfigDB do
use Ecto.Schema use Ecto.Schema
import Ecto.Changeset import Ecto.Changeset
import Pleroma.Web.Gettext import Pleroma.Web.Gettext
@ -19,10 +19,10 @@ defmodule Pleroma.Web.AdminAPI.Config do
timestamps() timestamps()
end end
@spec get_by_params(map()) :: Config.t() | nil @spec get_by_params(map()) :: ConfigDB.t() | nil
def get_by_params(params), do: Repo.get_by(Config, params) def get_by_params(params), do: Repo.get_by(ConfigDB, params)
@spec changeset(Config.t(), map()) :: Changeset.t() @spec changeset(ConfigDB.t(), map()) :: Changeset.t()
def changeset(config, params \\ %{}) do def changeset(config, params \\ %{}) do
params = Map.put(params, :value, transform(params[:value])) params = Map.put(params, :value, transform(params[:value]))
@ -32,15 +32,15 @@ defmodule Pleroma.Web.AdminAPI.Config do
|> unique_constraint(:key, name: :config_group_key_index) |> unique_constraint(:key, name: :config_group_key_index)
end end
@spec create(map()) :: {:ok, Config.t()} | {:error, Changeset.t()} @spec create(map()) :: {:ok, ConfigDB.t()} | {:error, Changeset.t()}
def create(params) do def create(params) do
%Config{} %ConfigDB{}
|> changeset(params) |> changeset(params)
|> Repo.insert() |> Repo.insert()
end end
@spec update(Config.t(), map()) :: {:ok, Config} | {:error, Changeset.t()} @spec update(ConfigDB.t(), map()) :: {:ok, ConfigDB.t()} | {:error, Changeset.t()}
def update(%Config{} = config, %{value: value}) do def update(%ConfigDB{} = config, %{value: value}) do
config config
|> changeset(%{value: value}) |> changeset(%{value: value})
|> Repo.update() |> Repo.update()
@ -57,9 +57,9 @@ defmodule Pleroma.Web.AdminAPI.Config do
{:logger, :backends} {:logger, :backends}
] ]
defp only_full_update?(%Config{} = config) do defp only_full_update?(%ConfigDB{} = config) do
config_group = Config.from_string(config.group) config_group = ConfigDB.from_string(config.group)
config_key = Config.from_string(config.key) config_key = ConfigDB.from_string(config.key)
Enum.any?(@full_key_update, fn Enum.any?(@full_key_update, fn
{group, key} when is_list(key) -> {group, key} when is_list(key) ->
@ -70,39 +70,39 @@ defmodule Pleroma.Web.AdminAPI.Config do
end) end)
end end
defp can_be_partially_updated?(%Config{} = config), do: not only_full_update?(config) defp can_be_partially_updated?(%ConfigDB{} = config), do: not only_full_update?(config)
@spec update_or_create(map()) :: {:ok, Config.t()} | {:error, Changeset.t()} @spec update_or_create(map()) :: {:ok, ConfigDB.t()} | {:error, Changeset.t()}
def update_or_create(params) do def update_or_create(params) do
search_opts = Map.take(params, [:group, :key]) search_opts = Map.take(params, [:group, :key])
with %Config{} = config <- Config.get_by_params(search_opts), with %ConfigDB{} = config <- ConfigDB.get_by_params(search_opts),
{:partial_update, true, config} <- {:partial_update, true, config} <-
{:partial_update, can_be_partially_updated?(config), config}, {:partial_update, can_be_partially_updated?(config), config},
old_value <- from_binary(config.value), old_value <- from_binary(config.value),
transformed_value <- do_transform(params[:value]), transformed_value <- do_transform(params[:value]),
{:can_be_merged, true, config} <- {:can_be_merged, is_list(transformed_value), config}, {:can_be_merged, true, config} <- {:can_be_merged, is_list(transformed_value), config},
new_value <- DeepMerge.deep_merge(old_value, transformed_value) do new_value <- DeepMerge.deep_merge(old_value, transformed_value) do
Config.update(config, %{value: new_value, transformed?: true}) ConfigDB.update(config, %{value: new_value, transformed?: true})
else else
{reason, false, config} when reason in [:partial_update, :can_be_merged] -> {reason, false, config} when reason in [:partial_update, :can_be_merged] ->
Config.update(config, params) ConfigDB.update(config, params)
nil -> nil ->
Config.create(params) ConfigDB.create(params)
end end
end end
@spec delete(map()) :: {:ok, Config.t()} | {:error, Changeset.t()} | {:ok, nil} @spec delete(map()) :: {:ok, ConfigDB.t()} | {:error, Changeset.t()} | {:ok, nil}
def delete(params) do def delete(params) do
search_opts = Map.delete(params, :subkeys) search_opts = Map.delete(params, :subkeys)
with %Config{} = config <- Config.get_by_params(search_opts), with %ConfigDB{} = config <- ConfigDB.get_by_params(search_opts),
{config, sub_keys} when is_list(sub_keys) <- {config, params[:subkeys]}, {config, sub_keys} when is_list(sub_keys) <- {config, params[:subkeys]},
old_value <- from_binary(config.value), old_value <- from_binary(config.value),
keys <- Enum.map(sub_keys, &do_transform_string(&1)), keys <- Enum.map(sub_keys, &do_transform_string(&1)),
new_value <- Keyword.drop(old_value, keys) do new_value <- Keyword.drop(old_value, keys) do
Config.update(config, %{value: new_value}) ConfigDB.update(config, %{value: new_value})
else else
{config, nil} -> {config, nil} ->
Repo.delete(config) Repo.delete(config)

View File

@ -5,10 +5,10 @@
defmodule Pleroma.Config.TransferTask do defmodule Pleroma.Config.TransferTask do
use Task use Task
require Logger alias Pleroma.ConfigDB
alias Pleroma.Repo alias Pleroma.Repo
alias Pleroma.Web.AdminAPI.Config
require Logger
def start_link(_) do def start_link(_) do
load_and_update_env() load_and_update_env()
@ -21,7 +21,7 @@ defmodule Pleroma.Config.TransferTask do
true <- Ecto.Adapters.SQL.table_exists?(Repo, "config"), true <- Ecto.Adapters.SQL.table_exists?(Repo, "config"),
started_applications <- Application.started_applications() do 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
Config ConfigDB
|> Repo.all() |> Repo.all()
|> Enum.map(&update_env(&1)) |> Enum.map(&update_env(&1))
|> Enum.uniq() |> Enum.uniq()
@ -33,9 +33,9 @@ defmodule Pleroma.Config.TransferTask do
defp update_env(setting) do defp update_env(setting) do
try do try do
key = Config.from_string(setting.key) key = ConfigDB.from_string(setting.key)
group = Config.from_string(setting.group) group = ConfigDB.from_string(setting.group)
value = Config.from_binary(setting.value) value = ConfigDB.from_binary(setting.value)
if group != :phoenix and key != :serve_endpoints do if group != :phoenix and key != :serve_endpoints do
:ok = Application.put_env(group, key, value) :ok = Application.put_env(group, key, value)

View File

@ -8,6 +8,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
import Pleroma.Web.ControllerHelper, only: [json_response: 3] import Pleroma.Web.ControllerHelper, only: [json_response: 3]
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.ConfigDB
alias Pleroma.ModerationLog alias Pleroma.ModerationLog
alias Pleroma.Plugs.OAuthScopesPlug alias Pleroma.Plugs.OAuthScopesPlug
alias Pleroma.ReportNote alias Pleroma.ReportNote
@ -17,7 +18,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
alias Pleroma.Web.ActivityPub.Relay alias Pleroma.Web.ActivityPub.Relay
alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.AdminAPI.AccountView alias Pleroma.Web.AdminAPI.AccountView
alias Pleroma.Web.AdminAPI.Config
alias Pleroma.Web.AdminAPI.ConfigView alias Pleroma.Web.AdminAPI.ConfigView
alias Pleroma.Web.AdminAPI.ModerationLogView alias Pleroma.Web.AdminAPI.ModerationLogView
alias Pleroma.Web.AdminAPI.Report alias Pleroma.Web.AdminAPI.Report
@ -799,7 +799,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
def config_show(conn, _params) do def config_show(conn, _params) do
with :ok <- configurable_from_database(conn) do with :ok <- configurable_from_database(conn) do
configs = Pleroma.Repo.all(Config) configs = Pleroma.Repo.all(ConfigDB)
if configs == [] do if configs == [] do
errors( errors(
@ -820,13 +820,13 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
Enum.map(configs, fn Enum.map(configs, fn
%{"group" => group, "key" => key, "delete" => true} = params -> %{"group" => group, "key" => key, "delete" => true} = params ->
with {:ok, config} <- with {:ok, config} <-
Config.delete(%{group: group, key: key, subkeys: params["subkeys"]}) do ConfigDB.delete(%{group: group, key: key, subkeys: params["subkeys"]}) do
config config
end end
%{"group" => group, "key" => key, "value" => value} -> %{"group" => group, "key" => key, "value" => value} ->
with {:ok, config} <- with {:ok, config} <-
Config.update_or_create(%{group: group, key: key, value: value}) do ConfigDB.update_or_create(%{group: group, key: key, value: value}) do
config config
end end
end) end)

View File

@ -15,7 +15,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigView do
%{ %{
key: config.key, key: config.key,
group: config.group, group: config.group,
value: Pleroma.Web.AdminAPI.Config.from_binary_with_convert(config.value) value: Pleroma.ConfigDB.from_binary_with_convert(config.value)
} }
end end
end end

View File

@ -2,27 +2,27 @@
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/> # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.AdminAPI.ConfigTest do defmodule Pleroma.ConfigDBTest do
use Pleroma.DataCase, async: true use Pleroma.DataCase, async: true
import Pleroma.Factory import Pleroma.Factory
alias Pleroma.Web.AdminAPI.Config alias Pleroma.ConfigDB
test "get_by_key/1" do test "get_by_key/1" do
config = insert(:config) config = insert(:config)
insert(:config) insert(:config)
assert config == Config.get_by_params(%{group: config.group, key: config.key}) assert config == ConfigDB.get_by_params(%{group: config.group, key: config.key})
end end
test "create/1" do test "create/1" do
{:ok, config} = Config.create(%{group: "pleroma", key: "some_key", value: "some_value"}) {:ok, config} = ConfigDB.create(%{group: "pleroma", key: "some_key", value: "some_value"})
assert config == Config.get_by_params(%{group: "pleroma", key: "some_key"}) assert config == ConfigDB.get_by_params(%{group: "pleroma", key: "some_key"})
end end
test "update/1" do test "update/1" do
config = insert(:config) config = insert(:config)
{:ok, updated} = Config.update(config, %{value: "some_value"}) {:ok, updated} = ConfigDB.update(config, %{value: "some_value"})
loaded = Config.get_by_params(%{group: config.group, key: config.key}) loaded = ConfigDB.get_by_params(%{group: config.group, key: config.key})
assert loaded == updated assert loaded == updated
end end
@ -36,32 +36,32 @@ defmodule Pleroma.Web.AdminAPI.ConfigTest do
%{group: config.group, key: config.key, value: "new_value"} %{group: config.group, key: config.key, value: "new_value"}
] ]
assert Repo.all(Config) |> length() == 1 assert Repo.all(ConfigDB) |> length() == 1
Enum.each(params, &Config.update_or_create(&1)) Enum.each(params, &ConfigDB.update_or_create(&1))
assert Repo.all(Config) |> length() == 2 assert Repo.all(ConfigDB) |> length() == 2
config1 = Config.get_by_params(%{group: config.group, key: config.key}) config1 = ConfigDB.get_by_params(%{group: config.group, key: config.key})
config2 = Config.get_by_params(%{group: "pleroma", key: key2}) config2 = ConfigDB.get_by_params(%{group: "pleroma", key: key2})
assert config1.value == Config.transform("new_value") assert config1.value == ConfigDB.transform("new_value")
assert config2.value == Config.transform("another_value") assert config2.value == ConfigDB.transform("another_value")
end end
test "partial update" do test "partial update" do
config = insert(:config, value: Config.to_binary(key1: "val1", key2: :val2)) config = insert(:config, value: ConfigDB.to_binary(key1: "val1", key2: :val2))
{:ok, _config} = {:ok, _config} =
Config.update_or_create(%{ ConfigDB.update_or_create(%{
group: config.group, group: config.group,
key: config.key, key: config.key,
value: [key1: :val1, key3: :val3] value: [key1: :val1, key3: :val3]
}) })
updated = Config.get_by_params(%{group: config.group, key: config.key}) updated = ConfigDB.get_by_params(%{group: config.group, key: config.key})
value = Config.from_binary(updated.value) value = ConfigDB.from_binary(updated.value)
assert length(value) == 3 assert length(value) == 3
assert value[:key1] == :val1 assert value[:key1] == :val1
assert value[:key2] == :val2 assert value[:key2] == :val2
@ -69,48 +69,50 @@ defmodule Pleroma.Web.AdminAPI.ConfigTest do
end end
test "deep merge" do test "deep merge" do
config = insert(:config, value: Config.to_binary(key1: "val1", key2: [k1: :v1, k2: "v2"])) config = insert(:config, value: ConfigDB.to_binary(key1: "val1", key2: [k1: :v1, k2: "v2"]))
{:ok, config} = {:ok, config} =
Config.update_or_create(%{ ConfigDB.update_or_create(%{
group: config.group, group: config.group,
key: config.key, key: config.key,
value: [key1: :val1, key2: [k2: :v2, k3: :v3], key3: :val3] value: [key1: :val1, key2: [k2: :v2, k3: :v3], key3: :val3]
}) })
updated = Config.get_by_params(%{group: config.group, key: config.key}) updated = ConfigDB.get_by_params(%{group: config.group, key: config.key})
assert config.value == updated.value assert config.value == updated.value
value = Config.from_binary(updated.value) value = ConfigDB.from_binary(updated.value)
assert value[:key1] == :val1 assert value[:key1] == :val1
assert value[:key2] == [k1: :v1, k2: :v2, k3: :v3] assert value[:key2] == [k1: :v1, k2: :v2, k3: :v3]
assert value[:key3] == :val3 assert value[:key3] == :val3
end end
test "only full update for some keys" do test "only full update for some keys" do
config1 = insert(:config, key: ":ecto_repos", value: Config.to_binary(repo: Pleroma.Repo)) config1 = insert(:config, key: ":ecto_repos", value: ConfigDB.to_binary(repo: Pleroma.Repo))
config2 = insert(:config, group: ":cors_plug", key: ":max_age", value: Config.to_binary(18))
config2 =
insert(:config, group: ":cors_plug", key: ":max_age", value: ConfigDB.to_binary(18))
{:ok, _config} = {:ok, _config} =
Config.update_or_create(%{ ConfigDB.update_or_create(%{
group: config1.group, group: config1.group,
key: config1.key, key: config1.key,
value: [another_repo: [Pleroma.Repo]] value: [another_repo: [Pleroma.Repo]]
}) })
{:ok, _config} = {:ok, _config} =
Config.update_or_create(%{ ConfigDB.update_or_create(%{
group: config2.group, group: config2.group,
key: config2.key, key: config2.key,
value: 777 value: 777
}) })
updated1 = Config.get_by_params(%{group: config1.group, key: config1.key}) updated1 = ConfigDB.get_by_params(%{group: config1.group, key: config1.key})
updated2 = Config.get_by_params(%{group: config2.group, key: config2.key}) updated2 = ConfigDB.get_by_params(%{group: config2.group, key: config2.key})
assert Config.from_binary(updated1.value) == [another_repo: [Pleroma.Repo]] assert ConfigDB.from_binary(updated1.value) == [another_repo: [Pleroma.Repo]]
assert Config.from_binary(updated2.value) == 777 assert ConfigDB.from_binary(updated2.value) == 777
end end
test "full update if value is not keyword" do test "full update if value is not keyword" do
@ -118,176 +120,176 @@ defmodule Pleroma.Web.AdminAPI.ConfigTest do
insert(:config, insert(:config,
group: ":tesla", group: ":tesla",
key: ":adapter", key: ":adapter",
value: Config.to_binary(Tesla.Adapter.Hackney) value: ConfigDB.to_binary(Tesla.Adapter.Hackney)
) )
{:ok, _config} = {:ok, _config} =
Config.update_or_create(%{ ConfigDB.update_or_create(%{
group: config.group, group: config.group,
key: config.key, key: config.key,
value: Tesla.Adapter.Httpc value: Tesla.Adapter.Httpc
}) })
updated = Config.get_by_params(%{group: config.group, key: config.key}) updated = ConfigDB.get_by_params(%{group: config.group, key: config.key})
assert Config.from_binary(updated.value) == Tesla.Adapter.Httpc assert ConfigDB.from_binary(updated.value) == Tesla.Adapter.Httpc
end end
end end
test "delete/1" do test "delete/1" do
config = insert(:config) config = insert(:config)
{:ok, _} = Config.delete(%{key: config.key, group: config.group}) {:ok, _} = ConfigDB.delete(%{key: config.key, group: config.group})
refute Config.get_by_params(%{key: config.key, group: config.group}) refute ConfigDB.get_by_params(%{key: config.key, group: config.group})
end end
describe "transform/1" do describe "transform/1" do
test "string" do test "string" do
binary = Config.transform("value as string") binary = ConfigDB.transform("value as string")
assert binary == :erlang.term_to_binary("value as string") assert binary == :erlang.term_to_binary("value as string")
assert Config.from_binary(binary) == "value as string" assert ConfigDB.from_binary(binary) == "value as string"
end end
test "boolean" do test "boolean" do
binary = Config.transform(false) binary = ConfigDB.transform(false)
assert binary == :erlang.term_to_binary(false) assert binary == :erlang.term_to_binary(false)
assert Config.from_binary(binary) == false assert ConfigDB.from_binary(binary) == false
end end
test "nil" do test "nil" do
binary = Config.transform(nil) binary = ConfigDB.transform(nil)
assert binary == :erlang.term_to_binary(nil) assert binary == :erlang.term_to_binary(nil)
assert Config.from_binary(binary) == nil assert ConfigDB.from_binary(binary) == nil
end end
test "integer" do test "integer" do
binary = Config.transform(150) binary = ConfigDB.transform(150)
assert binary == :erlang.term_to_binary(150) assert binary == :erlang.term_to_binary(150)
assert Config.from_binary(binary) == 150 assert ConfigDB.from_binary(binary) == 150
end end
test "atom" do test "atom" do
binary = Config.transform(":atom") binary = ConfigDB.transform(":atom")
assert binary == :erlang.term_to_binary(:atom) assert binary == :erlang.term_to_binary(:atom)
assert Config.from_binary(binary) == :atom assert ConfigDB.from_binary(binary) == :atom
end end
test "ssl options" do test "ssl options" do
binary = Config.transform([":tlsv1", ":tlsv1.1", ":tlsv1.2"]) binary = ConfigDB.transform([":tlsv1", ":tlsv1.1", ":tlsv1.2"])
assert binary == :erlang.term_to_binary([:tlsv1, :"tlsv1.1", :"tlsv1.2"]) assert binary == :erlang.term_to_binary([:tlsv1, :"tlsv1.1", :"tlsv1.2"])
assert Config.from_binary(binary) == [:tlsv1, :"tlsv1.1", :"tlsv1.2"] assert ConfigDB.from_binary(binary) == [:tlsv1, :"tlsv1.1", :"tlsv1.2"]
end end
test "pleroma module" do test "pleroma module" do
binary = Config.transform("Pleroma.Bookmark") binary = ConfigDB.transform("Pleroma.Bookmark")
assert binary == :erlang.term_to_binary(Pleroma.Bookmark) assert binary == :erlang.term_to_binary(Pleroma.Bookmark)
assert Config.from_binary(binary) == Pleroma.Bookmark assert ConfigDB.from_binary(binary) == Pleroma.Bookmark
end end
test "pleroma string" do test "pleroma string" do
binary = Config.transform("Pleroma") binary = ConfigDB.transform("Pleroma")
assert binary == :erlang.term_to_binary("Pleroma") assert binary == :erlang.term_to_binary("Pleroma")
assert Config.from_binary(binary) == "Pleroma" assert ConfigDB.from_binary(binary) == "Pleroma"
end end
test "phoenix module" do test "phoenix module" do
binary = Config.transform("Phoenix.Socket.V1.JSONSerializer") binary = ConfigDB.transform("Phoenix.Socket.V1.JSONSerializer")
assert binary == :erlang.term_to_binary(Phoenix.Socket.V1.JSONSerializer) assert binary == :erlang.term_to_binary(Phoenix.Socket.V1.JSONSerializer)
assert Config.from_binary(binary) == Phoenix.Socket.V1.JSONSerializer assert ConfigDB.from_binary(binary) == Phoenix.Socket.V1.JSONSerializer
end end
test "tesla module" do test "tesla module" do
binary = Config.transform("Tesla.Adapter.Hackney") binary = ConfigDB.transform("Tesla.Adapter.Hackney")
assert binary == :erlang.term_to_binary(Tesla.Adapter.Hackney) assert binary == :erlang.term_to_binary(Tesla.Adapter.Hackney)
assert Config.from_binary(binary) == Tesla.Adapter.Hackney assert ConfigDB.from_binary(binary) == Tesla.Adapter.Hackney
end end
test "ExSyslogger module" do test "ExSyslogger module" do
binary = Config.transform("ExSyslogger") binary = ConfigDB.transform("ExSyslogger")
assert binary == :erlang.term_to_binary(ExSyslogger) assert binary == :erlang.term_to_binary(ExSyslogger)
assert Config.from_binary(binary) == ExSyslogger assert ConfigDB.from_binary(binary) == ExSyslogger
end end
test "Quack.Logger module" do test "Quack.Logger module" do
binary = Config.transform("Quack.Logger") binary = ConfigDB.transform("Quack.Logger")
assert binary == :erlang.term_to_binary(Quack.Logger) assert binary == :erlang.term_to_binary(Quack.Logger)
assert Config.from_binary(binary) == Quack.Logger assert ConfigDB.from_binary(binary) == Quack.Logger
end end
test "sigil" do test "sigil" do
binary = Config.transform("~r[comp[lL][aA][iI][nN]er]") binary = ConfigDB.transform("~r[comp[lL][aA][iI][nN]er]")
assert binary == :erlang.term_to_binary(~r/comp[lL][aA][iI][nN]er/) assert binary == :erlang.term_to_binary(~r/comp[lL][aA][iI][nN]er/)
assert Config.from_binary(binary) == ~r/comp[lL][aA][iI][nN]er/ assert ConfigDB.from_binary(binary) == ~r/comp[lL][aA][iI][nN]er/
end end
test "link sigil" do test "link sigil" do
binary = Config.transform("~r/https:\/\/example.com/") binary = ConfigDB.transform("~r/https:\/\/example.com/")
assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/) assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/)
assert Config.from_binary(binary) == ~r/https:\/\/example.com/ assert ConfigDB.from_binary(binary) == ~r/https:\/\/example.com/
end end
test "link sigil with um modifiers" do test "link sigil with um modifiers" do
binary = Config.transform("~r/https:\/\/example.com/um") binary = ConfigDB.transform("~r/https:\/\/example.com/um")
assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/um) assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/um)
assert Config.from_binary(binary) == ~r/https:\/\/example.com/um assert ConfigDB.from_binary(binary) == ~r/https:\/\/example.com/um
end end
test "link sigil with i modifier" do test "link sigil with i modifier" do
binary = Config.transform("~r/https:\/\/example.com/i") binary = ConfigDB.transform("~r/https:\/\/example.com/i")
assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/i) assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/i)
assert Config.from_binary(binary) == ~r/https:\/\/example.com/i assert ConfigDB.from_binary(binary) == ~r/https:\/\/example.com/i
end end
test "link sigil with s modifier" do test "link sigil with s modifier" do
binary = Config.transform("~r/https:\/\/example.com/s") binary = ConfigDB.transform("~r/https:\/\/example.com/s")
assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/s) assert binary == :erlang.term_to_binary(~r/https:\/\/example.com/s)
assert Config.from_binary(binary) == ~r/https:\/\/example.com/s assert ConfigDB.from_binary(binary) == ~r/https:\/\/example.com/s
end end
test "raise if valid delimiter not found" do test "raise if valid delimiter not found" do
assert_raise ArgumentError, "valid delimiter for Regex expression not found", fn -> assert_raise ArgumentError, "valid delimiter for Regex expression not found", fn ->
Config.transform("~r/https://[]{}<>\"'()|example.com/s") ConfigDB.transform("~r/https://[]{}<>\"'()|example.com/s")
end end
end end
test "2 child tuple" do test "2 child tuple" do
binary = Config.transform(%{"tuple" => ["v1", ":v2"]}) binary = ConfigDB.transform(%{"tuple" => ["v1", ":v2"]})
assert binary == :erlang.term_to_binary({"v1", :v2}) assert binary == :erlang.term_to_binary({"v1", :v2})
assert Config.from_binary(binary) == {"v1", :v2} assert ConfigDB.from_binary(binary) == {"v1", :v2}
end end
test "proxy tuple with localhost" do test "proxy tuple with localhost" do
binary = binary =
Config.transform(%{ ConfigDB.transform(%{
"tuple" => [":proxy_url", %{"tuple" => [":socks5", "localhost", 1234]}] "tuple" => [":proxy_url", %{"tuple" => [":socks5", "localhost", 1234]}]
}) })
assert binary == :erlang.term_to_binary({:proxy_url, {:socks5, :localhost, 1234}}) assert binary == :erlang.term_to_binary({:proxy_url, {:socks5, :localhost, 1234}})
assert Config.from_binary(binary) == {:proxy_url, {:socks5, :localhost, 1234}} assert ConfigDB.from_binary(binary) == {:proxy_url, {:socks5, :localhost, 1234}}
end end
test "proxy tuple with domain" do test "proxy tuple with domain" do
binary = binary =
Config.transform(%{ ConfigDB.transform(%{
"tuple" => [":proxy_url", %{"tuple" => [":socks5", "domain.com", 1234]}] "tuple" => [":proxy_url", %{"tuple" => [":socks5", "domain.com", 1234]}]
}) })
assert binary == :erlang.term_to_binary({:proxy_url, {:socks5, 'domain.com', 1234}}) assert binary == :erlang.term_to_binary({:proxy_url, {:socks5, 'domain.com', 1234}})
assert Config.from_binary(binary) == {:proxy_url, {:socks5, 'domain.com', 1234}} assert ConfigDB.from_binary(binary) == {:proxy_url, {:socks5, 'domain.com', 1234}}
end end
test "proxy tuple with ip" do test "proxy tuple with ip" do
binary = binary =
Config.transform(%{ ConfigDB.transform(%{
"tuple" => [":proxy_url", %{"tuple" => [":socks5", "127.0.0.1", 1234]}] "tuple" => [":proxy_url", %{"tuple" => [":socks5", "127.0.0.1", 1234]}]
}) })
assert binary == :erlang.term_to_binary({:proxy_url, {:socks5, {127, 0, 0, 1}, 1234}}) assert binary == :erlang.term_to_binary({:proxy_url, {:socks5, {127, 0, 0, 1}, 1234}})
assert Config.from_binary(binary) == {:proxy_url, {:socks5, {127, 0, 0, 1}, 1234}} assert ConfigDB.from_binary(binary) == {:proxy_url, {:socks5, {127, 0, 0, 1}, 1234}}
end end
test "tuple with n childs" do test "tuple with n childs" do
binary = binary =
Config.transform(%{ ConfigDB.transform(%{
"tuple" => [ "tuple" => [
"v1", "v1",
":v2", ":v2",
@ -303,12 +305,12 @@ defmodule Pleroma.Web.AdminAPI.ConfigTest do
{"v1", :v2, Pleroma.Bookmark, 150, false, Phoenix.Socket.V1.JSONSerializer} {"v1", :v2, Pleroma.Bookmark, 150, false, Phoenix.Socket.V1.JSONSerializer}
) )
assert Config.from_binary(binary) == assert ConfigDB.from_binary(binary) ==
{"v1", :v2, Pleroma.Bookmark, 150, false, Phoenix.Socket.V1.JSONSerializer} {"v1", :v2, Pleroma.Bookmark, 150, false, Phoenix.Socket.V1.JSONSerializer}
end end
test "tuple with dispatch key" do test "tuple with dispatch key" do
binary = Config.transform(%{"tuple" => [":dispatch", ["{:_, binary = ConfigDB.transform(%{"tuple" => [":dispatch", ["{:_,
[ [
{\"/api/v1/streaming\", Pleroma.Web.MastodonAPI.WebsocketHandler, []}, {\"/api/v1/streaming\", Pleroma.Web.MastodonAPI.WebsocketHandler, []},
{\"/websocket\", Phoenix.Endpoint.CowboyWebSocket, {\"/websocket\", Phoenix.Endpoint.CowboyWebSocket,
@ -332,7 +334,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigTest do
]} ]}
) )
assert Config.from_binary(binary) == assert ConfigDB.from_binary(binary) ==
{:dispatch, {:dispatch,
[ [
{:_, {:_,
@ -347,38 +349,38 @@ defmodule Pleroma.Web.AdminAPI.ConfigTest do
end end
test "map with string key" do test "map with string key" do
binary = Config.transform(%{"key" => "value"}) binary = ConfigDB.transform(%{"key" => "value"})
assert binary == :erlang.term_to_binary(%{"key" => "value"}) assert binary == :erlang.term_to_binary(%{"key" => "value"})
assert Config.from_binary(binary) == %{"key" => "value"} assert ConfigDB.from_binary(binary) == %{"key" => "value"}
end end
test "map with atom key" do test "map with atom key" do
binary = Config.transform(%{":key" => "value"}) binary = ConfigDB.transform(%{":key" => "value"})
assert binary == :erlang.term_to_binary(%{key: "value"}) assert binary == :erlang.term_to_binary(%{key: "value"})
assert Config.from_binary(binary) == %{key: "value"} assert ConfigDB.from_binary(binary) == %{key: "value"}
end end
test "list of strings" do test "list of strings" do
binary = Config.transform(["v1", "v2", "v3"]) binary = ConfigDB.transform(["v1", "v2", "v3"])
assert binary == :erlang.term_to_binary(["v1", "v2", "v3"]) assert binary == :erlang.term_to_binary(["v1", "v2", "v3"])
assert Config.from_binary(binary) == ["v1", "v2", "v3"] assert ConfigDB.from_binary(binary) == ["v1", "v2", "v3"]
end end
test "list of modules" do test "list of modules" do
binary = Config.transform(["Pleroma.Repo", "Pleroma.Activity"]) binary = ConfigDB.transform(["Pleroma.Repo", "Pleroma.Activity"])
assert binary == :erlang.term_to_binary([Pleroma.Repo, Pleroma.Activity]) assert binary == :erlang.term_to_binary([Pleroma.Repo, Pleroma.Activity])
assert Config.from_binary(binary) == [Pleroma.Repo, Pleroma.Activity] assert ConfigDB.from_binary(binary) == [Pleroma.Repo, Pleroma.Activity]
end end
test "list of atoms" do test "list of atoms" do
binary = Config.transform([":v1", ":v2", ":v3"]) binary = ConfigDB.transform([":v1", ":v2", ":v3"])
assert binary == :erlang.term_to_binary([:v1, :v2, :v3]) assert binary == :erlang.term_to_binary([:v1, :v2, :v3])
assert Config.from_binary(binary) == [:v1, :v2, :v3] assert ConfigDB.from_binary(binary) == [:v1, :v2, :v3]
end end
test "list of mixed values" do test "list of mixed values" do
binary = binary =
Config.transform([ ConfigDB.transform([
"v1", "v1",
":v2", ":v2",
"Pleroma.Repo", "Pleroma.Repo",
@ -397,7 +399,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigTest do
false false
]) ])
assert Config.from_binary(binary) == [ assert ConfigDB.from_binary(binary) == [
"v1", "v1",
:v2, :v2,
Pleroma.Repo, Pleroma.Repo,
@ -408,23 +410,23 @@ defmodule Pleroma.Web.AdminAPI.ConfigTest do
end end
test "simple keyword" do test "simple keyword" do
binary = Config.transform([%{"tuple" => [":key", "value"]}]) binary = ConfigDB.transform([%{"tuple" => [":key", "value"]}])
assert binary == :erlang.term_to_binary([{:key, "value"}]) assert binary == :erlang.term_to_binary([{:key, "value"}])
assert Config.from_binary(binary) == [{:key, "value"}] assert ConfigDB.from_binary(binary) == [{:key, "value"}]
assert Config.from_binary(binary) == [key: "value"] assert ConfigDB.from_binary(binary) == [key: "value"]
end end
test "keyword with partial_chain key" do test "keyword with partial_chain key" do
binary = binary =
Config.transform([%{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]}]) ConfigDB.transform([%{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]}])
assert binary == :erlang.term_to_binary(partial_chain: &:hackney_connect.partial_chain/1) assert binary == :erlang.term_to_binary(partial_chain: &:hackney_connect.partial_chain/1)
assert Config.from_binary(binary) == [partial_chain: &:hackney_connect.partial_chain/1] assert ConfigDB.from_binary(binary) == [partial_chain: &:hackney_connect.partial_chain/1]
end end
test "keyword" do test "keyword" do
binary = binary =
Config.transform([ ConfigDB.transform([
%{"tuple" => [":types", "Pleroma.PostgresTypes"]}, %{"tuple" => [":types", "Pleroma.PostgresTypes"]},
%{"tuple" => [":telemetry_event", ["Pleroma.Repo.Instrumenter"]]}, %{"tuple" => [":telemetry_event", ["Pleroma.Repo.Instrumenter"]]},
%{"tuple" => [":migration_lock", nil]}, %{"tuple" => [":migration_lock", nil]},
@ -441,7 +443,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigTest do
key2: "string" key2: "string"
) )
assert Config.from_binary(binary) == [ assert ConfigDB.from_binary(binary) == [
types: Pleroma.PostgresTypes, types: Pleroma.PostgresTypes,
telemetry_event: [Pleroma.Repo.Instrumenter], telemetry_event: [Pleroma.Repo.Instrumenter],
migration_lock: nil, migration_lock: nil,
@ -452,7 +454,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigTest do
test "complex keyword with nested mixed childs" do test "complex keyword with nested mixed childs" do
binary = binary =
Config.transform([ ConfigDB.transform([
%{"tuple" => [":uploader", "Pleroma.Uploaders.Local"]}, %{"tuple" => [":uploader", "Pleroma.Uploaders.Local"]},
%{"tuple" => [":filters", ["Pleroma.Upload.Filter.Dedupe"]]}, %{"tuple" => [":filters", ["Pleroma.Upload.Filter.Dedupe"]]},
%{"tuple" => [":link_name", true]}, %{"tuple" => [":link_name", true]},
@ -492,7 +494,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigTest do
] ]
) )
assert Config.from_binary(binary) == assert ConfigDB.from_binary(binary) ==
[ [
uploader: Pleroma.Uploaders.Local, uploader: Pleroma.Uploaders.Local,
filters: [Pleroma.Upload.Filter.Dedupe], filters: [Pleroma.Upload.Filter.Dedupe],
@ -512,7 +514,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigTest do
test "common keyword" do test "common keyword" do
binary = binary =
Config.transform([ ConfigDB.transform([
%{"tuple" => [":level", ":warn"]}, %{"tuple" => [":level", ":warn"]},
%{"tuple" => [":meta", [":all"]]}, %{"tuple" => [":meta", [":all"]]},
%{"tuple" => [":path", ""]}, %{"tuple" => [":path", ""]},
@ -529,7 +531,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigTest do
webhook_url: "https://hooks.slack.com/services/YOUR-KEY-HERE" webhook_url: "https://hooks.slack.com/services/YOUR-KEY-HERE"
) )
assert Config.from_binary(binary) == [ assert ConfigDB.from_binary(binary) == [
level: :warn, level: :warn,
meta: [:all], meta: [:all],
path: "", path: "",
@ -540,7 +542,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigTest do
test "complex keyword with sigil" do test "complex keyword with sigil" do
binary = binary =
Config.transform([ ConfigDB.transform([
%{"tuple" => [":federated_timeline_removal", []]}, %{"tuple" => [":federated_timeline_removal", []]},
%{"tuple" => [":reject", ["~r/comp[lL][aA][iI][nN]er/"]]}, %{"tuple" => [":reject", ["~r/comp[lL][aA][iI][nN]er/"]]},
%{"tuple" => [":replace", []]} %{"tuple" => [":replace", []]}
@ -553,13 +555,13 @@ defmodule Pleroma.Web.AdminAPI.ConfigTest do
replace: [] replace: []
) )
assert Config.from_binary(binary) == assert ConfigDB.from_binary(binary) ==
[federated_timeline_removal: [], reject: [~r/comp[lL][aA][iI][nN]er/], replace: []] [federated_timeline_removal: [], reject: [~r/comp[lL][aA][iI][nN]er/], replace: []]
end end
test "complex keyword with tuples with more than 2 values" do test "complex keyword with tuples with more than 2 values" do
binary = binary =
Config.transform([ ConfigDB.transform([
%{ %{
"tuple" => [ "tuple" => [
":http", ":http",
@ -630,7 +632,7 @@ defmodule Pleroma.Web.AdminAPI.ConfigTest do
] ]
) )
assert Config.from_binary(binary) == [ assert ConfigDB.from_binary(binary) == [
http: [ http: [
key1: [ key1: [
{:_, {:_,

View File

@ -5,7 +5,7 @@
defmodule Pleroma.Config.TransferTaskTest do defmodule Pleroma.Config.TransferTaskTest do
use Pleroma.DataCase use Pleroma.DataCase
alias Pleroma.Web.AdminAPI.Config alias Pleroma.ConfigDB
clear_config(:configurable_from_database) do clear_config(:configurable_from_database) do
Pleroma.Config.put(:configurable_from_database, true) Pleroma.Config.put(:configurable_from_database, true)
@ -16,19 +16,19 @@ defmodule Pleroma.Config.TransferTaskTest do
refute Application.get_env(:idna, :test_key) refute Application.get_env(:idna, :test_key)
refute Application.get_env(:quack, :test_key) refute Application.get_env(:quack, :test_key)
Config.create(%{ ConfigDB.create(%{
group: ":pleroma", group: ":pleroma",
key: ":test_key", key: ":test_key",
value: [live: 2, com: 3] value: [live: 2, com: 3]
}) })
Config.create(%{ ConfigDB.create(%{
group: ":idna", group: ":idna",
key: ":test_key", key: ":test_key",
value: [live: 15, com: 35] value: [live: 15, com: 35]
}) })
Config.create(%{ ConfigDB.create(%{
group: ":quack", group: ":quack",
key: ":test_key", key: ":test_key",
value: [:test_value1, :test_value2] value: [:test_value1, :test_value2]
@ -48,7 +48,7 @@ defmodule Pleroma.Config.TransferTaskTest do
end end
test "non existing atom" do test "non existing atom" do
Config.create(%{ ConfigDB.create(%{
group: ":pleroma", group: ":pleroma",
key: ":undefined_atom_key", key: ":undefined_atom_key",
value: [live: 2, com: 3] value: [live: 2, com: 3]

View File

@ -394,7 +394,7 @@ defmodule Pleroma.Factory do
end end
def config_factory do def config_factory do
%Pleroma.Web.AdminAPI.Config{ %Pleroma.ConfigDB{
key: key:
sequence(:key, fn key -> sequence(:key, fn key ->
# Atom dynamic registration hack in tests # Atom dynamic registration hack in tests

View File

@ -4,8 +4,8 @@
defmodule Mix.Tasks.Pleroma.ConfigTest do defmodule Mix.Tasks.Pleroma.ConfigTest do
use Pleroma.DataCase use Pleroma.DataCase
alias Pleroma.ConfigDB
alias Pleroma.Repo alias Pleroma.Repo
alias Pleroma.Web.AdminAPI.Config
setup_all do setup_all do
Mix.shell(Mix.Shell.Process) Mix.shell(Mix.Shell.Process)
@ -26,7 +26,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
test "settings are migrated to db" do test "settings are migrated to db" do
initial = Application.get_env(:quack, :level) initial = Application.get_env(:quack, :level)
on_exit(fn -> Application.put_env(:quack, :level, initial) end) on_exit(fn -> Application.put_env(:quack, :level, initial) end)
assert Repo.all(Config) == [] assert Repo.all(ConfigDB) == []
Application.put_env(:pleroma, :first_setting, key: "value", key2: [Repo]) Application.put_env(:pleroma, :first_setting, key: "value", key2: [Repo])
Application.put_env(:pleroma, :second_setting, key: "value2", key2: ["Activity"]) Application.put_env(:pleroma, :second_setting, key: "value2", key2: ["Activity"])
@ -34,14 +34,14 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
Mix.Tasks.Pleroma.Config.run(["migrate_to_db"]) Mix.Tasks.Pleroma.Config.run(["migrate_to_db"])
config1 = Config.get_by_params(%{group: ":pleroma", key: ":first_setting"}) config1 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"})
config2 = Config.get_by_params(%{group: ":pleroma", key: ":second_setting"}) config2 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":second_setting"})
config3 = Config.get_by_params(%{group: ":quack", key: ":level"}) config3 = ConfigDB.get_by_params(%{group: ":quack", key: ":level"})
refute Config.get_by_params(%{group: ":pleroma", key: "Pleroma.Repo"}) refute ConfigDB.get_by_params(%{group: ":pleroma", key: "Pleroma.Repo"})
assert Config.from_binary(config1.value) == [key: "value", key2: [Repo]] assert ConfigDB.from_binary(config1.value) == [key: "value", key2: [Repo]]
assert Config.from_binary(config2.value) == [key: "value2", key2: ["Activity"]] assert ConfigDB.from_binary(config2.value) == [key: "value2", key2: ["Activity"]]
assert Config.from_binary(config3.value) == :info assert ConfigDB.from_binary(config3.value) == :info
end end
describe "with deletion temp file" do describe "with deletion temp file" do
@ -56,23 +56,23 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
end end
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(%{ ConfigDB.create(%{
group: ":pleroma", group: ":pleroma",
key: ":setting_first", key: ":setting_first",
value: [key: "value", key2: ["Activity"]] value: [key: "value", key2: ["Activity"]]
}) })
Config.create(%{ ConfigDB.create(%{
group: ":pleroma", group: ":pleroma",
key: ":setting_second", key: ":setting_second",
value: [key: "value2", key2: [Repo]] value: [key: "value2", key2: [Repo]]
}) })
Config.create(%{group: ":quack", key: ":level", value: :info}) ConfigDB.create(%{group: ":quack", key: ":level", value: :info})
Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "--env", "temp", "-d"]) Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "--env", "temp", "-d"])
assert Repo.all(Config) == [] assert Repo.all(ConfigDB) == []
file = File.read!(temp_file) file = File.read!(temp_file)
assert file =~ "config :pleroma, :setting_first," assert file =~ "config :pleroma, :setting_first,"
@ -81,7 +81,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
end end
test "load a settings with large values and pass to file", %{temp_file: temp_file} do test "load a settings with large values and pass to file", %{temp_file: temp_file} do
Config.create(%{ ConfigDB.create(%{
group: ":pleroma", group: ":pleroma",
key: ":instance", key: ":instance",
value: [ value: [
@ -151,7 +151,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "--env", "temp", "-d"]) Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "--env", "temp", "-d"])
assert Repo.all(Config) == [] assert Repo.all(ConfigDB) == []
assert File.exists?(temp_file) assert File.exists?(temp_file)
{:ok, file} = File.read(temp_file) {:ok, file} = File.read(temp_file)

View File

@ -2832,14 +2832,14 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
test "transfer settings to DB and to file", %{conn: conn} do test "transfer settings to DB and to file", %{conn: conn} do
on_exit(fn -> :ok = File.rm("config/test.exported_from_db.secret.exs") end) on_exit(fn -> :ok = File.rm("config/test.exported_from_db.secret.exs") end)
assert Repo.all(Pleroma.Web.AdminAPI.Config) == [] assert Repo.all(Pleroma.ConfigDB) == []
Mix.Tasks.Pleroma.Config.run(["migrate_to_db"]) Mix.Tasks.Pleroma.Config.run(["migrate_to_db"])
assert Repo.aggregate(Pleroma.Web.AdminAPI.Config, :count, :id) > 0 assert Repo.aggregate(Pleroma.ConfigDB, :count, :id) > 0
conn = get(conn, "/api/pleroma/admin/config/migrate_from_db") conn = get(conn, "/api/pleroma/admin/config/migrate_from_db")
assert json_response(conn, 200) == %{} assert json_response(conn, 200) == %{}
assert Repo.all(Pleroma.Web.AdminAPI.Config) == [] assert Repo.all(Pleroma.ConfigDB) == []
end end
test "returns error if configuration from database is off", %{conn: conn} do test "returns error if configuration from database is off", %{conn: conn} do
@ -2852,7 +2852,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert json_response(conn, 400) == assert json_response(conn, 400) ==
"To use this endpoint you need to enable configuration from database." "To use this endpoint you need to enable configuration from database."
assert Repo.all(Pleroma.Web.AdminAPI.Config) == [] assert Repo.all(Pleroma.ConfigDB) == []
end end
end end