Fix searchable unlisted events
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
5a5196595a
commit
bee79166d3
@ -136,9 +136,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do
|
|||||||
events =
|
events =
|
||||||
if @number_of_related_events - length(events) > 0 do
|
if @number_of_related_events - length(events) > 0 do
|
||||||
events
|
events
|
||||||
|> Enum.concat(
|
|> Enum.concat(Events.list_events(1, @number_of_related_events, :begins_on, :asc, true))
|
||||||
Events.list_events(1, @number_of_related_events, :begins_on, :asc, true, true)
|
|
||||||
)
|
|
||||||
|> uniq_events()
|
|> uniq_events()
|
||||||
else
|
else
|
||||||
events
|
events
|
||||||
|
@ -162,7 +162,7 @@ defmodule Mobilizon.Events do
|
|||||||
event =
|
event =
|
||||||
url
|
url
|
||||||
|> event_by_url_query()
|
|> event_by_url_query()
|
||||||
|> filter_public_visibility()
|
|> filter_unlisted_and_public_visibility()
|
||||||
|> filter_draft()
|
|> filter_draft()
|
||||||
|> preload_for_event()
|
|> preload_for_event()
|
||||||
|> Repo.one()
|
|> Repo.one()
|
||||||
@ -184,7 +184,7 @@ defmodule Mobilizon.Events do
|
|||||||
def get_public_event_by_url_with_preload!(url) do
|
def get_public_event_by_url_with_preload!(url) do
|
||||||
url
|
url
|
||||||
|> event_by_url_query()
|
|> event_by_url_query()
|
||||||
|> filter_public_visibility()
|
|> filter_unlisted_and_public_visibility()
|
||||||
|> filter_draft()
|
|> filter_draft()
|
||||||
|> preload_for_event()
|
|> preload_for_event()
|
||||||
|> Repo.one!()
|
|> Repo.one!()
|
||||||
@ -197,7 +197,7 @@ defmodule Mobilizon.Events do
|
|||||||
def get_public_event_by_uuid_with_preload(uuid) do
|
def get_public_event_by_uuid_with_preload(uuid) do
|
||||||
uuid
|
uuid
|
||||||
|> event_by_uuid_query()
|
|> event_by_uuid_query()
|
||||||
|> filter_public_visibility()
|
|> filter_unlisted_and_public_visibility()
|
||||||
|> filter_draft()
|
|> filter_draft()
|
||||||
|> preload_for_event()
|
|> preload_for_event()
|
||||||
|> Repo.one()
|
|> Repo.one()
|
||||||
@ -345,13 +345,12 @@ defmodule Mobilizon.Events do
|
|||||||
@doc """
|
@doc """
|
||||||
Returns the list of events.
|
Returns the list of events.
|
||||||
"""
|
"""
|
||||||
@spec list_events(integer | nil, integer | nil, atom, atom, boolean, boolean) :: [Event.t()]
|
@spec list_events(integer | nil, integer | nil, atom, atom, boolean) :: [Event.t()]
|
||||||
def list_events(
|
def list_events(
|
||||||
page \\ nil,
|
page \\ nil,
|
||||||
limit \\ nil,
|
limit \\ nil,
|
||||||
sort \\ :begins_on,
|
sort \\ :begins_on,
|
||||||
direction \\ :asc,
|
direction \\ :asc,
|
||||||
is_unlisted \\ false,
|
|
||||||
is_future \\ true
|
is_future \\ true
|
||||||
) do
|
) do
|
||||||
query = from(e in Event, preload: [:organizer_actor, :participants])
|
query = from(e in Event, preload: [:organizer_actor, :participants])
|
||||||
@ -360,7 +359,6 @@ defmodule Mobilizon.Events do
|
|||||||
|> Page.paginate(page, limit)
|
|> Page.paginate(page, limit)
|
||||||
|> sort(sort, direction)
|
|> sort(sort, direction)
|
||||||
|> filter_future_events(is_future)
|
|> filter_future_events(is_future)
|
||||||
|> filter_unlisted(is_unlisted)
|
|
||||||
|> filter_draft()
|
|> filter_draft()
|
||||||
|> filter_local_or_from_followed_instances_events()
|
|> filter_local_or_from_followed_instances_events()
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
@ -445,7 +443,7 @@ defmodule Mobilizon.Events do
|
|||||||
@spec count_local_events :: integer
|
@spec count_local_events :: integer
|
||||||
def count_local_events do
|
def count_local_events do
|
||||||
count_local_events_query()
|
count_local_events_query()
|
||||||
|> filter_public_visibility()
|
|> filter_unlisted_and_public_visibility()
|
||||||
|> filter_draft()
|
|> filter_draft()
|
||||||
|> Repo.one()
|
|> Repo.one()
|
||||||
end
|
end
|
||||||
@ -1273,7 +1271,7 @@ defmodule Mobilizon.Events do
|
|||||||
@spec events_for_search_query(String.t()) :: Ecto.Query.t()
|
@spec events_for_search_query(String.t()) :: Ecto.Query.t()
|
||||||
defp events_for_search_query(search_string) do
|
defp events_for_search_query(search_string) do
|
||||||
Event
|
Event
|
||||||
|> where([e], e.visibility in ^@public_visibility)
|
|> where([e], e.visibility == ^:public)
|
||||||
|> do_event_for_search_query(search_string)
|
|> do_event_for_search_query(search_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1304,7 +1302,7 @@ defmodule Mobilizon.Events do
|
|||||||
join: te in "events_tags",
|
join: te in "events_tags",
|
||||||
on: e.id == te.event_id,
|
on: e.id == te.event_id,
|
||||||
where: e.begins_on > ^DateTime.utc_now(),
|
where: e.begins_on > ^DateTime.utc_now(),
|
||||||
where: e.visibility in ^@public_visibility,
|
where: e.visibility == ^:public,
|
||||||
where: te.tag_id in ^tags_ids,
|
where: te.tag_id in ^tags_ids,
|
||||||
order_by: [asc: e.begins_on],
|
order_by: [asc: e.begins_on],
|
||||||
limit: ^limit
|
limit: ^limit
|
||||||
@ -1498,7 +1496,12 @@ defmodule Mobilizon.Events do
|
|||||||
|
|
||||||
@spec filter_public_visibility(Ecto.Query.t()) :: Ecto.Query.t()
|
@spec filter_public_visibility(Ecto.Query.t()) :: Ecto.Query.t()
|
||||||
defp filter_public_visibility(query) do
|
defp filter_public_visibility(query) do
|
||||||
from(e in query, where: e.visibility in ^@public_visibility)
|
from(e in query, where: e.visibility == ^:public)
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec filter_unlisted_and_public_visibility(Ecto.Query.t()) :: Ecto.Query.t()
|
||||||
|
defp filter_unlisted_and_public_visibility(query) do
|
||||||
|
from(q in query, where: q.visibility in ^@public_visibility)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec filter_not_event_uuid(Ecto.Query.t(), String.t() | nil) :: Ecto.Query.t()
|
@spec filter_not_event_uuid(Ecto.Query.t(), String.t() | nil) :: Ecto.Query.t()
|
||||||
@ -1530,15 +1533,6 @@ defmodule Mobilizon.Events do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec filter_unlisted(Ecto.Query.t(), boolean) :: Ecto.Query.t()
|
|
||||||
defp filter_unlisted(query, true) do
|
|
||||||
from(q in query, where: q.visibility in ^@public_visibility)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp filter_unlisted(query, false) do
|
|
||||||
from(q in query, where: q.visibility == ^:public)
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec filter_approved_role(Ecto.Query.t()) :: Ecto.Query.t()
|
@spec filter_approved_role(Ecto.Query.t()) :: Ecto.Query.t()
|
||||||
defp filter_approved_role(query) do
|
defp filter_approved_role(query) do
|
||||||
filter_role(query, [:not_approved, :rejected])
|
filter_role(query, [:not_approved, :rejected])
|
||||||
|
Loading…
Reference in New Issue
Block a user