forked from AkkomaGang/akkoma
Merge branch 'admin-api-users-sort' into 'develop'
AdminAPI: sort new users at the top Closes #2709 See merge request pleroma/pleroma!3481
This commit is contained in:
commit
3f58213646
4 changed files with 59 additions and 71 deletions
|
@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- HTTPSecurityPlug now sends a response header to opt out of Google's FLoC (Federated Learning of Cohorts) targeted advertising.
|
- HTTPSecurityPlug now sends a response header to opt out of Google's FLoC (Federated Learning of Cohorts) targeted advertising.
|
||||||
- Email address is now returned if requesting user is the owner of the user account so it can be exposed in client and FE user settings UIs.
|
- Email address is now returned if requesting user is the owner of the user account so it can be exposed in client and FE user settings UIs.
|
||||||
- Improved Twittercard and OpenGraph meta tag generation including thumbnails and image dimension metadata when available.
|
- Improved Twittercard and OpenGraph meta tag generation including thumbnails and image dimension metadata when available.
|
||||||
|
- AdminAPI: sort users so the newest are at the top.
|
||||||
- ActivityPub Client-to-Server(C2S): Limitation on the type of Activity/Object are lifted as they are now passed through ObjectValidators
|
- ActivityPub Client-to-Server(C2S): Limitation on the type of Activity/Object are lifted as they are now passed through ObjectValidators
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -17,7 +17,7 @@ def user(params \\ %{}) do
|
||||||
|> Map.drop([:page, :page_size])
|
|> Map.drop([:page, :page_size])
|
||||||
|> Map.put(:invisible, false)
|
|> Map.put(:invisible, false)
|
||||||
|> User.Query.build()
|
|> User.Query.build()
|
||||||
|> order_by([u], u.nickname)
|
|> order_by(desc: :id)
|
||||||
|
|
||||||
paginated_query =
|
paginated_query =
|
||||||
User.Query.paginate(query, params[:page] || 1, params[:page_size] || @page_size)
|
User.Query.paginate(query, params[:page] || 1, params[:page_size] || @page_size)
|
||||||
|
|
|
@ -384,24 +384,22 @@ test "renders users array for the first page", %{conn: conn, admin: admin} do
|
||||||
|
|
||||||
conn = get(conn, "/api/pleroma/admin/users?page=1")
|
conn = get(conn, "/api/pleroma/admin/users?page=1")
|
||||||
|
|
||||||
users =
|
users = [
|
||||||
[
|
user_response(
|
||||||
user_response(
|
user2,
|
||||||
admin,
|
%{
|
||||||
%{"roles" => %{"admin" => true, "moderator" => false}}
|
"local" => true,
|
||||||
),
|
"is_approved" => false,
|
||||||
user_response(user, %{"local" => false, "tags" => ["foo", "bar"]}),
|
"registration_reason" => "I'm a chill dude",
|
||||||
user_response(
|
"actor_type" => "Person"
|
||||||
user2,
|
}
|
||||||
%{
|
),
|
||||||
"local" => true,
|
user_response(user, %{"local" => false, "tags" => ["foo", "bar"]}),
|
||||||
"is_approved" => false,
|
user_response(
|
||||||
"registration_reason" => "I'm a chill dude",
|
admin,
|
||||||
"actor_type" => "Person"
|
%{"roles" => %{"admin" => true, "moderator" => false}}
|
||||||
}
|
)
|
||||||
)
|
]
|
||||||
]
|
|
||||||
|> Enum.sort_by(& &1["nickname"])
|
|
||||||
|
|
||||||
assert json_response_and_validate_schema(conn, 200) == %{
|
assert json_response_and_validate_schema(conn, 200) == %{
|
||||||
"count" => 3,
|
"count" => 3,
|
||||||
|
@ -525,7 +523,7 @@ test "regular search with page size", %{conn: conn} do
|
||||||
assert json_response_and_validate_schema(conn1, 200) == %{
|
assert json_response_and_validate_schema(conn1, 200) == %{
|
||||||
"count" => 2,
|
"count" => 2,
|
||||||
"page_size" => 1,
|
"page_size" => 1,
|
||||||
"users" => [user_response(user)]
|
"users" => [user_response(user2)]
|
||||||
}
|
}
|
||||||
|
|
||||||
conn2 = get(conn, "/api/pleroma/admin/users?query=a&page_size=1&page=2")
|
conn2 = get(conn, "/api/pleroma/admin/users?query=a&page_size=1&page=2")
|
||||||
|
@ -533,7 +531,7 @@ test "regular search with page size", %{conn: conn} do
|
||||||
assert json_response_and_validate_schema(conn2, 200) == %{
|
assert json_response_and_validate_schema(conn2, 200) == %{
|
||||||
"count" => 2,
|
"count" => 2,
|
||||||
"page_size" => 1,
|
"page_size" => 1,
|
||||||
"users" => [user_response(user2)]
|
"users" => [user_response(user)]
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -565,18 +563,16 @@ test "only local users with no query", %{conn: conn, admin: old_admin} do
|
||||||
|
|
||||||
conn = get(conn, "/api/pleroma/admin/users?filters=local")
|
conn = get(conn, "/api/pleroma/admin/users?filters=local")
|
||||||
|
|
||||||
users =
|
users = [
|
||||||
[
|
user_response(user),
|
||||||
user_response(user),
|
user_response(admin, %{
|
||||||
user_response(admin, %{
|
"roles" => %{"admin" => true, "moderator" => false}
|
||||||
"roles" => %{"admin" => true, "moderator" => false}
|
}),
|
||||||
}),
|
user_response(old_admin, %{
|
||||||
user_response(old_admin, %{
|
"is_active" => true,
|
||||||
"is_active" => true,
|
"roles" => %{"admin" => true, "moderator" => false}
|
||||||
"roles" => %{"admin" => true, "moderator" => false}
|
})
|
||||||
})
|
]
|
||||||
]
|
|
||||||
|> Enum.sort_by(& &1["nickname"])
|
|
||||||
|
|
||||||
assert json_response_and_validate_schema(conn, 200) == %{
|
assert json_response_and_validate_schema(conn, 200) == %{
|
||||||
"count" => 3,
|
"count" => 3,
|
||||||
|
@ -604,7 +600,6 @@ test "only unconfirmed users", %{conn: conn} do
|
||||||
"is_approved" => true
|
"is_approved" => true
|
||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
|> Enum.sort_by(& &1["nickname"])
|
|
||||||
|
|
||||||
assert result == %{"count" => 2, "page_size" => 50, "users" => users}
|
assert result == %{"count" => 2, "page_size" => 50, "users" => users}
|
||||||
end
|
end
|
||||||
|
@ -642,18 +637,16 @@ test "load only admins", %{conn: conn, admin: admin} do
|
||||||
|
|
||||||
conn = get(conn, "/api/pleroma/admin/users?filters=is_admin")
|
conn = get(conn, "/api/pleroma/admin/users?filters=is_admin")
|
||||||
|
|
||||||
users =
|
users = [
|
||||||
[
|
user_response(second_admin, %{
|
||||||
user_response(admin, %{
|
"is_active" => true,
|
||||||
"is_active" => true,
|
"roles" => %{"admin" => true, "moderator" => false}
|
||||||
"roles" => %{"admin" => true, "moderator" => false}
|
}),
|
||||||
}),
|
user_response(admin, %{
|
||||||
user_response(second_admin, %{
|
"is_active" => true,
|
||||||
"is_active" => true,
|
"roles" => %{"admin" => true, "moderator" => false}
|
||||||
"roles" => %{"admin" => true, "moderator" => false}
|
})
|
||||||
})
|
]
|
||||||
]
|
|
||||||
|> Enum.sort_by(& &1["nickname"])
|
|
||||||
|
|
||||||
assert json_response_and_validate_schema(conn, 200) == %{
|
assert json_response_and_validate_schema(conn, 200) == %{
|
||||||
"count" => 2,
|
"count" => 2,
|
||||||
|
@ -693,13 +686,11 @@ test "load users with actor_type is Person", %{admin: admin, conn: conn} do
|
||||||
|> get(user_path(conn, :index), %{actor_types: ["Person"]})
|
|> get(user_path(conn, :index), %{actor_types: ["Person"]})
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
users =
|
users = [
|
||||||
[
|
user_response(user2),
|
||||||
user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}}),
|
user_response(user1),
|
||||||
user_response(user1),
|
user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}})
|
||||||
user_response(user2)
|
]
|
||||||
]
|
|
||||||
|> Enum.sort_by(& &1["nickname"])
|
|
||||||
|
|
||||||
assert response == %{"count" => 3, "page_size" => 50, "users" => users}
|
assert response == %{"count" => 3, "page_size" => 50, "users" => users}
|
||||||
end
|
end
|
||||||
|
@ -716,14 +707,12 @@ test "load users with actor_type is Person and Service", %{admin: admin, conn: c
|
||||||
|> get(user_path(conn, :index), %{actor_types: ["Person", "Service"]})
|
|> get(user_path(conn, :index), %{actor_types: ["Person", "Service"]})
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
users =
|
users = [
|
||||||
[
|
user_response(user2),
|
||||||
user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}}),
|
user_response(user1),
|
||||||
user_response(user1),
|
user_response(user_service, %{"actor_type" => "Service"}),
|
||||||
user_response(user2),
|
user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}})
|
||||||
user_response(user_service, %{"actor_type" => "Service"})
|
]
|
||||||
]
|
|
||||||
|> Enum.sort_by(& &1["nickname"])
|
|
||||||
|
|
||||||
assert response == %{"count" => 4, "page_size" => 50, "users" => users}
|
assert response == %{"count" => 4, "page_size" => 50, "users" => users}
|
||||||
end
|
end
|
||||||
|
@ -752,12 +741,10 @@ test "load users with tags list", %{conn: conn} do
|
||||||
|
|
||||||
conn = get(conn, "/api/pleroma/admin/users?tags[]=first&tags[]=second")
|
conn = get(conn, "/api/pleroma/admin/users?tags[]=first&tags[]=second")
|
||||||
|
|
||||||
users =
|
users = [
|
||||||
[
|
user_response(user2, %{"tags" => ["second"]}),
|
||||||
user_response(user1, %{"tags" => ["first"]}),
|
user_response(user1, %{"tags" => ["first"]})
|
||||||
user_response(user2, %{"tags" => ["second"]})
|
]
|
||||||
]
|
|
||||||
|> Enum.sort_by(& &1["nickname"])
|
|
||||||
|
|
||||||
assert json_response_and_validate_schema(conn, 200) == %{
|
assert json_response_and_validate_schema(conn, 200) == %{
|
||||||
"count" => 2,
|
"count" => 2,
|
||||||
|
@ -781,8 +768,8 @@ test "`active` filters out users pending approval", %{token: token} do
|
||||||
"count" => 2,
|
"count" => 2,
|
||||||
"page_size" => 50,
|
"page_size" => 50,
|
||||||
"users" => [
|
"users" => [
|
||||||
%{"id" => ^admin_id},
|
%{"id" => ^user_id},
|
||||||
%{"id" => ^user_id}
|
%{"id" => ^admin_id}
|
||||||
]
|
]
|
||||||
} = json_response_and_validate_schema(conn, 200)
|
} = json_response_and_validate_schema(conn, 200)
|
||||||
end
|
end
|
||||||
|
|
|
@ -151,9 +151,9 @@ test "it returns users by actor_types" do
|
||||||
|
|
||||||
{:ok, [^user_service], 1} = Search.user(%{actor_types: ["Service"]})
|
{:ok, [^user_service], 1} = Search.user(%{actor_types: ["Service"]})
|
||||||
{:ok, [^user_application], 1} = Search.user(%{actor_types: ["Application"]})
|
{:ok, [^user_application], 1} = Search.user(%{actor_types: ["Application"]})
|
||||||
{:ok, [^user1, ^user2], 2} = Search.user(%{actor_types: ["Person"]})
|
{:ok, [^user2, ^user1], 2} = Search.user(%{actor_types: ["Person"]})
|
||||||
|
|
||||||
{:ok, [^user_service, ^user1, ^user2], 3} =
|
{:ok, [^user2, ^user1, ^user_service], 3} =
|
||||||
Search.user(%{actor_types: ["Person", "Service"]})
|
Search.user(%{actor_types: ["Person", "Service"]})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue