Events with only one event creator participant can't be left
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -582,6 +582,28 @@ defmodule Mobilizon.Events do
|
||||
)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of organizers participants for an event.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> list_organizers_participants_for_event(id)
|
||||
[%Participant{role: :creator}, ...]
|
||||
|
||||
"""
|
||||
def list_organizers_participants_for_event(id, page \\ nil, limit \\ nil) do
|
||||
Repo.all(
|
||||
from(
|
||||
p in Participant,
|
||||
join: e in Event,
|
||||
on: p.event_id == e.id,
|
||||
where: e.id == ^id and p.role == ^:creator,
|
||||
preload: [:actor]
|
||||
)
|
||||
|> paginate(page, limit)
|
||||
)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a single participant.
|
||||
|
||||
|
||||
@@ -100,12 +100,19 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||
with {:is_owned, true, _} <- User.owns_actor(user, actor_id),
|
||||
{:ok, %Participant{} = participant} <-
|
||||
Mobilizon.Events.get_participant(event_id, actor_id),
|
||||
{:ok, _} <- Mobilizon.Events.delete_participant(participant) do
|
||||
{:only_organizer, false} <-
|
||||
{:only_organizer,
|
||||
Mobilizon.Events.list_organizers_participants_for_event(event_id) |> length == 1},
|
||||
{:ok, _} <-
|
||||
Mobilizon.Events.delete_participant(participant) do
|
||||
{:ok, %{event: %{id: event_id}, actor: %{id: actor_id}}}
|
||||
else
|
||||
{:is_owned, false} ->
|
||||
{:error, "Actor id is not owned by authenticated user"}
|
||||
|
||||
{:only_organizer, true} ->
|
||||
{:error, "You can't leave event because you're the only event creator participant"}
|
||||
|
||||
{:error, :participant_not_found} ->
|
||||
{:error, "Participant not found"}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user