Make sure people can't join an event with limited participants
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -762,6 +762,17 @@ defmodule Mobilizon.Events do
|
||||
|> Repo.aggregate(:count, :id)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Counts participant participants.
|
||||
"""
|
||||
@spec count_participant_participants(integer | String.t()) :: integer
|
||||
def count_participant_participants(event_id) do
|
||||
event_id
|
||||
|> count_participants_query()
|
||||
|> filter_participant_role()
|
||||
|> Repo.aggregate(:count, :id)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Counts unapproved participants.
|
||||
"""
|
||||
@@ -1457,6 +1468,11 @@ defmodule Mobilizon.Events do
|
||||
from(p in query, where: p.role not in ^[:not_approved, :rejected])
|
||||
end
|
||||
|
||||
@spec filter_participant_role(Ecto.Query.t()) :: Ecto.Query.t()
|
||||
defp filter_participant_role(query) do
|
||||
from(p in query, where: p.role == ^:participant)
|
||||
end
|
||||
|
||||
@spec filter_unapproved_role(Ecto.Query.t()) :: Ecto.Query.t()
|
||||
defp filter_unapproved_role(query) do
|
||||
from(p in query, where: p.role == ^:not_approved)
|
||||
|
||||
Reference in New Issue
Block a user