forked from AkkomaGang/akkoma
Merge branch 'feature/1677-need_reboot-flag-endpoint' into 'develop'
Added need_reboot endpoint to admin api Closes #1677 See merge request pleroma/pleroma!2373
This commit is contained in:
parent
a4afeed426
commit
fb9ec885cc
4 changed files with 46 additions and 29 deletions
|
@ -773,6 +773,8 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
||||||
|
|
||||||
### Restarts pleroma application
|
### Restarts pleroma application
|
||||||
|
|
||||||
|
**Only works when configuration from database is enabled.**
|
||||||
|
|
||||||
- Params: none
|
- Params: none
|
||||||
- Response:
|
- Response:
|
||||||
- On failure:
|
- On failure:
|
||||||
|
@ -782,11 +784,24 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
||||||
{}
|
{}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## `GET /api/pleroma/admin/need_reboot`
|
||||||
|
|
||||||
|
### Returns the flag whether the pleroma should be restarted
|
||||||
|
|
||||||
|
- Params: none
|
||||||
|
- Response:
|
||||||
|
- `need_reboot` - boolean
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"need_reboot": false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## `GET /api/pleroma/admin/config`
|
## `GET /api/pleroma/admin/config`
|
||||||
|
|
||||||
### Get list of merged default settings with saved in database.
|
### Get list of merged default settings with saved in database.
|
||||||
|
|
||||||
*If `need_reboot` flag exists in response, instance must be restarted, so reboot time settings can take effect.*
|
*If `need_reboot` is `true`, instance must be restarted, so reboot time settings can take effect.*
|
||||||
|
|
||||||
**Only works when configuration from database is enabled.**
|
**Only works when configuration from database is enabled.**
|
||||||
|
|
||||||
|
@ -808,13 +823,12 @@ Note: Available `:permission_group` is currently moderator and admin. 404 is ret
|
||||||
"need_reboot": true
|
"need_reboot": true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
need_reboot - *optional*, if were changed reboot time settings.
|
|
||||||
|
|
||||||
## `POST /api/pleroma/admin/config`
|
## `POST /api/pleroma/admin/config`
|
||||||
|
|
||||||
### Update config settings
|
### Update config settings
|
||||||
|
|
||||||
*If `need_reboot` flag exists in response, instance must be restarted, so reboot time settings can take effect.*
|
*If `need_reboot` is `true`, instance must be restarted, so reboot time settings can take effect.*
|
||||||
|
|
||||||
**Only works when configuration from database is enabled.**
|
**Only works when configuration from database is enabled.**
|
||||||
|
|
||||||
|
@ -956,7 +970,6 @@ config :quack,
|
||||||
"need_reboot": true
|
"need_reboot": true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
need_reboot - *optional*, if were changed reboot time settings.
|
|
||||||
|
|
||||||
## ` GET /api/pleroma/admin/config/descriptions`
|
## ` GET /api/pleroma/admin/config/descriptions`
|
||||||
|
|
||||||
|
|
|
@ -911,16 +911,7 @@ def config_show(conn, _params) do
|
||||||
end)
|
end)
|
||||||
|> List.flatten()
|
|> List.flatten()
|
||||||
|
|
||||||
response = %{configs: merged}
|
json(conn, %{configs: merged, need_reboot: Restarter.Pleroma.need_reboot?()})
|
||||||
|
|
||||||
response =
|
|
||||||
if Restarter.Pleroma.need_reboot?() do
|
|
||||||
Map.put(response, :need_reboot, true)
|
|
||||||
else
|
|
||||||
response
|
|
||||||
end
|
|
||||||
|
|
||||||
json(conn, response)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -947,28 +938,22 @@ def config_update(conn, %{"configs" => configs}) do
|
||||||
|
|
||||||
Config.TransferTask.load_and_update_env(deleted, false)
|
Config.TransferTask.load_and_update_env(deleted, false)
|
||||||
|
|
||||||
need_reboot? =
|
if !Restarter.Pleroma.need_reboot?() do
|
||||||
Restarter.Pleroma.need_reboot?() ||
|
changed_reboot_settings? =
|
||||||
Enum.any?(updated, fn config ->
|
(updated ++ deleted)
|
||||||
|
|> Enum.any?(fn config ->
|
||||||
group = ConfigDB.from_string(config.group)
|
group = ConfigDB.from_string(config.group)
|
||||||
key = ConfigDB.from_string(config.key)
|
key = ConfigDB.from_string(config.key)
|
||||||
value = ConfigDB.from_binary(config.value)
|
value = ConfigDB.from_binary(config.value)
|
||||||
Config.TransferTask.pleroma_need_restart?(group, key, value)
|
Config.TransferTask.pleroma_need_restart?(group, key, value)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
response = %{configs: updated}
|
if changed_reboot_settings?, do: Restarter.Pleroma.need_reboot()
|
||||||
|
|
||||||
response =
|
|
||||||
if need_reboot? do
|
|
||||||
Restarter.Pleroma.need_reboot()
|
|
||||||
Map.put(response, :need_reboot, need_reboot?)
|
|
||||||
else
|
|
||||||
response
|
|
||||||
end
|
end
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_view(ConfigView)
|
|> put_view(ConfigView)
|
||||||
|> render("index.json", response)
|
|> render("index.json", %{configs: updated, need_reboot: Restarter.Pleroma.need_reboot?()})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -980,6 +965,10 @@ def restart(conn, _params) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def need_reboot(conn, _params) do
|
||||||
|
json(conn, %{need_reboot: Restarter.Pleroma.need_reboot?()})
|
||||||
|
end
|
||||||
|
|
||||||
defp configurable_from_database(conn) do
|
defp configurable_from_database(conn) do
|
||||||
if Config.get(:configurable_from_database) do
|
if Config.get(:configurable_from_database) do
|
||||||
:ok
|
:ok
|
||||||
|
|
|
@ -200,6 +200,7 @@ defmodule Pleroma.Web.Router do
|
||||||
get("/config", AdminAPIController, :config_show)
|
get("/config", AdminAPIController, :config_show)
|
||||||
post("/config", AdminAPIController, :config_update)
|
post("/config", AdminAPIController, :config_update)
|
||||||
get("/config/descriptions", AdminAPIController, :config_descriptions)
|
get("/config/descriptions", AdminAPIController, :config_descriptions)
|
||||||
|
get("/need_reboot", AdminAPIController, :need_reboot)
|
||||||
get("/restart", AdminAPIController, :restart)
|
get("/restart", AdminAPIController, :restart)
|
||||||
|
|
||||||
get("/moderation_log", AdminAPIController, :list_log)
|
get("/moderation_log", AdminAPIController, :list_log)
|
||||||
|
|
|
@ -2291,7 +2291,7 @@ test "saving config which need pleroma reboot", %{conn: conn} do
|
||||||
|> get("/api/pleroma/admin/config")
|
|> get("/api/pleroma/admin/config")
|
||||||
|> json_response(200)
|
|> json_response(200)
|
||||||
|
|
||||||
refute Map.has_key?(configs, "need_reboot")
|
assert configs["need_reboot"] == false
|
||||||
end
|
end
|
||||||
|
|
||||||
test "update setting which need reboot, don't change reboot flag until reboot", %{conn: conn} do
|
test "update setting which need reboot, don't change reboot flag until reboot", %{conn: conn} do
|
||||||
|
@ -2347,7 +2347,7 @@ test "update setting which need reboot, don't change reboot flag until reboot",
|
||||||
|> get("/api/pleroma/admin/config")
|
|> get("/api/pleroma/admin/config")
|
||||||
|> json_response(200)
|
|> json_response(200)
|
||||||
|
|
||||||
refute Map.has_key?(configs, "need_reboot")
|
assert configs["need_reboot"] == false
|
||||||
end
|
end
|
||||||
|
|
||||||
test "saving config with nested merge", %{conn: conn} do
|
test "saving config with nested merge", %{conn: conn} do
|
||||||
|
@ -3065,6 +3065,20 @@ test "pleroma restarts", %{conn: conn} do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "need_reboot flag", %{conn: conn} do
|
||||||
|
assert conn
|
||||||
|
|> get("/api/pleroma/admin/need_reboot")
|
||||||
|
|> json_response(200) == %{"need_reboot" => false}
|
||||||
|
|
||||||
|
Restarter.Pleroma.need_reboot()
|
||||||
|
|
||||||
|
assert conn
|
||||||
|
|> get("/api/pleroma/admin/need_reboot")
|
||||||
|
|> json_response(200) == %{"need_reboot" => true}
|
||||||
|
|
||||||
|
on_exit(fn -> Restarter.Pleroma.refresh() end)
|
||||||
|
end
|
||||||
|
|
||||||
describe "GET /api/pleroma/admin/statuses" do
|
describe "GET /api/pleroma/admin/statuses" do
|
||||||
test "returns all public, unlisted, and direct statuses", %{conn: conn, admin: admin} do
|
test "returns all public, unlisted, and direct statuses", %{conn: conn, admin: admin} do
|
||||||
blocked = insert(:user)
|
blocked = insert(:user)
|
||||||
|
|
Loading…
Reference in a new issue