From: Alexander Strizhakov Date: Sat, 7 Mar 2020 09:41:37 +0000 (+0300) Subject: Merge branch 'develop' into gun X-Git-Url: http://git.squeep.com/?a=commitdiff_plain;h=b2eb1124d115beda0907121c3c6f10783b34f352;hp=-c;p=akkoma Merge branch 'develop' into gun --- b2eb1124d115beda0907121c3c6f10783b34f352 diff --combined CHANGELOG.md index cc18f2f99,4f7a9f44c..95918ee60 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@@ -39,6 -39,7 +39,7 @@@ The format is based on [Keep a Changelo - Logger: default log level changed from `warn` to `info`. - Config mix task `migrate_to_db` truncates `config` table before migrating the config file. - Default to `prepare: :unnamed` in the database configuration. + - Instance stats are now loaded on startup instead of being empty until next hourly job.
API Changes @@@ -79,7 -80,6 +80,7 @@@ - User settings: Add _This account is a_ option. - A new users admin digest email - OAuth: admin scopes support (relevant setting: `[:auth, :enforce_oauth_admin_scope_usage]`). +- New HTTP adapter [gun](https://github.com/ninenines/gun). Gun adapter requires minimum OTP version of 22.2 otherwise Pleroma won’t start. For hackney OTP update is not required. - Add an option `authorized_fetch_mode` to require HTTP signatures for AP fetches. - ActivityPub: support for `replies` collection (output for outgoing federation & fetching on incoming federation). - Mix task to refresh counter cache (`mix pleroma.refresh_counter_cache`) diff --combined docs/API/admin_api.md index e3f494795,47afdfba5..be6617e49 --- a/docs/API/admin_api.md +++ b/docs/API/admin_api.md @@@ -278,6 -278,19 +278,19 @@@ Note: Available `:permission_group` is - On failure: `Not found` - On success: JSON array of instance's latest statuses + ## `GET /api/pleroma/admin/statuses` + + ### Retrives all latest statuses + + - Params: + - *optional* `page_size`: number of statuses to return (default is `20`) + - *optional* `local_only`: excludes remote statuses + - *optional* `godmode`: `true`/`false` – allows to see private statuses + - *optional* `with_reblogs`: `true`/`false` – allows to see reblogs (default is false) + - Response: + - On failure: `Not found` + - On success: JSON array of user's latest statuses + ## `POST /api/pleroma/admin/relay` ### Follow a Relay @@@ -751,8 -764,6 +764,8 @@@ Some modifications are necessary to sav Most of the settings will be applied in `runtime`, this means that you don't need to restart the instance. But some settings are applied in `compile time` and require a reboot of the instance, such as: - all settings inside these keys: - `:hackney_pools` + - `:connections_pool` + - `:pools` - `:chat` - partially settings inside these keys: - `:seconds_valid` in `Pleroma.Captcha` diff --combined lib/pleroma/config/transfer_task.ex index 0c2d03ba0,435fc7450..bf1b943d8 --- a/lib/pleroma/config/transfer_task.ex +++ b/lib/pleroma/config/transfer_task.ex @@@ -18,10 -18,7 +18,10 @@@ defmodule Pleroma.Config.TransferTask d {:pleroma, Oban}, {:pleroma, :rate_limit}, {:pleroma, :markup}, - {:plerome, :streamer} + {:pleroma, :streamer}, + {:pleroma, :pools}, + {:pleroma, :connections_pool}, + {:tesla, :adapter} ] @reboot_time_subkeys [ @@@ -45,7 -42,8 +45,8 @@@ @spec load_and_update_env([ConfigDB.t()]) :: :ok | false def load_and_update_env(deleted \\ [], restart_pleroma? \\ true) do - with true <- Pleroma.Config.get(:configurable_from_database), + with {:configurable, true} <- + {:configurable, Pleroma.Config.get(:configurable_from_database)}, true <- Ecto.Adapters.SQL.table_exists?(Repo, "config"), started_applications <- Application.started_applications() do # We need to restart applications for loaded settings take effect @@@ -68,37 -66,18 +69,40 @@@ if :pleroma in applications do List.delete(applications, :pleroma) ++ [:pleroma] else + Restarter.Pleroma.rebooted() applications end Enum.each(applications, &restart(started_applications, &1, Pleroma.Config.get(:env))) :ok + else + {:configurable, false} -> Restarter.Pleroma.rebooted() end end + defp group_for_restart(:logger, key, _, merged_value) do + # change logger configuration in runtime, without restart + if Keyword.keyword?(merged_value) and + key not in [:compile_time_application, :backends, :compile_time_purge_matching] do + Logger.configure_backend(key, merged_value) + else + Logger.configure([{key, merged_value}]) + end + + nil + end + + defp group_for_restart(:tesla, _, _, _), do: :pleroma + + defp group_for_restart(group, _, _, _) when group != :pleroma, do: group + + defp group_for_restart(group, key, value, _) do + if pleroma_need_restart?(group, key, value) do + group + end + end + defp merge_and_update(setting) do try do key = ConfigDB.from_string(setting.key) @@@ -120,7 -99,21 +124,7 @@@ :ok = update_env(group, key, merged_value) - if group != :logger do - if group != :pleroma or pleroma_need_restart?(group, key, value) do - group - end - else - # change logger configuration in runtime, without restart - if Keyword.keyword?(merged_value) and - key not in [:compile_time_application, :backends, :compile_time_purge_matching] do - Logger.configure_backend(key, merged_value) - else - Logger.configure([{key, merged_value}]) - end - - nil - end + group_for_restart(group, key, value, merged_value) rescue error -> error_msg = diff --combined restarter/lib/pleroma.ex index e48bc4d1d,7f08c637c..149a569ce --- a/restarter/lib/pleroma.ex +++ b/restarter/lib/pleroma.ex @@@ -3,11 -3,21 +3,21 @@@ defmodule Restarter.Pleroma d require Logger + @init_state %{need_reboot: false, rebooted: false, after_boot: false} + def start_link(_) do GenServer.start_link(__MODULE__, [], name: __MODULE__) end - def init(_), do: {:ok, %{need_reboot?: false}} + def init(_), do: {:ok, @init_state} + + def rebooted? do + GenServer.call(__MODULE__, :rebooted?) + end + + def rebooted do + GenServer.cast(__MODULE__, :rebooted) + end def need_reboot? do GenServer.call(__MODULE__, :need_reboot?) @@@ -29,41 -39,51 +39,51 @@@ GenServer.cast(__MODULE__, {:after_boot, env}) end + def handle_call(:rebooted?, _from, state) do + {:reply, state[:rebooted], state} + end + def handle_call(:need_reboot?, _from, state) do - {:reply, state[:need_reboot?], state} + {:reply, state[:need_reboot], state} end - def handle_cast(:refresh, _state) do - {:noreply, %{need_reboot?: false}} + def handle_cast(:rebooted, state) do + {:noreply, Map.put(state, :rebooted, true)} end - def handle_cast(:need_reboot, %{need_reboot?: true} = state), do: {:noreply, state} + def handle_cast(:need_reboot, %{need_reboot: true} = state), do: {:noreply, state} def handle_cast(:need_reboot, state) do - {:noreply, Map.put(state, :need_reboot?, true)} + {:noreply, Map.put(state, :need_reboot, true)} + end + + def handle_cast(:refresh, _state) do + {:noreply, @init_state} end def handle_cast({:restart, :test, _}, state) do - Logger.warn("pleroma restarted") + Logger.debug("pleroma manually restarted") - {:noreply, Map.put(state, :need_reboot?, false)} + {:noreply, Map.put(state, :need_reboot, false)} end def handle_cast({:restart, _, delay}, state) do Process.sleep(delay) do_restart(:pleroma) - {:noreply, Map.put(state, :need_reboot?, false)} + {:noreply, Map.put(state, :need_reboot, false)} end def handle_cast({:after_boot, _}, %{after_boot: true} = state), do: {:noreply, state} def handle_cast({:after_boot, :test}, state) do - Logger.warn("pleroma restarted") + Logger.debug("pleroma restarted after boot") - {:noreply, Map.put(state, :after_boot, true)} + state = %{state | after_boot: true, rebooted: true} + {:noreply, state} end def handle_cast({:after_boot, _}, state) do do_restart(:pleroma) - {:noreply, Map.put(state, :after_boot, true)} + state = %{state | after_boot: true, rebooted: true} + {:noreply, state} end defp do_restart(app) do diff --combined test/web/admin_api/admin_api_controller_test.exs index 3b73525af,8009d4386..d6b839948 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@@ -1880,10 -1880,10 +1880,10 @@@ defmodule Pleroma.Web.AdminAPI.AdminAPI "@#{admin.nickname} deleted status ##{id}" end - test "returns error when status is not exist", %{conn: conn} do + test "returns 404 when the status does not exist", %{conn: conn} do conn = delete(conn, "/api/pleroma/admin/statuses/test") - assert json_response(conn, :bad_request) == "Could not delete" + assert json_response(conn, :not_found) == "Not found" end end @@@ -2513,8 -2513,7 +2513,8 @@@ "value" => "Tesla.Adapter.Httpc", "db" => [":adapter"] } - ] + ], + "need_reboot" => true } end @@@ -2601,6 -2600,7 +2601,6 @@@ %{"tuple" => [":seconds_valid", 60]}, %{"tuple" => [":path", ""]}, %{"tuple" => [":key1", nil]}, - %{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]}, %{"tuple" => [":regex1", "~r/https:\/\/example.com/"]}, %{"tuple" => [":regex2", "~r/https:\/\/example.com/u"]}, %{"tuple" => [":regex3", "~r/https:\/\/example.com/i"]}, @@@ -2630,6 -2630,7 +2630,6 @@@ %{"tuple" => [":seconds_valid", 60]}, %{"tuple" => [":path", ""]}, %{"tuple" => [":key1", nil]}, - %{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]}, %{"tuple" => [":regex1", "~r/https:\\/\\/example.com/"]}, %{"tuple" => [":regex2", "~r/https:\\/\\/example.com/u"]}, %{"tuple" => [":regex3", "~r/https:\\/\\/example.com/i"]}, @@@ -2642,6 -2643,7 +2642,6 @@@ ":seconds_valid", ":path", ":key1", - ":partial_chain", ":regex1", ":regex2", ":regex3", @@@ -2655,8 -2657,7 +2655,8 @@@ "value" => "Tesla.Adapter.Httpc", "db" => [":adapter"] } - ] + ], + "need_reboot" => true } end