Merge branch 'admin-config-fix' into 'develop'
Admin config fix See merge request pleroma/pleroma!1471
This commit is contained in:
commit
5230b9ef3d
@ -564,6 +564,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
|||||||
|
|
||||||
## `/api/pleroma/admin/config`
|
## `/api/pleroma/admin/config`
|
||||||
### List config settings
|
### List config settings
|
||||||
|
List config settings only works with `:pleroma => :instance => :dynamic_configuration` setting to `true`.
|
||||||
- Method `GET`
|
- Method `GET`
|
||||||
- Params: none
|
- Params: none
|
||||||
- Response:
|
- Response:
|
||||||
@ -582,6 +583,7 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
|||||||
|
|
||||||
## `/api/pleroma/admin/config`
|
## `/api/pleroma/admin/config`
|
||||||
### Update config settings
|
### Update config settings
|
||||||
|
Updating config settings only works with `:pleroma => :instance => :dynamic_configuration` setting to `true`.
|
||||||
Module name can be passed as string, which starts with `Pleroma`, e.g. `"Pleroma.Upload"`.
|
Module name can be passed as string, which starts with `Pleroma`, e.g. `"Pleroma.Upload"`.
|
||||||
Atom keys and values can be passed with `:` in the beginning, e.g. `":upload"`.
|
Atom keys and values can be passed with `:` in the beginning, e.g. `":upload"`.
|
||||||
Tuples can be passed as `{"tuple": ["first_val", Pleroma.Module, []]}`.
|
Tuples can be passed as `{"tuple": ["first_val", Pleroma.Module, []]}`.
|
||||||
|
@ -84,6 +84,7 @@ defmodule Pleroma.Web.AdminAPI.Config do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defp do_convert({:dispatch, [entity]}), do: %{"tuple" => [":dispatch", [inspect(entity)]]}
|
defp do_convert({:dispatch, [entity]}), do: %{"tuple" => [":dispatch", [inspect(entity)]]}
|
||||||
|
defp do_convert({:partial_chain, entity}), do: %{"tuple" => [":partial_chain", inspect(entity)]}
|
||||||
|
|
||||||
defp do_convert(entity) when is_tuple(entity),
|
defp do_convert(entity) when is_tuple(entity),
|
||||||
do: %{"tuple" => do_convert(Tuple.to_list(entity))}
|
do: %{"tuple" => do_convert(Tuple.to_list(entity))}
|
||||||
@ -113,11 +114,15 @@ defmodule Pleroma.Web.AdminAPI.Config do
|
|||||||
defp do_transform(%Regex{} = entity) when is_map(entity), do: entity
|
defp do_transform(%Regex{} = entity) when is_map(entity), do: entity
|
||||||
|
|
||||||
defp do_transform(%{"tuple" => [":dispatch", [entity]]}) do
|
defp do_transform(%{"tuple" => [":dispatch", [entity]]}) do
|
||||||
cleaned_string = String.replace(entity, ~r/[^\w|^{:,[|^,|^[|^\]^}|^\/|^\.|^"]^\s/, "")
|
{dispatch_settings, []} = do_eval(entity)
|
||||||
{dispatch_settings, []} = Code.eval_string(cleaned_string, [], requires: [], macros: [])
|
|
||||||
{:dispatch, [dispatch_settings]}
|
{:dispatch, [dispatch_settings]}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp do_transform(%{"tuple" => [":partial_chain", entity]}) do
|
||||||
|
{partial_chain, []} = do_eval(entity)
|
||||||
|
{:partial_chain, partial_chain}
|
||||||
|
end
|
||||||
|
|
||||||
defp do_transform(%{"tuple" => entity}) do
|
defp do_transform(%{"tuple" => entity}) do
|
||||||
Enum.reduce(entity, {}, fn val, acc -> Tuple.append(acc, do_transform(val)) end)
|
Enum.reduce(entity, {}, fn val, acc -> Tuple.append(acc, do_transform(val)) end)
|
||||||
end
|
end
|
||||||
@ -149,4 +154,9 @@ defmodule Pleroma.Web.AdminAPI.Config do
|
|||||||
do: String.to_existing_atom("Elixir." <> value),
|
do: String.to_existing_atom("Elixir." <> value),
|
||||||
else: value
|
else: value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp do_eval(entity) do
|
||||||
|
cleaned_string = String.replace(entity, ~r/[^\w|^{:,[|^,|^[|^\]^}|^\/|^\.|^"]^\s/, "")
|
||||||
|
Code.eval_string(cleaned_string, [], requires: [], macros: [])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -1571,7 +1571,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||||||
%{"tuple" => [":method", "Pleroma.Captcha.Kocaptcha"]},
|
%{"tuple" => [":method", "Pleroma.Captcha.Kocaptcha"]},
|
||||||
%{"tuple" => [":seconds_valid", 60]},
|
%{"tuple" => [":seconds_valid", 60]},
|
||||||
%{"tuple" => [":path", ""]},
|
%{"tuple" => [":path", ""]},
|
||||||
%{"tuple" => [":key1", nil]}
|
%{"tuple" => [":key1", nil]},
|
||||||
|
%{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -1587,7 +1588,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||||||
%{"tuple" => [":method", "Pleroma.Captcha.Kocaptcha"]},
|
%{"tuple" => [":method", "Pleroma.Captcha.Kocaptcha"]},
|
||||||
%{"tuple" => [":seconds_valid", 60]},
|
%{"tuple" => [":seconds_valid", 60]},
|
||||||
%{"tuple" => [":path", ""]},
|
%{"tuple" => [":path", ""]},
|
||||||
%{"tuple" => [":key1", nil]}
|
%{"tuple" => [":key1", nil]},
|
||||||
|
%{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -238,6 +238,14 @@ defmodule Pleroma.Web.AdminAPI.ConfigTest do
|
|||||||
assert Config.from_binary(binary) == [key: "value"]
|
assert Config.from_binary(binary) == [key: "value"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "keyword with partial_chain key" do
|
||||||
|
binary =
|
||||||
|
Config.transform([%{"tuple" => [":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]
|
||||||
|
end
|
||||||
|
|
||||||
test "keyword" do
|
test "keyword" do
|
||||||
binary =
|
binary =
|
||||||
Config.transform([
|
Config.transform([
|
||||||
|
Loading…
Reference in New Issue
Block a user