Make sure people can't join an event with limited participants

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-10-11 11:50:06 +02:00
parent db5b02e397
commit bf25d22786
5 changed files with 101 additions and 3 deletions

View File

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