Admin API: Filter out unapproved users when the `active` filter is on
authorEgor Kislitsyn <egor@kislitsyn.com>
Mon, 10 Aug 2020 13:57:36 +0000 (17:57 +0400)
committerEgor Kislitsyn <egor@kislitsyn.com>
Mon, 10 Aug 2020 14:27:39 +0000 (18:27 +0400)
lib/pleroma/user/query.ex
test/web/admin_api/controllers/admin_api_controller_test.exs

index 45553cb6c9a6b407f4aace4ce7c917f508cf6aec..d618432fffcc70e8bb86ceb44baec07f26adb8dd 100644 (file)
@@ -130,6 +130,7 @@ defmodule Pleroma.User.Query do
   defp compose_query({:active, _}, query) do
     User.restrict_deactivated(query)
     |> where([u], not is_nil(u.nickname))
+    |> where([u], u.approval_pending == false)
   end
 
   defp compose_query({:legacy_active, _}, query) do
index b5d5bd8c70e837bc6ca09825174a7c24cdf0ba5e..7f0f026056830a4c87a3f01203013d2c1aefd3bf 100644 (file)
@@ -1164,6 +1164,27 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
              }
     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
       admin = insert(:user, nickname: "john", is_admin: true)
       token = insert(:oauth_admin_token, user: admin)