Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into reject

This commit is contained in:
lain 2020-08-12 12:53:04 +02:00
commit bb92ad44a6
5 changed files with 44 additions and 10 deletions

View File

@ -15,8 +15,8 @@ defmodule Pleroma.JobQueueMonitor do
@impl true
def init(state) do
:telemetry.attach("oban-monitor-failure", [:oban, :failure], &handle_event/4, nil)
:telemetry.attach("oban-monitor-success", [:oban, :success], &handle_event/4, nil)
:telemetry.attach("oban-monitor-failure", [:oban, :job, :exception], &handle_event/4, nil)
:telemetry.attach("oban-monitor-success", [:oban, :job, :stop], &handle_event/4, nil)
{:ok, state}
end
@ -25,8 +25,11 @@ defmodule Pleroma.JobQueueMonitor do
GenServer.call(__MODULE__, :stats)
end
def handle_event([:oban, status], %{duration: duration}, meta, _) do
GenServer.cast(__MODULE__, {:process_event, status, duration, meta})
def handle_event([:oban, :job, event], %{duration: duration}, meta, _) do
GenServer.cast(
__MODULE__,
{:process_event, mapping_status(event), duration, meta}
)
end
@impl true
@ -75,4 +78,7 @@ defmodule Pleroma.JobQueueMonitor do
|> Map.update!(:processed_jobs, &(&1 + 1))
|> Map.update!(status, &(&1 + 1))
end
defp mapping_status(:stop), do: :success
defp mapping_status(:exception), do: :failure
end

View File

@ -18,6 +18,12 @@ defmodule Pleroma.Web.ControllerHelper do
def truthy_param?(value), do: not falsy_param?(value)
def json_response(conn, status, _) when status in [204, :no_content] do
conn
|> put_resp_header("content-type", "application/json")
|> send_resp(status, "")
end
def json_response(conn, status, json) do
conn
|> put_status(status)

View File

@ -0,0 +1,15 @@
defmodule Pleroma.Repo.Migrations.SetDefaultsToUserApprovalPending do
use Ecto.Migration
def up do
execute("UPDATE users SET approval_pending = false WHERE approval_pending IS NULL")
alter table(:users) do
modify(:approval_pending, :boolean, default: false, null: false)
end
end
def down do
:ok
end
end

View File

@ -56,6 +56,13 @@ defmodule Pleroma.Web.ConnCase do
[conn: conn]
end
defp empty_json_response(conn) do
body = response(conn, 204)
response_content_type(conn, :json)
body
end
defp json_response_and_validate_schema(
%{
private: %{
@ -79,7 +86,7 @@ defmodule Pleroma.Web.ConnCase do
end
schema = lookup[op_id].responses[status].content[content_type].schema
json = json_response(conn, status)
json = if status == 204, do: empty_json_response(conn), else: json_response(conn, status)
case OpenApiSpex.cast_value(json, schema, spec) do
{:ok, _data} ->

View File

@ -439,7 +439,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
user1: user1,
user2: user2
} do
assert json_response(conn, :no_content)
assert empty_json_response(conn)
assert User.get_cached_by_id(user1.id).tags == ["x", "foo", "bar"]
assert User.get_cached_by_id(user2.id).tags == ["y", "foo", "bar"]
@ -457,7 +457,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
end
test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do
assert json_response(conn, :no_content)
assert empty_json_response(conn)
assert User.get_cached_by_id(user3.id).tags == ["unchanged"]
end
end
@ -485,7 +485,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
user1: user1,
user2: user2
} do
assert json_response(conn, :no_content)
assert empty_json_response(conn)
assert User.get_cached_by_id(user1.id).tags == []
assert User.get_cached_by_id(user2.id).tags == ["y"]
@ -503,7 +503,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
end
test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do
assert json_response(conn, :no_content)
assert empty_json_response(conn)
assert User.get_cached_by_id(user3.id).tags == ["unchanged"]
end
end
@ -1777,7 +1777,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
conn =
patch(conn, "/api/pleroma/admin/users/force_password_reset", %{nicknames: [user.nickname]})
assert json_response(conn, 204) == ""
assert empty_json_response(conn) == ""
ObanHelpers.perform_all()