2021-09-24 14:46:42 +00:00
|
|
|
defmodule Mobilizon.Web.Email.Actor do
|
|
|
|
@moduledoc """
|
|
|
|
Handles emails sent about actors status.
|
|
|
|
"""
|
2022-04-05 10:16:22 +00:00
|
|
|
use Phoenix.Swoosh, view: Mobilizon.Web.EmailView
|
2021-09-24 14:46:42 +00:00
|
|
|
|
|
|
|
import Mobilizon.Web.Gettext
|
|
|
|
|
|
|
|
alias Mobilizon.Actors.Actor
|
|
|
|
alias Mobilizon.Events.{Event, Participant}
|
2021-09-30 07:34:39 +00:00
|
|
|
alias Mobilizon.Users
|
2021-09-24 14:46:42 +00:00
|
|
|
alias Mobilizon.Users.User
|
|
|
|
alias Mobilizon.Web.Email
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Send a notification to participants from events organized by an actor that is going to be suspended
|
|
|
|
"""
|
|
|
|
@spec send_notification_event_participants_from_suspension(Participant.t(), Actor.t()) ::
|
|
|
|
:ok
|
|
|
|
def send_notification_event_participants_from_suspension(
|
|
|
|
%Participant{
|
|
|
|
actor: %Actor{user_id: nil}
|
|
|
|
},
|
|
|
|
_suspended
|
|
|
|
),
|
|
|
|
do: :ok
|
|
|
|
|
|
|
|
def send_notification_event_participants_from_suspension(%Participant{role: role}, _suspended)
|
|
|
|
when role not in [:participant, :moderator, :administrator],
|
|
|
|
do: :ok
|
|
|
|
|
|
|
|
def send_notification_event_participants_from_suspension(
|
|
|
|
%Participant{
|
|
|
|
actor: %Actor{user_id: user_id},
|
|
|
|
event: %Event{} = event,
|
|
|
|
role: member_role
|
|
|
|
},
|
|
|
|
%Actor{} = suspended
|
|
|
|
) do
|
|
|
|
with %User{email: email, locale: locale} <- Users.get_user!(user_id) do
|
|
|
|
Gettext.put_locale(locale)
|
|
|
|
|
|
|
|
subject = gettext("Your participation to %{event} has been cancelled!", event: event.title)
|
|
|
|
|
2022-04-05 10:16:22 +00:00
|
|
|
[to: email, subject: subject]
|
|
|
|
|> Email.base_email()
|
|
|
|
|> render_body(:actor_suspension_participants, %{
|
|
|
|
locale: locale,
|
|
|
|
actor: suspended,
|
|
|
|
event: event,
|
|
|
|
role: member_role,
|
|
|
|
subject: subject
|
|
|
|
})
|
|
|
|
|> Email.Mailer.send_email()
|
2021-09-24 14:46:42 +00:00
|
|
|
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|