admin user search: added filter by `actor_type`
authorMaksim Pechnikov <parallel588@gmail.com>
Fri, 25 Sep 2020 13:04:01 +0000 (16:04 +0300)
committerMaksim Pechnikov <parallel588@gmail.com>
Thu, 22 Oct 2020 08:53:28 +0000 (11:53 +0300)
lib/pleroma/user/query.ex
test/pleroma/web/admin_api/search_test.exs

index 711439eef613b046e4294c80cda63b82e411df5c..7ef2a145592f70d1e78dc726c74ef66e698e3470 100644 (file)
@@ -56,7 +56,8 @@ defmodule Pleroma.User.Query do
             ap_id: [String.t()],
             order_by: term(),
             select: term(),
-            limit: pos_integer()
+            limit: pos_integer(),
+            actor_types: [String.t()]
           }
           | map()
 
@@ -115,6 +116,10 @@ defmodule Pleroma.User.Query do
     where(query, [u], u.is_admin == ^bool)
   end
 
+  defp compose_query({:actor_types, actor_types}, query) when is_list(actor_types) do
+    where(query, [u], u.actor_type in ^actor_types)
+  end
+
   defp compose_query({:is_moderator, bool}, query) do
     where(query, [u], u.is_moderator == ^bool)
   end
index 82da86f7f4333cd8b031284daf826ebceef9b48d..92a116c659e337fceed074396ed1476af6c7494b 100644 (file)
@@ -143,6 +143,20 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do
       assert user2 in users
     end
 
+    test "it returns users by actor_types" do
+      user_service = insert(:user, actor_type: "Service")
+      user_application = insert(:user, actor_type: "Application")
+      user1 = insert(:user)
+      user2 = insert(:user)
+
+      {: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, [^user_service, ^user1, ^user2], 3} =
+        Search.user(%{actor_types: ["Person", "Service"]})
+    end
+
     test "it returns user by display name" do
       user = insert(:user, name: "Display name")
       insert(:user)