mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-23 13:44:58 +00:00
Do not crash on invalid atom in configDB
This commit is contained in:
parent
4a78c431cf
commit
af7c3fab98
4 changed files with 15 additions and 1 deletions
|
@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
|
||||
### Fixed
|
||||
- /api/v1/accounts/lookup will now respect restrict\_unauthenticated
|
||||
- Unknown atoms in the config DB will no longer crash akkoma on boot
|
||||
|
||||
### Upgrade notes
|
||||
- Ensure `config :tesla, :adapter` is either unset, or set to `{Tesla.Adapter.Finch, name: MyFinch}` in your .exs config
|
||||
|
|
|
@ -42,6 +42,7 @@ defmodule Pleroma.Config.TransferTask do
|
|||
# We need to restart applications for loaded settings take effect
|
||||
{logger, other} =
|
||||
(Repo.all(ConfigDB) ++ deleted_settings)
|
||||
|> Enum.reject(&invalid_key_or_group/1)
|
||||
|> Enum.map(&merge_with_default/1)
|
||||
|> Enum.split_with(fn {group, _, _, _} -> group == :logger end)
|
||||
|
||||
|
@ -85,6 +86,10 @@ defmodule Pleroma.Config.TransferTask do
|
|||
end
|
||||
end
|
||||
|
||||
defp invalid_key_or_group(%ConfigDB{key: :invalid_atom}), do: true
|
||||
defp invalid_key_or_group(%ConfigDB{group: :invalid_atom}), do: true
|
||||
defp invalid_key_or_group(_), do: false
|
||||
|
||||
defp merge_with_default(%{group: group, key: key, value: value} = setting) do
|
||||
default =
|
||||
if group == :pleroma do
|
||||
|
|
|
@ -342,7 +342,11 @@ defmodule Pleroma.ConfigDB do
|
|||
|
||||
def string_to_elixir_types(value) do
|
||||
if module_name?(value) do
|
||||
String.to_existing_atom("Elixir." <> value)
|
||||
try do
|
||||
String.to_existing_atom("Elixir." <> value)
|
||||
rescue
|
||||
ArgumentError -> :invalid_atom
|
||||
end
|
||||
else
|
||||
value
|
||||
end
|
||||
|
|
|
@ -227,6 +227,10 @@ defmodule Pleroma.ConfigDBTest do
|
|||
assert ConfigDB.to_elixir_types("Pleroma.Bookmark") == Pleroma.Bookmark
|
||||
end
|
||||
|
||||
test "removed module" do
|
||||
assert ConfigDB.to_elixir_types("Pleroma.Nowhere") == :invalid_atom
|
||||
end
|
||||
|
||||
test "pleroma string" do
|
||||
assert ConfigDB.to_elixir_types("Pleroma") == "Pleroma"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue