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

@@ -411,8 +411,16 @@ defmodule Mobilizon.Service.ActivityPub do
def join(object, actor, local \\ true)
def join(%Event{} = event, %Actor{} = actor, local) do
with role <- Mobilizon.Events.get_default_participant_role(event),
def join(%Event{options: options} = event, %Actor{} = actor, local) do
# TODO Refactor me for federation
with maximum_attendee_capacity <-
Map.get(options, :maximum_attendee_capacity, 2_000_000) || false,
{:maximum_attendee_capacity, true} <-
{:maximum_attendee_capacity,
!maximum_attendee_capacity ||
Mobilizon.Events.count_participant_participants(event.id) <
maximum_attendee_capacity},
role <- Mobilizon.Events.get_default_participant_role(event),
{:ok, %Participant{} = participant} <-
Mobilizon.Events.create_participant(%{
role: role,