forked from mirrors/akkoma
Revert guards on string_to_elixir_types/1, remove unnecessary assignment in test
This commit is contained in:
parent
c3b8c77967
commit
f95b52255b
2 changed files with 8 additions and 13 deletions
|
@ -141,9 +141,7 @@ defmodule Pleroma.ConfigDB do
|
||||||
@spec update_or_create(map()) :: {:ok, ConfigDB.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
|
||||||
params = Map.put(params, :value, to_elixir_types(params[:value]))
|
params = Map.put(params, :value, to_elixir_types(params[:value]))
|
||||||
|
search_opts = Map.take(params, [:group, :key])
|
||||||
search_opts =
|
|
||||||
Map.take(params, [:group, :key]) |> Map.update!(:key, &string_to_elixir_types(&1))
|
|
||||||
|
|
||||||
with %ConfigDB{} = config <- ConfigDB.get_by_params(search_opts),
|
with %ConfigDB{} = config <- ConfigDB.get_by_params(search_opts),
|
||||||
{_, true, config} <- {:partial_update, can_be_partially_updated?(config), config},
|
{_, true, config} <- {:partial_update, can_be_partially_updated?(config), config},
|
||||||
|
@ -327,7 +325,7 @@ defmodule Pleroma.ConfigDB do
|
||||||
|
|
||||||
@spec string_to_elixir_types(String.t()) ::
|
@spec string_to_elixir_types(String.t()) ::
|
||||||
atom() | Regex.t() | module() | String.t() | no_return()
|
atom() | Regex.t() | module() | String.t() | no_return()
|
||||||
def string_to_elixir_types("~r" <> _pattern = regex) when is_binary(regex) do
|
def string_to_elixir_types("~r" <> _pattern = regex) do
|
||||||
pattern =
|
pattern =
|
||||||
~r/^~r(?'delimiter'[\/|"'([{<]{1})(?'pattern'.+)[\/|"')\]}>]{1}(?'modifier'[uismxfU]*)/u
|
~r/^~r(?'delimiter'[\/|"'([{<]{1})(?'pattern'.+)[\/|"')\]}>]{1}(?'modifier'[uismxfU]*)/u
|
||||||
|
|
||||||
|
@ -341,9 +339,9 @@ defmodule Pleroma.ConfigDB do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def string_to_elixir_types(":" <> atom) when is_binary(atom), do: String.to_atom(atom)
|
def string_to_elixir_types(":" <> atom), do: String.to_atom(atom)
|
||||||
|
|
||||||
def string_to_elixir_types(value) when is_binary(value) do
|
def string_to_elixir_types(value) do
|
||||||
if module_name?(value) do
|
if module_name?(value) do
|
||||||
String.to_existing_atom("Elixir." <> value)
|
String.to_existing_atom("Elixir." <> value)
|
||||||
else
|
else
|
||||||
|
@ -351,8 +349,6 @@ defmodule Pleroma.ConfigDB do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def string_to_elixir_types(value) when is_atom(value), do: value
|
|
||||||
|
|
||||||
defp parse_host("localhost"), do: :localhost
|
defp parse_host("localhost"), do: :localhost
|
||||||
|
|
||||||
defp parse_host(host) do
|
defp parse_host(host) do
|
||||||
|
|
|
@ -1481,11 +1481,10 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
_res =
|
assert conn
|
||||||
assert conn
|
|> put_req_header("content-type", "application/json")
|
||||||
|> put_req_header("content-type", "application/json")
|
|> post("/api/pleroma/admin/config", %{"configs" => [params]})
|
||||||
|> post("/api/pleroma/admin/config", %{"configs" => [params]})
|
|> json_response_and_validate_schema(200)
|
||||||
|> json_response_and_validate_schema(200)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue