Add a dropdown on participate menu, disallow listing participations

Now requires quering the person endpoint to know if an actor
participates in an event, organizers can make authenticated requests to
event { participants { } } to see the pending / approved participants.

Also closes #174

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-09-26 16:38:58 +02:00
parent 8a3e606c15
commit 757d2cabec
34 changed files with 655 additions and 439 deletions

View File

@@ -128,14 +128,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
@@ -143,12 +147,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

View File

@@ -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