admin user search: added filter by `actor_type`

This commit is contained in:
Maksim Pechnikov 2020-09-25 16:04:01 +03:00
parent 46b420aa60
commit 60663150b5
2 changed files with 20 additions and 1 deletions

View File

@ -56,7 +56,8 @@ defmodule Pleroma.User.Query do
ap_id: [String.t()], ap_id: [String.t()],
order_by: term(), order_by: term(),
select: term(), select: term(),
limit: pos_integer() limit: pos_integer(),
actor_types: [String.t()]
} }
| map() | map()
@ -115,6 +116,10 @@ defp compose_query({:is_admin, bool}, query) do
where(query, [u], u.is_admin == ^bool) where(query, [u], u.is_admin == ^bool)
end 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 defp compose_query({:is_moderator, bool}, query) do
where(query, [u], u.is_moderator == ^bool) where(query, [u], u.is_moderator == ^bool)
end end

View File

@ -143,6 +143,20 @@ test "it returns users with tags" do
assert user2 in users assert user2 in users
end 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 test "it returns user by display name" do
user = insert(:user, name: "Display name") user = insert(:user, name: "Display name")
insert(:user) insert(:user)