Send email notifications when a participation is approved/rejected

Also handles participant status :rejected instead of deleting the
participation

Closes #164

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-09-30 13:48:47 +02:00
parent d30b2fa147
commit 5b4f1c271a
47 changed files with 3092 additions and 484 deletions

View File

@@ -70,6 +70,7 @@ defmodule Mobilizon.Events do
defenum(ParticipantRole, :participant_role, [
:not_approved,
:rejected,
:participant,
:moderator,
:administrator,
@@ -718,6 +719,17 @@ defmodule Mobilizon.Events do
|> Repo.aggregate(:count, :id)
end
@doc """
Counts rejected participants.
"""
@spec count_rejected_participants(integer | String.t()) :: integer
def count_rejected_participants(event_id) do
event_id
|> count_participants_query()
|> filter_rejected_role()
|> Repo.aggregate(:count, :id)
end
@doc """
Gets the default participant role depending on the event join options.
"""
@@ -1361,7 +1373,7 @@ defmodule Mobilizon.Events do
@spec filter_approved_role(Ecto.Query.t()) :: Ecto.Query.t()
defp filter_approved_role(query) do
from(p in query, where: p.role != ^:not_approved)
from(p in query, where: p.role not in ^[:not_approved, :rejected])
end
@spec filter_unapproved_role(Ecto.Query.t()) :: Ecto.Query.t()
@@ -1369,6 +1381,11 @@ defmodule Mobilizon.Events do
from(p in query, where: p.role == ^:not_approved)
end
@spec filter_rejected_role(Ecto.Query.t()) :: Ecto.Query.t()
defp filter_rejected_role(query) do
from(p in query, where: p.role == ^:rejected)
end
@spec filter_role(Ecto.Query.t(), list(atom())) :: Ecto.Query.t()
defp filter_role(query, []), do: query