Fix event notification tests
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -738,6 +738,11 @@ defmodule Mobilizon.Events do
|
||||
|> Repo.one()
|
||||
end
|
||||
|
||||
@spec get_participant!(integer | String.t()) :: Participant.t()
|
||||
def get_participant!(participant_id) do
|
||||
Repo.get_by!(Participant, id: participant_id)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a single participation for an event and actor.
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ defmodule Mobilizon.Events.Participant do
|
||||
|
||||
# No lookalike symbols
|
||||
@symbols '6789BCDFGHJKLMNPQRTW'
|
||||
@symbol_count Enum.count(@symbols)
|
||||
@symbol_count Enum.count(@symbols) - 1
|
||||
@code_length 6
|
||||
|
||||
@spec generate_code :: String.t()
|
||||
|
||||
@@ -3,11 +3,10 @@ defmodule Mobilizon.Service.Workers.Notification do
|
||||
Worker to send notifications
|
||||
"""
|
||||
|
||||
alias Mobilizon.{Actors, Events, Users}
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.{Event, Participant}
|
||||
alias Mobilizon.Storage.Page
|
||||
alias Mobilizon.Users
|
||||
alias Mobilizon.Users.{Setting, User}
|
||||
alias Mobilizon.Web.Email.{Mailer, Notification}
|
||||
|
||||
@@ -22,12 +21,19 @@ defmodule Mobilizon.Service.Workers.Notification do
|
||||
def perform(%Job{
|
||||
args: %{"op" => "before_event_notification", "participant_id" => participant_id}
|
||||
}) do
|
||||
with %Participant{actor: %Actor{user_id: user_id}, event: %Event{status: :confirmed}} =
|
||||
participant <- Events.get_participant(participant_id),
|
||||
%User{email: email, locale: locale, settings: %Setting{notification_before_event: true}} <-
|
||||
Users.get_user_with_settings!(user_id) do
|
||||
with %Participant{} = participant <- Events.get_participant(participant_id),
|
||||
%Event{status: :confirmed} = event <-
|
||||
Events.get_event_with_preload!(participant.event_id),
|
||||
%Actor{user_id: user_id} = actor when not is_nil(user_id) <-
|
||||
Actors.get_actor_with_preload!(participant.actor_id) do
|
||||
%User{email: email, locale: locale, settings: %Setting{notification_before_event: true}} =
|
||||
Users.get_user_with_settings!(user_id)
|
||||
|
||||
email
|
||||
|> Notification.before_event_notification(participant, locale)
|
||||
|> Notification.before_event_notification(
|
||||
%Participant{participant | event: event, actor: actor},
|
||||
locale
|
||||
)
|
||||
|> Mailer.send_email_later()
|
||||
|
||||
:ok
|
||||
@@ -50,7 +56,12 @@ defmodule Mobilizon.Service.Workers.Notification do
|
||||
Enum.filter(participations, fn participation ->
|
||||
participation.event.status == :confirmed
|
||||
end),
|
||||
true <- length(participations) > 0 do
|
||||
true <- length(participations) > 0,
|
||||
participations <-
|
||||
Enum.map(participations, fn participation ->
|
||||
%Event{} = event = Events.get_event_with_preload!(participation.event_id)
|
||||
%Participant{participation | event: event}
|
||||
end) do
|
||||
user
|
||||
|> Notification.on_day_notification(participations, total, locale)
|
||||
|> Mailer.send_email_later()
|
||||
@@ -79,7 +90,12 @@ defmodule Mobilizon.Service.Workers.Notification do
|
||||
Enum.filter(participations, fn participation ->
|
||||
participation.event.status == :confirmed
|
||||
end),
|
||||
true <- length(participations) > 0 do
|
||||
true <- length(participations) > 0,
|
||||
participations <-
|
||||
Enum.map(participations, fn participation ->
|
||||
%Event{} = event = Events.get_event_with_preload!(participation.event_id)
|
||||
%Participant{participation | event: event}
|
||||
end) do
|
||||
user
|
||||
|> Notification.weekly_notification(participations, total, locale)
|
||||
|> Mailer.send_email_later()
|
||||
@@ -99,7 +115,7 @@ defmodule Mobilizon.Service.Workers.Notification do
|
||||
}
|
||||
}) do
|
||||
with %User{} = user <- Users.get_user(user_id),
|
||||
{:ok, %Event{} = event} <- Events.get_event(event_id),
|
||||
{:ok, %Event{} = event} <- Events.get_event_with_preload(event_id),
|
||||
%Page{total: total} when total > 0 <-
|
||||
Events.list_participants_for_event(event_id, [:not_approved]) do
|
||||
user
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
<!-- THIS EMAIL WAS BUILT AND TESTED WITH LITMUS http://litmus.com -->
|
||||
<!-- IT WAS RELEASED UNDER THE MIT LICENSE https://opensource.org/licenses/MIT -->
|
||||
<!-- QUESTIONS? TWEET US @LITMUSAPP -->
|
||||
<!DOCTYPE html>
|
||||
<html lang={"#{ @locale }"}>
|
||||
<head>
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
<td bgcolor="#ffffff" align="center" style="padding: 20px 30px 60px 30px;">
|
||||
<table border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td align="center" style="border-radius: 3px;" bgcolor="#474467"><a href={"#{ "#{Mobilizon.Web.Endpoint.url()}/password-reset/#{@token}" }"} target="_blank" style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #474467; display: inline-block;">
|
||||
<td align="center" style="border-radius: 3px;" bgcolor="#474467"><a href={"#{Mobilizon.Web.Endpoint.url()}/password-reset/#{@token}"} target="_blank" style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #474467; display: inline-block;">
|
||||
<%= gettext "Reset Password" %>
|
||||
</a></td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user