Fix searching for persons

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-05-02 19:27:34 +02:00
parent 3afc7c7feb
commit 5afdd80c71
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
3 changed files with 9 additions and 2 deletions

View File

@ -46,7 +46,7 @@ defmodule Mobilizon.GraphQL.API.Search do
actor_type: [result_type], actor_type: [result_type],
radius: Map.get(args, :radius), radius: Map.get(args, :radius),
location: Map.get(args, :location), location: Map.get(args, :location),
minimum_visibility: :public minimum_visibility: Map.get(args, :minimum_visibility, :public)
], ],
page, page,
limit limit

View File

@ -9,7 +9,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Search do
Search persons Search persons
""" """
def search_persons(_parent, %{page: page, limit: limit} = args, _resolution) do def search_persons(_parent, %{page: page, limit: limit} = args, _resolution) do
Search.search_actors(args, page, limit, :Person) Search.search_actors(Map.put(args, :minimum_visibility, :private), page, limit, :Person)
end end
@doc """ @doc """

View File

@ -500,6 +500,10 @@ defmodule Mobilizon.Actors do
defp filter_suspended(query, true), do: where(query, [a], a.suspended) defp filter_suspended(query, true), do: where(query, [a], a.suspended)
defp filter_suspended(query, false), do: where(query, [a], not a.suspended) defp filter_suspended(query, false), do: where(query, [a], not a.suspended)
@spec filter_out_anonymous_actor_id(Ecto.Query.t(), integer() | String.t()) :: Ecto.Query.t()
defp filter_out_anonymous_actor_id(query, anonymous_actor_id),
do: where(query, [a], a.id != ^anonymous_actor_id)
@doc """ @doc """
Returns the list of local actors by their username. Returns the list of local actors by their username.
""" """
@ -527,12 +531,15 @@ defmodule Mobilizon.Actors do
page \\ nil, page \\ nil,
limit \\ nil limit \\ nil
) do ) do
anonymous_actor_id = Mobilizon.Config.anonymous_actor_id()
Actor Actor
|> actor_by_username_or_name_query(term) |> actor_by_username_or_name_query(term)
|> actors_for_location(Keyword.get(options, :location), Keyword.get(options, :radius)) |> actors_for_location(Keyword.get(options, :location), Keyword.get(options, :radius))
|> filter_by_types(Keyword.get(options, :actor_type, :Group)) |> filter_by_types(Keyword.get(options, :actor_type, :Group))
|> filter_by_minimum_visibility(Keyword.get(options, :minimum_visibility, :public)) |> filter_by_minimum_visibility(Keyword.get(options, :minimum_visibility, :public))
|> filter_suspended(false) |> filter_suspended(false)
|> filter_out_anonymous_actor_id(anonymous_actor_id)
|> Page.build_page(page, limit) |> Page.build_page(page, limit)
end end