Hide event group organizers

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-01-25 12:00:06 +01:00
parent 8b99ba1cff
commit 3b78cffb17
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
2 changed files with 46 additions and 5 deletions

View File

@ -12,12 +12,53 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do
alias Mobilizon.GraphQL.API alias Mobilizon.GraphQL.API
alias Mobilizon.Federation.ActivityPub.Activity alias Mobilizon.Federation.ActivityPub.Activity
import Mobilizon.Users.Guards, only: [is_moderator: 1]
import Mobilizon.Web.Gettext import Mobilizon.Web.Gettext
# We limit the max number of events that can be retrieved # We limit the max number of events that can be retrieved
@event_max_limit 100 @event_max_limit 100
@number_of_related_events 3 @number_of_related_events 3
def organizer_for_event(
%Event{attributed_to_id: attributed_to_id, organizer_actor_id: organizer_actor_id},
_args,
%{context: %{current_user: %User{role: user_role} = user}} = _resolution
)
when not is_nil(attributed_to_id) do
with %Actor{id: group_id} <- Actors.get_actor(attributed_to_id),
%Actor{id: actor_id} <- Users.get_actor_for_user(user),
{:member, true} <-
{:member, Actors.is_member?(actor_id, group_id) or is_moderator(user_role)},
%Actor{} = actor <- Actors.get_actor(organizer_actor_id) do
{:ok, actor}
else
_ -> {:ok, nil}
end
end
def organizer_for_event(
%Event{attributed_to_id: attributed_to_id},
_args,
_resolution
)
when not is_nil(attributed_to_id) do
case Actors.get_actor(attributed_to_id) do
%Actor{} -> {:ok, nil}
_ -> {:error, "Unable to get organizer actor"}
end
end
def organizer_for_event(
%Event{organizer_actor_id: organizer_actor_id},
_args,
_resolution
) do
case Actors.get_actor(organizer_actor_id) do
%Actor{} = actor -> {:ok, actor}
_ -> {:error, "Unable to get organizer actor"}
end
end
def list_events(_parent, %{page: page, limit: limit}, _resolution) def list_events(_parent, %{page: page, limit: limit}, _resolution)
when limit < @event_max_limit do when limit < @event_max_limit do
{:ok, Events.list_events(page, limit)} {:ok, Events.list_events(page, limit)}

View File

@ -51,16 +51,16 @@ defmodule Mobilizon.GraphQL.Schema.EventType do
field(:online_address, :string, description: "Online address of the event") field(:online_address, :string, description: "Online address of the event")
field(:phone_address, :string, description: "Phone address for the event") field(:phone_address, :string, description: "Phone address for the event")
field(:organizer_actor, :actor,
resolve: dataloader(Actors),
description: "The event's organizer (as a person)"
)
field(:attributed_to, :actor, field(:attributed_to, :actor,
resolve: dataloader(Actors), resolve: dataloader(Actors),
description: "Who the event is attributed to (often a group)" description: "Who the event is attributed to (often a group)"
) )
field(:organizer_actor, :actor,
resolve: &Event.organizer_for_event/3,
description: "The event's organizer (as a person)"
)
field(:tags, list_of(:tag), field(:tags, list_of(:tag),
resolve: &Tag.list_tags_for_event/3, resolve: &Tag.list_tags_for_event/3,
description: "The event's tags" description: "The event's tags"