Merge branch 'hide-event-group-organizers' into 'master'
Hide event group organizers Closes #561 See merge request framasoft/mobilizon!806
This commit is contained in:
commit
6563433e4e
@ -12,12 +12,53 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do
|
||||
alias Mobilizon.GraphQL.API
|
||||
|
||||
alias Mobilizon.Federation.ActivityPub.Activity
|
||||
import Mobilizon.Users.Guards, only: [is_moderator: 1]
|
||||
import Mobilizon.Web.Gettext
|
||||
|
||||
# We limit the max number of events that can be retrieved
|
||||
@event_max_limit 100
|
||||
@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)
|
||||
when limit < @event_max_limit do
|
||||
{:ok, Events.list_events(page, limit)}
|
||||
|
@ -51,16 +51,16 @@ defmodule Mobilizon.GraphQL.Schema.EventType do
|
||||
field(:online_address, :string, description: "Online address of 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,
|
||||
resolve: dataloader(Actors),
|
||||
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),
|
||||
resolve: &Tag.list_tags_for_event/3,
|
||||
description: "The event's tags"
|
||||
|
Loading…
Reference in New Issue
Block a user