forked from AkkomaGang/akkoma
Merge branch 'fix/search-users-for-admin' into 'develop'
Rework users search Closes admin-fe#12 See merge request pleroma/pleroma!954
This commit is contained in:
commit
606766b010
2 changed files with 25 additions and 15 deletions
|
@ -788,34 +788,27 @@ def search_for_admin(%{query: nil, local: local, page: page, page_size: page_siz
|
||||||
|
|
||||||
@spec search_for_admin(%{
|
@spec search_for_admin(%{
|
||||||
query: binary(),
|
query: binary(),
|
||||||
admin: Pleroma.User.t(),
|
|
||||||
local: boolean(),
|
local: boolean(),
|
||||||
page: number(),
|
page: number(),
|
||||||
page_size: number()
|
page_size: number()
|
||||||
}) :: {:ok, [Pleroma.User.t()], number()}
|
}) :: {:ok, [Pleroma.User.t()], number()}
|
||||||
def search_for_admin(%{
|
def search_for_admin(%{
|
||||||
query: term,
|
query: term,
|
||||||
admin: admin,
|
|
||||||
local: local,
|
local: local,
|
||||||
page: page,
|
page: page,
|
||||||
page_size: page_size
|
page_size: page_size
|
||||||
}) do
|
}) do
|
||||||
term = String.trim_leading(term, "@")
|
maybe_local_query = User |> maybe_local_user_query(local)
|
||||||
|
|
||||||
local_paginated_query =
|
search_query = from(u in maybe_local_query, where: ilike(u.nickname, ^"%#{term}%"))
|
||||||
User
|
count = search_query |> Repo.aggregate(:count, :id)
|
||||||
|> maybe_local_user_query(local)
|
|
||||||
|
results =
|
||||||
|
search_query
|
||||||
|> paginate(page, page_size)
|
|> paginate(page, page_size)
|
||||||
|
|> Repo.all()
|
||||||
|
|
||||||
search_query = fts_search_subquery(term, local_paginated_query)
|
{:ok, results, count}
|
||||||
|
|
||||||
count =
|
|
||||||
term
|
|
||||||
|> fts_search_subquery()
|
|
||||||
|> maybe_local_user_query(local)
|
|
||||||
|> Repo.aggregate(:count, :id)
|
|
||||||
|
|
||||||
{:ok, do_search(search_query, admin), count}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def search(query, resolve \\ false, for_user \\ nil) do
|
def search(query, resolve \\ false, for_user \\ nil) do
|
||||||
|
|
|
@ -1098,4 +1098,21 @@ test "bookmarks" do
|
||||||
assert {:ok, user_state3} = User.bookmark(user, id2)
|
assert {:ok, user_state3} = User.bookmark(user, id2)
|
||||||
assert user_state3.bookmarks == [id2]
|
assert user_state3.bookmarks == [id2]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "search for admin" do
|
||||||
|
test "it ignores case" do
|
||||||
|
insert(:user, nickname: "papercoach")
|
||||||
|
insert(:user, nickname: "CanadaPaperCoach")
|
||||||
|
|
||||||
|
{:ok, _results, count} =
|
||||||
|
User.search_for_admin(%{
|
||||||
|
query: "paper",
|
||||||
|
local: false,
|
||||||
|
page: 1,
|
||||||
|
page_size: 50
|
||||||
|
})
|
||||||
|
|
||||||
|
assert count == 2
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue