AdminAPI: sort user results by ID descending
authorAlex Gleason <alex@alexgleason.me>
Wed, 14 Jul 2021 02:37:25 +0000 (21:37 -0500)
committerAlex Gleason <alex@alexgleason.me>
Wed, 14 Jul 2021 03:47:02 +0000 (22:47 -0500)
lib/pleroma/web/admin_api/search.ex
test/pleroma/web/admin_api/controllers/user_controller_test.exs
test/pleroma/web/admin_api/search_test.exs

index eeeebdf4ec7f1652a03c5bc72256a2e54238b239..f7d2b73278c94d10eba66330e881c874d042c82e 100644 (file)
@@ -23,7 +23,7 @@ defmodule Pleroma.Web.AdminAPI.Search do
       |> Map.drop([:page, :page_size])
       |> Map.put(:invisible, false)
       |> User.Query.build()
-      |> order_by([u], u.nickname)
+      |> order_by(desc: :id)
 
     paginated_query =
       User.Query.paginate(query, params[:page] || 1, params[:page_size] || @page_size)
index beb8a5d58c454b02af963fd9ea4657afe7557b47..5ae2c91804751f98da1321a8a03f397de5dbaeec 100644 (file)
@@ -376,24 +376,22 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
 
       conn = get(conn, "/api/pleroma/admin/users?page=1")
 
-      users =
-        [
-          user_response(
-            admin,
-            %{"roles" => %{"admin" => true, "moderator" => false}}
-          ),
-          user_response(user, %{"local" => false, "tags" => ["foo", "bar"]}),
-          user_response(
-            user2,
-            %{
-              "local" => true,
-              "is_approved" => false,
-              "registration_reason" => "I'm a chill dude",
-              "actor_type" => "Person"
-            }
-          )
-        ]
-        |> Enum.sort_by(& &1["nickname"])
+      users = [
+        user_response(
+          user2,
+          %{
+            "local" => true,
+            "is_approved" => false,
+            "registration_reason" => "I'm a chill dude",
+            "actor_type" => "Person"
+          }
+        ),
+        user_response(user, %{"local" => false, "tags" => ["foo", "bar"]}),
+        user_response(
+          admin,
+          %{"roles" => %{"admin" => true, "moderator" => false}}
+        )
+      ]
 
       assert json_response(conn, 200) == %{
                "count" => 3,
@@ -517,7 +515,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
       assert json_response(conn1, 200) == %{
                "count" => 2,
                "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")
@@ -525,7 +523,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
       assert json_response(conn2, 200) == %{
                "count" => 2,
                "page_size" => 1,
-               "users" => [user_response(user2)]
+               "users" => [user_response(user)]
              }
     end
 
@@ -557,18 +555,16 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
 
       conn = get(conn, "/api/pleroma/admin/users?filters=local")
 
-      users =
-        [
-          user_response(user),
-          user_response(admin, %{
-            "roles" => %{"admin" => true, "moderator" => false}
-          }),
-          user_response(old_admin, %{
-            "is_active" => true,
-            "roles" => %{"admin" => true, "moderator" => false}
-          })
-        ]
-        |> Enum.sort_by(& &1["nickname"])
+      users = [
+        user_response(user),
+        user_response(admin, %{
+          "roles" => %{"admin" => true, "moderator" => false}
+        }),
+        user_response(old_admin, %{
+          "is_active" => true,
+          "roles" => %{"admin" => true, "moderator" => false}
+        })
+      ]
 
       assert json_response(conn, 200) == %{
                "count" => 3,
@@ -596,7 +592,6 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
             "is_approved" => true
           })
         end)
-        |> Enum.sort_by(& &1["nickname"])
 
       assert result == %{"count" => 2, "page_size" => 50, "users" => users}
     end
@@ -634,18 +629,16 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
 
       conn = get(conn, "/api/pleroma/admin/users?filters=is_admin")
 
-      users =
-        [
-          user_response(admin, %{
-            "is_active" => true,
-            "roles" => %{"admin" => true, "moderator" => false}
-          }),
-          user_response(second_admin, %{
-            "is_active" => true,
-            "roles" => %{"admin" => true, "moderator" => false}
-          })
-        ]
-        |> Enum.sort_by(& &1["nickname"])
+      users = [
+        user_response(second_admin, %{
+          "is_active" => true,
+          "roles" => %{"admin" => true, "moderator" => false}
+        }),
+        user_response(admin, %{
+          "is_active" => true,
+          "roles" => %{"admin" => true, "moderator" => false}
+        })
+      ]
 
       assert json_response(conn, 200) == %{
                "count" => 2,
@@ -685,13 +678,11 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
         |> get(user_path(conn, :list), %{actor_types: ["Person"]})
         |> json_response(200)
 
-      users =
-        [
-          user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}}),
-          user_response(user1),
-          user_response(user2)
-        ]
-        |> Enum.sort_by(& &1["nickname"])
+      users = [
+        user_response(user2),
+        user_response(user1),
+        user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}})
+      ]
 
       assert response == %{"count" => 3, "page_size" => 50, "users" => users}
     end
@@ -708,14 +699,12 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
         |> get(user_path(conn, :list), %{actor_types: ["Person", "Service"]})
         |> json_response(200)
 
-      users =
-        [
-          user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}}),
-          user_response(user1),
-          user_response(user2),
-          user_response(user_service, %{"actor_type" => "Service"})
-        ]
-        |> Enum.sort_by(& &1["nickname"])
+      users = [
+        user_response(user2),
+        user_response(user1),
+        user_response(user_service, %{"actor_type" => "Service"}),
+        user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}})
+      ]
 
       assert response == %{"count" => 4, "page_size" => 50, "users" => users}
     end
@@ -744,12 +733,10 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
 
       conn = get(conn, "/api/pleroma/admin/users?tags[]=first&tags[]=second")
 
-      users =
-        [
-          user_response(user1, %{"tags" => ["first"]}),
-          user_response(user2, %{"tags" => ["second"]})
-        ]
-        |> Enum.sort_by(& &1["nickname"])
+      users = [
+        user_response(user2, %{"tags" => ["second"]}),
+        user_response(user1, %{"tags" => ["first"]})
+      ]
 
       assert json_response(conn, 200) == %{
                "count" => 2,
@@ -773,8 +760,8 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
                "count" => 2,
                "page_size" => 50,
                "users" => [
-                 %{"id" => ^admin_id},
-                 %{"id" => ^user_id}
+                 %{"id" => ^user_id},
+                 %{"id" => ^admin_id}
                ]
              } = json_response(conn, 200)
     end
index b8eeec65b6de8eeb54d5965da3b68c88e379b2a6..2335c5228399efba0be7c4b06da2016a0ee8c275 100644 (file)
@@ -151,9 +151,9 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do
 
       {:ok, [^user_service], 1} = Search.user(%{actor_types: ["Service"]})
       {: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"]})
     end