Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into fix/activity-expirations-again

This commit is contained in:
lain 2020-08-11 17:49:24 +02:00
commit 0589e9156a
5 changed files with 56 additions and 6 deletions

View file

@ -130,6 +130,7 @@ defmodule Pleroma.User.Query do
defp compose_query({:active, _}, query) do defp compose_query({:active, _}, query) do
User.restrict_deactivated(query) User.restrict_deactivated(query)
|> where([u], not is_nil(u.nickname)) |> where([u], not is_nil(u.nickname))
|> where([u], u.approval_pending == false)
end end
defp compose_query({:legacy_active, _}, query) do defp compose_query({:legacy_active, _}, query) do

View file

@ -18,6 +18,12 @@ defmodule Pleroma.Web.ControllerHelper do
def truthy_param?(value), do: not falsy_param?(value) 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 def json_response(conn, status, json) do
conn conn
|> put_status(status) |> 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] [conn: conn]
end end
defp empty_json_response(conn) do
body = response(conn, 204)
response_content_type(conn, :json)
body
end
defp json_response_and_validate_schema( defp json_response_and_validate_schema(
%{ %{
private: %{ private: %{
@ -79,7 +86,7 @@ defmodule Pleroma.Web.ConnCase do
end end
schema = lookup[op_id].responses[status].content[content_type].schema 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 case OpenApiSpex.cast_value(json, schema, spec) do
{:ok, _data} -> {:ok, _data} ->

View file

@ -439,7 +439,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
user1: user1, user1: user1,
user2: user2 user2: user2
} do } 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(user1.id).tags == ["x", "foo", "bar"]
assert User.get_cached_by_id(user2.id).tags == ["y", "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 end
test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do 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"] assert User.get_cached_by_id(user3.id).tags == ["unchanged"]
end end
end end
@ -485,7 +485,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
user1: user1, user1: user1,
user2: user2 user2: user2
} do } 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(user1.id).tags == []
assert User.get_cached_by_id(user2.id).tags == ["y"] assert User.get_cached_by_id(user2.id).tags == ["y"]
@ -503,7 +503,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
end end
test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do 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"] assert User.get_cached_by_id(user3.id).tags == ["unchanged"]
end end
end end
@ -1164,6 +1164,27 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
} }
end end
test "`active` filters out users pending approval", %{token: token} do
insert(:user, approval_pending: true)
%{id: user_id} = insert(:user, approval_pending: false)
%{id: admin_id} = token.user
conn =
build_conn()
|> assign(:user, token.user)
|> assign(:token, token)
|> get("/api/pleroma/admin/users?filters=active")
assert %{
"count" => 2,
"page_size" => 50,
"users" => [
%{"id" => ^admin_id},
%{"id" => ^user_id}
]
} = json_response(conn, 200)
end
test "it works with multiple filters" do test "it works with multiple filters" do
admin = insert(:user, nickname: "john", is_admin: true) admin = insert(:user, nickname: "john", is_admin: true)
token = insert(:oauth_admin_token, user: admin) token = insert(:oauth_admin_token, user: admin)
@ -1756,7 +1777,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
conn = conn =
patch(conn, "/api/pleroma/admin/users/force_password_reset", %{nicknames: [user.nickname]}) 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() ObanHelpers.perform_all()