Merge branch 'feature/participate-dropdown' into 'master'
Add a dropdown on participate menu, disallow listing participations Closes #174 See merge request framasoft/mobilizon!200
This commit is contained in:
@@ -593,12 +593,12 @@ defmodule Mobilizon.Events do
|
||||
@spec list_participants_for_event(String.t(), list(atom()), integer | nil, integer | nil) ::
|
||||
[Participant.t()]
|
||||
def list_participants_for_event(
|
||||
uuid,
|
||||
id,
|
||||
roles \\ @default_participant_roles,
|
||||
page \\ nil,
|
||||
limit \\ nil
|
||||
) do
|
||||
uuid
|
||||
id
|
||||
|> list_participants_for_event_query()
|
||||
|> filter_role(roles)
|
||||
|> Page.paginate(page, limit)
|
||||
@@ -688,7 +688,7 @@ defmodule Mobilizon.Events do
|
||||
Returns the list of participations for an actor.
|
||||
"""
|
||||
@spec list_event_participations_for_actor(Actor.t(), integer | nil, integer | nil) ::
|
||||
[Event.t()]
|
||||
[Participant.t()]
|
||||
def list_event_participations_for_actor(%Actor{id: actor_id}, page \\ nil, limit \\ nil) do
|
||||
actor_id
|
||||
|> event_participations_for_actor_query()
|
||||
@@ -1241,13 +1241,11 @@ defmodule Mobilizon.Events do
|
||||
@spec event_participations_for_actor_query(integer) :: Ecto.Query.t()
|
||||
def event_participations_for_actor_query(actor_id) do
|
||||
from(
|
||||
e in Event,
|
||||
join: p in Participant,
|
||||
join: a in Actor,
|
||||
on: p.actor_id == a.id,
|
||||
p in Participant,
|
||||
join: e in Event,
|
||||
on: p.event_id == e.id,
|
||||
where: a.id == ^actor_id and p.role != ^:not_approved,
|
||||
preload: [:picture, :tags]
|
||||
where: p.actor_id == ^actor_id and p.role != ^:not_approved,
|
||||
preload: [:event]
|
||||
)
|
||||
end
|
||||
|
||||
@@ -1281,12 +1279,12 @@ defmodule Mobilizon.Events do
|
||||
end
|
||||
|
||||
@spec list_participants_for_event_query(String.t()) :: Ecto.Query.t()
|
||||
defp list_participants_for_event_query(event_uuid) do
|
||||
defp list_participants_for_event_query(event_id) do
|
||||
from(
|
||||
p in Participant,
|
||||
join: e in Event,
|
||||
on: p.event_id == e.id,
|
||||
where: e.uuid == ^event_uuid,
|
||||
where: e.id == ^event_id,
|
||||
preload: [:actor]
|
||||
)
|
||||
end
|
||||
|
||||
@@ -38,34 +38,42 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
List participant for event (separate request)
|
||||
"""
|
||||
def list_participants_for_event(_parent, %{uuid: uuid, page: page, limit: limit}, _resolution) do
|
||||
{:ok, Mobilizon.Events.list_participants_for_event(uuid, [], page, limit)}
|
||||
end
|
||||
|
||||
@doc """
|
||||
List participants for event (through an event request)
|
||||
"""
|
||||
def list_participants_for_event(
|
||||
%Event{uuid: uuid},
|
||||
%{page: page, limit: limit, roles: roles},
|
||||
_resolution
|
||||
%Event{id: event_id},
|
||||
%{page: page, limit: limit, roles: roles, actor_id: actor_id},
|
||||
%{context: %{current_user: %User{} = user}} = _resolution
|
||||
) do
|
||||
roles =
|
||||
case roles do
|
||||
"" ->
|
||||
[]
|
||||
with {:is_owned, %Actor{} = _actor} <- User.owns_actor(user, actor_id),
|
||||
# Check that moderator has right
|
||||
{:actor_approve_permission, true} <-
|
||||
{:actor_approve_permission, Mobilizon.Events.moderator_for_event?(event_id, actor_id)} do
|
||||
roles =
|
||||
case roles do
|
||||
"" ->
|
||||
[]
|
||||
|
||||
roles ->
|
||||
roles
|
||||
|> String.split(",")
|
||||
|> Enum.map(&String.downcase/1)
|
||||
|> Enum.map(&String.to_existing_atom/1)
|
||||
end
|
||||
roles ->
|
||||
roles
|
||||
|> String.split(",")
|
||||
|> Enum.map(&String.downcase/1)
|
||||
|> Enum.map(&String.to_existing_atom/1)
|
||||
end
|
||||
|
||||
{:ok, Mobilizon.Events.list_participants_for_event(uuid, roles, page, limit)}
|
||||
{:ok, Mobilizon.Events.list_participants_for_event(event_id, roles, page, limit)}
|
||||
else
|
||||
{:is_owned, nil} ->
|
||||
{:error, "Moderator Actor ID is not owned by authenticated user"}
|
||||
|
||||
{:actor_approve_permission, _} ->
|
||||
{:error, "Provided moderator actor ID doesn't have permission on this event"}
|
||||
end
|
||||
end
|
||||
|
||||
def list_participants_for_event(_, _args, _resolution) do
|
||||
{:ok, []}
|
||||
end
|
||||
|
||||
def stats_participants_for_event(%Event{id: id}, _args, _resolution) do
|
||||
|
||||
@@ -6,6 +6,7 @@ defmodule MobilizonWeb.Resolvers.Person do
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.Participant
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Users
|
||||
alias Mobilizon.Users.User
|
||||
@@ -173,27 +174,33 @@ defmodule MobilizonWeb.Resolvers.Person do
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of events this person is going to
|
||||
Returns the participation for a specific event
|
||||
"""
|
||||
def person_going_to_events(%Actor{id: actor_id}, _args, %{context: %{current_user: user}}) do
|
||||
with {:is_owned, %Actor{} = actor} <- User.owns_actor(user, actor_id),
|
||||
events <- Events.list_event_participations_for_actor(actor) do
|
||||
{:ok, events}
|
||||
def person_participations(%Actor{id: actor_id}, %{event_id: event_id}, %{
|
||||
context: %{current_user: user}
|
||||
}) do
|
||||
with {:is_owned, %Actor{} = _actor} <- User.owns_actor(user, actor_id),
|
||||
{:no_participant, {:ok, %Participant{} = participant}} <-
|
||||
{:no_participant, Events.get_participant(event_id, actor_id)} do
|
||||
{:ok, [participant]}
|
||||
else
|
||||
{:is_owned, nil} ->
|
||||
{:error, "Actor id is not owned by authenticated user"}
|
||||
|
||||
{:no_participant, _} ->
|
||||
{:ok, []}
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of events this person is going to
|
||||
"""
|
||||
def person_going_to_events(_parent, %{}, %{context: %{current_user: user}}) do
|
||||
with %Actor{} = actor <- Users.get_actor_for_user(user),
|
||||
events <- Events.list_event_participations_for_actor(actor) do
|
||||
{:ok, events}
|
||||
def person_participations(%Actor{id: actor_id}, _args, %{context: %{current_user: user}}) do
|
||||
with {:is_owned, %Actor{} = actor} <- User.owns_actor(user, actor_id),
|
||||
participations <- Events.list_event_participations_for_actor(actor) do
|
||||
{:ok, participations}
|
||||
else
|
||||
{:is_owned, false} ->
|
||||
{:is_owned, nil} ->
|
||||
{:error, "Actor id is not owned by authenticated user"}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -225,10 +225,11 @@ defmodule MobilizonWeb.Resolvers.User do
|
||||
@doc """
|
||||
Returns the list of events for all of this user's identities are going to
|
||||
"""
|
||||
def user_participations(_parent, args, %{
|
||||
context: %{current_user: %User{id: user_id}}
|
||||
def user_participations(%User{id: user_id}, args, %{
|
||||
context: %{current_user: %User{id: logged_user_id}}
|
||||
}) do
|
||||
with participations <-
|
||||
with true <- user_id == logged_user_id,
|
||||
participations <-
|
||||
Events.list_participations_for_user(
|
||||
user_id,
|
||||
Map.get(args, :after_datetime),
|
||||
|
||||
@@ -116,7 +116,6 @@ defmodule MobilizonWeb.Schema do
|
||||
import_fields(:person_queries)
|
||||
import_fields(:group_queries)
|
||||
import_fields(:event_queries)
|
||||
import_fields(:participant_queries)
|
||||
import_fields(:tag_queries)
|
||||
import_fields(:address_queries)
|
||||
import_fields(:config_queries)
|
||||
|
||||
@@ -56,8 +56,11 @@ defmodule MobilizonWeb.Schema.Actors.PersonType do
|
||||
)
|
||||
|
||||
@desc "The list of events this person goes to"
|
||||
field :going_to_events, list_of(:event) do
|
||||
resolve(&Person.person_going_to_events/3)
|
||||
field(:participations, list_of(:participant),
|
||||
description: "The list of events this person goes to"
|
||||
) do
|
||||
arg(:event_id, :id)
|
||||
resolve(&Person.person_participations/3)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ defmodule MobilizonWeb.Schema.EventType do
|
||||
arg(:page, :integer, default_value: 1)
|
||||
arg(:limit, :integer, default_value: 10)
|
||||
arg(:roles, :string, default_value: "")
|
||||
arg(:actor_id, :id)
|
||||
resolve(&Event.list_participants_for_event/3)
|
||||
end
|
||||
|
||||
|
||||
@@ -44,16 +44,6 @@ defmodule MobilizonWeb.Schema.Events.ParticipantType do
|
||||
field(:actor, :deleted_object)
|
||||
end
|
||||
|
||||
object :participant_queries do
|
||||
@desc "Get all participants for an event uuid"
|
||||
field :participants, list_of(:participant) do
|
||||
arg(:uuid, non_null(:uuid))
|
||||
arg(:page, :integer, default_value: 1)
|
||||
arg(:limit, :integer, default_value: 10)
|
||||
resolve(&Resolvers.Event.list_participants_for_event/3)
|
||||
end
|
||||
end
|
||||
|
||||
object :participant_mutations do
|
||||
@desc "Join an event"
|
||||
field :join_event, :participant do
|
||||
|
||||
@@ -47,7 +47,7 @@ defmodule MobilizonWeb.Schema.UserType do
|
||||
field(:role, :user_role, description: "The role for the user")
|
||||
|
||||
field(:participations, list_of(:participant),
|
||||
description: "The list of events this person goes to"
|
||||
description: "The list of events this user goes to"
|
||||
) do
|
||||
arg(:after_datetime, :datetime)
|
||||
arg(:before_datetime, :datetime)
|
||||
|
||||
@@ -122,14 +122,18 @@ defmodule Mobilizon.Service.Export.Feed do
|
||||
%FeedToken{actor: actor, user: %User{} = user} <- Events.get_feed_token(token) do
|
||||
case actor do
|
||||
%Actor{} = actor ->
|
||||
events = fetch_identity_going_to_events(actor)
|
||||
events = actor |> fetch_identity_participations() |> participations_to_events()
|
||||
{:ok, build_actor_feed(actor, events, false)}
|
||||
|
||||
nil ->
|
||||
with actors <- Users.get_actors_for_user(user),
|
||||
events <-
|
||||
actors
|
||||
|> Enum.map(&Events.list_event_participations_for_actor/1)
|
||||
|> Enum.map(fn actor ->
|
||||
actor
|
||||
|> Events.list_event_participations_for_actor()
|
||||
|> participations_to_events()
|
||||
end)
|
||||
|> Enum.concat() do
|
||||
{:ok, build_user_feed(events, user, token)}
|
||||
end
|
||||
@@ -137,12 +141,18 @@ defmodule Mobilizon.Service.Export.Feed do
|
||||
end
|
||||
end
|
||||
|
||||
defp fetch_identity_going_to_events(%Actor{} = actor) do
|
||||
defp fetch_identity_participations(%Actor{} = actor) do
|
||||
with events <- Events.list_event_participations_for_actor(actor) do
|
||||
events
|
||||
end
|
||||
end
|
||||
|
||||
defp participations_to_events(participations) do
|
||||
participations
|
||||
|> Enum.map(& &1.event_id)
|
||||
|> Enum.map(&Events.get_event_with_preload!/1)
|
||||
end
|
||||
|
||||
# Build an atom feed from actor and it's public events
|
||||
@spec build_user_feed(list(), User.t(), String.t()) :: String.t()
|
||||
defp build_user_feed(events, %User{email: email}, token) do
|
||||
|
||||
@@ -33,7 +33,7 @@ defmodule Mobilizon.Service.Export.ICalendar do
|
||||
dtend: event.ends_on,
|
||||
description: event.description,
|
||||
uid: event.uuid,
|
||||
categories: [event.category] ++ (event.tags |> Enum.map(& &1.slug))
|
||||
categories: event.tags |> Enum.map(& &1.slug)
|
||||
}
|
||||
end
|
||||
|
||||
@@ -52,7 +52,8 @@ defmodule Mobilizon.Service.Export.ICalendar do
|
||||
|
||||
@spec export_private_actor(Actor.t()) :: String.t()
|
||||
def export_private_actor(%Actor{} = actor) do
|
||||
with events <- Events.list_event_participations_for_actor(actor) do
|
||||
with events <-
|
||||
actor |> Events.list_event_participations_for_actor() |> participations_to_events() do
|
||||
{:ok, %ICalendar{events: events |> Enum.map(&do_export_event/1)} |> ICalendar.to_ics()}
|
||||
end
|
||||
end
|
||||
@@ -107,7 +108,11 @@ defmodule Mobilizon.Service.Export.ICalendar do
|
||||
with actors <- Users.get_actors_for_user(user),
|
||||
events <-
|
||||
actors
|
||||
|> Enum.map(&Events.list_event_participations_for_actor/1)
|
||||
|> Enum.map(fn actor ->
|
||||
actor
|
||||
|> Events.list_event_participations_for_actor()
|
||||
|> participations_to_events()
|
||||
end)
|
||||
|> Enum.concat() do
|
||||
{:ok,
|
||||
%ICalendar{events: events |> Enum.map(&do_export_event/1)} |> ICalendar.to_ics()}
|
||||
@@ -115,4 +120,10 @@ defmodule Mobilizon.Service.Export.ICalendar do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp participations_to_events(participations) do
|
||||
participations
|
||||
|> Enum.map(& &1.event_id)
|
||||
|> Enum.map(&Events.get_event_with_preload!/1)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user