plug(
OAuthScopesPlug,
%{scopes: ["read"], admin: true}
- when action in [:config_show, :migrate_to_db, :migrate_from_db, :list_log]
+ when action in [:config_show, :migrate_from_db, :list_log]
)
plug(
|> render("index.json", %{log: log})
end
- def migrate_to_db(conn, _params) do
- Mix.Tasks.Pleroma.Config.run(["migrate_to_db"])
- json(conn, %{})
- end
-
- def migrate_from_db(conn, _params) do
- Mix.Tasks.Pleroma.Config.run([
- "migrate_from_db",
- "--env",
- to_string(Pleroma.Config.get(:env)),
- "-d"
- ])
-
- json(conn, %{})
- end
-
def config_descriptions(conn, _params) do
conn
|> Plug.Conn.put_resp_content_type("application/json")
|> Plug.Conn.send_resp(200, @descriptions_json)
end
- def config_show(conn, _params) do
- configs = Pleroma.Repo.all(Config)
+ def migrate_from_db(conn, _params) do
+ with :ok <- configurable_from_database(conn) do
+ Mix.Tasks.Pleroma.Config.run([
+ "migrate_from_db",
+ "--env",
+ to_string(Pleroma.Config.get(:env)),
+ "-d"
+ ])
- conn
- |> put_view(ConfigView)
- |> render("index.json", %{configs: configs})
+ json(conn, %{})
+ end
end
- def config_update(conn, %{"configs" => configs}) do
- updated =
- if Pleroma.Config.get([:instance, :dynamic_configuration]) do
- updated =
- Enum.map(configs, fn
- %{"group" => group, "key" => key, "delete" => "true"} = params ->
- with {:ok, config} <-
- Config.delete(%{group: group, key: key, subkeys: params["subkeys"]}) do
- config
- end
-
- %{"group" => group, "key" => key, "value" => value} ->
- with {:ok, config} <-
- Config.update_or_create(%{group: group, key: key, value: value}) do
- config
- end
- end)
- |> Enum.reject(&is_nil(&1))
-
- Pleroma.Config.TransferTask.load_and_update_env()
-
- Mix.Tasks.Pleroma.Config.run([
- "migrate_from_db",
- "--env",
- to_string(Pleroma.Config.get(:env))
- ])
-
- updated
+ def config_show(conn, _params) do
+ with :ok <- configurable_from_database(conn) do
+ configs = Pleroma.Repo.all(Config)
+
+ if configs == [] do
+ errors(
+ conn,
+ {:error, "To use configuration from database migrate your settings to database."}
+ )
else
- []
+ conn
+ |> put_view(ConfigView)
+ |> render("index.json", %{configs: configs})
end
+ end
+ end
- conn
- |> put_view(ConfigView)
- |> render("index.json", %{configs: updated})
+ def config_update(conn, %{"configs" => configs}) do
+ with :ok <- configurable_from_database(conn) do
+ updated =
+ Enum.map(configs, fn
+ %{"group" => group, "key" => key, "delete" => true} = params ->
+ with {:ok, config} <-
+ Config.delete(%{group: group, key: key, subkeys: params["subkeys"]}) do
+ config
+ end
+
+ %{"group" => group, "key" => key, "value" => value} ->
+ with {:ok, config} <-
+ Config.update_or_create(%{group: group, key: key, value: value}) do
+ config
+ end
+ end)
+ |> Enum.reject(&is_nil(&1))
+
+ Pleroma.Config.TransferTask.load_and_update_env()
+
+ Mix.Tasks.Pleroma.Config.run([
+ "migrate_from_db",
+ "--env",
+ to_string(Pleroma.Config.get(:env))
+ ])
+
+ conn
+ |> put_view(ConfigView)
+ |> render("index.json", %{configs: updated})
+ end
+ end
+
+ defp configurable_from_database(conn) do
+ if Pleroma.Config.get(:configurable_from_database) do
+ :ok
+ else
+ errors(
+ conn,
+ {:error, "To use this endpoint you need to enable configuration from database."}
+ )
+ end
end
def reload_emoji(conn, _params) do