Fix unlisted groups being available in search
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -40,8 +40,13 @@ defmodule Mobilizon.GraphQL.API.Search do
|
||||
true ->
|
||||
page =
|
||||
Actors.build_actors_by_username_or_name_page(
|
||||
Map.put(args, :term, term),
|
||||
[result_type],
|
||||
term,
|
||||
[
|
||||
actor_type: [result_type],
|
||||
radius: Map.get(args, :radius),
|
||||
location: Map.get(args, :location),
|
||||
minimum_visibility: :public
|
||||
],
|
||||
page,
|
||||
limit
|
||||
)
|
||||
|
||||
@@ -149,6 +149,7 @@ defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
|
||||
enum :group_visibility do
|
||||
value(:public, description: "Publicly listed and federated")
|
||||
value(:unlisted, description: "Visible only to people with the link - or invited")
|
||||
value(:private, description: "Visible only to people with the link - or invited")
|
||||
end
|
||||
|
||||
object :group_queries do
|
||||
@@ -198,6 +199,11 @@ defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
|
||||
default_value: :public
|
||||
)
|
||||
|
||||
arg(:openness, :openness,
|
||||
default_value: :invite_only,
|
||||
description: "Whether the group can be join freely, with approval or is invite-only."
|
||||
)
|
||||
|
||||
arg(:avatar, :media_input,
|
||||
description:
|
||||
"The avatar for the group, either as an object or directly the ID of an existing media"
|
||||
|
||||
@@ -135,7 +135,14 @@ defmodule Mobilizon.Actors.Actor do
|
||||
:preferred_username,
|
||||
:members_url
|
||||
]
|
||||
@group_creation_optional_attrs [:shared_inbox_url, :name, :domain, :summary, :visibility]
|
||||
@group_creation_optional_attrs [
|
||||
:shared_inbox_url,
|
||||
:name,
|
||||
:domain,
|
||||
:summary,
|
||||
:visibility,
|
||||
:openness
|
||||
]
|
||||
@group_creation_attrs @group_creation_required_attrs ++ @group_creation_optional_attrs
|
||||
|
||||
schema "actors" do
|
||||
|
||||
@@ -512,21 +512,22 @@ defmodule Mobilizon.Actors do
|
||||
Builds a page struct for actors by their name or displayed name.
|
||||
"""
|
||||
@spec build_actors_by_username_or_name_page(
|
||||
map(),
|
||||
[ActorType.t()],
|
||||
String.t(),
|
||||
Keyword.t(),
|
||||
integer | nil,
|
||||
integer | nil
|
||||
) :: Page.t()
|
||||
def build_actors_by_username_or_name_page(
|
||||
%{term: term} = args,
|
||||
types,
|
||||
term,
|
||||
options \\ [],
|
||||
page \\ nil,
|
||||
limit \\ nil
|
||||
) do
|
||||
Actor
|
||||
|> actor_by_username_or_name_query(term)
|
||||
|> actors_for_location(args)
|
||||
|> filter_by_types(types)
|
||||
|> actors_for_location(Keyword.get(options, :location), Keyword.get(options, :radius))
|
||||
|> filter_by_types(Keyword.get(options, :actor_type, :Group))
|
||||
|> filter_by_minimum_visibility(Keyword.get(options, :minimum_visibility, :public))
|
||||
|> filter_suspended(false)
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
@@ -1395,11 +1396,8 @@ defmodule Mobilizon.Actors do
|
||||
)
|
||||
end
|
||||
|
||||
@spec actors_for_location(Ecto.Query.t(), map()) :: Ecto.Query.t()
|
||||
defp actors_for_location(query, %{radius: radius}) when is_nil(radius),
|
||||
do: query
|
||||
|
||||
defp actors_for_location(query, %{location: location, radius: radius})
|
||||
@spec actors_for_location(Ecto.Query.t(), String.t(), integer()) :: Ecto.Query.t()
|
||||
defp actors_for_location(query, location, radius)
|
||||
when is_valid_string?(location) and not is_nil(radius) do
|
||||
with {lon, lat} <- Geohax.decode(location),
|
||||
point <- Geo.WKT.decode!("SRID=4326;POINT(#{lon} #{lat})") do
|
||||
@@ -1414,7 +1412,7 @@ defmodule Mobilizon.Actors do
|
||||
end
|
||||
end
|
||||
|
||||
defp actors_for_location(query, _args), do: query
|
||||
defp actors_for_location(query, _location, _radius), do: query
|
||||
|
||||
@spec person_query :: Ecto.Query.t()
|
||||
defp person_query do
|
||||
@@ -1660,6 +1658,21 @@ defmodule Mobilizon.Actors do
|
||||
from(a in query, where: a.type in ^types)
|
||||
end
|
||||
|
||||
@spec filter_by_minimum_visibility(Ecto.Query.t(), atom()) :: Ecto.Query.t()
|
||||
defp filter_by_minimum_visibility(query, :private), do: query
|
||||
|
||||
defp filter_by_minimum_visibility(query, :restricted) do
|
||||
from(a in query, where: a.visibility in ^[:public, :unlisted, :restricted])
|
||||
end
|
||||
|
||||
defp filter_by_minimum_visibility(query, :unlisted) do
|
||||
from(a in query, where: a.visibility in ^[:public, :unlisted])
|
||||
end
|
||||
|
||||
defp filter_by_minimum_visibility(query, :public) do
|
||||
from(a in query, where: a.visibility == ^:public)
|
||||
end
|
||||
|
||||
@spec filter_by_name(Ecto.Query.t(), [String.t()]) :: Ecto.Query.t()
|
||||
defp filter_by_name(query, [name]) do
|
||||
from(a in query, where: a.preferred_username == ^name and is_nil(a.domain))
|
||||
|
||||
Reference in New Issue
Block a user