Fix search exposing events to unlogged users

Closes #892

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-11-08 18:46:04 +01:00
parent 729a6a7113
commit 3961a2067b
6 changed files with 78 additions and 36 deletions

View File

@@ -26,7 +26,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Search do
%{page: page, limit: limit} = args,
%{context: context} = _resolution
) do
current_actor = Map.get(context, :current_actor, nil)
current_actor = Map.get(context, :current_actor)
current_actor_id = if current_actor, do: current_actor.id, else: nil
args = Map.put(args, :current_actor_id, current_actor_id)
Search.search_actors(args, page, limit, :Group)
@@ -37,7 +37,13 @@ defmodule Mobilizon.GraphQL.Resolvers.Search do
"""
@spec search_events(any(), map(), Absinthe.Resolution.t()) ::
{:ok, Page.t(Event.t())} | {:error, String.t()}
def search_events(_parent, %{page: page, limit: limit} = args, _resolution) do
def search_events(
_parent,
%{page: page, limit: limit} = args,
%{context: context} = _resolution
) do
current_user = Map.get(context, :current_user)
args = Map.put(args, :current_user, current_user)
Search.search_events(args, page, limit)
end