Make sure event update notification email gets sent to anonymous

participants

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2020-10-08 08:53:25 +02:00
parent 9f9f58ce7d
commit f4b777c3d6
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
3 changed files with 31 additions and 12 deletions

View file

@ -1572,8 +1572,11 @@ defmodule Mobilizon.Events do
Participant
|> join(:inner, [p], a in Actor, on: p.actor_id == a.id and is_nil(a.domain))
|> join(:left, [_p, a], u in User, on: a.user_id == u.id)
|> where([p], p.event_id == ^event_id)
|> select([_p, a, u], {a, u})
|> where(
[p],
p.event_id == ^event_id and p.role not in [^:not_approved, ^:not_confirmed, ^:rejected]
)
|> select([p, a, u], {p, a, u})
end
@spec list_participations_for_user_query(integer()) :: Ecto.Query.t()

View file

@ -11,25 +11,26 @@ defmodule Mobilizon.Web.Email.Event do
alias Mobilizon.Actors.Actor
alias Mobilizon.Events
alias Mobilizon.Events.Event
alias Mobilizon.Events.{Event, Participant}
alias Mobilizon.Storage.Repo
alias Mobilizon.Users.User
alias Mobilizon.Web.{Email, Gettext}
alias Mobilizon.Web.Email
alias Mobilizon.Web.Gettext, as: GettextBackend
@important_changes [:title, :begins_on, :ends_on, :status, :physical_address]
@spec event_updated(User.t(), Actor.t(), Event.t(), Event.t(), MapSet.t(), String.t()) ::
@spec event_updated(String.t(), Actor.t(), Event.t(), Event.t(), MapSet.t(), String.t()) ::
Bamboo.Email.t()
def event_updated(
%User{} = user,
email,
%Actor{} = actor,
%Event{} = old_event,
%Event{} = event,
changes,
locale \\ "en"
) do
Gettext.put_locale(locale)
GettextBackend.put_locale(locale)
subject =
gettext(
@ -37,7 +38,7 @@ defmodule Mobilizon.Web.Email.Event do
title: old_event.title
)
Email.base_email(to: {Actor.display_name(actor), user.email}, subject: subject)
Email.base_email(to: {Actor.display_name(actor), email}, subject: subject)
|> assign(:locale, locale)
|> assign(:event, event)
|> assign(:old_event, old_event)
@ -73,12 +74,27 @@ defmodule Mobilizon.Web.Email.Event do
end
defp send_notification_for_event_update_to_participant(
{%Actor{} = actor, %User{locale: locale} = user},
{%Participant{} = _participant, %Actor{} = actor,
%User{locale: locale, email: email} = _user},
%Event{} = old_event,
%Event{} = event,
diff
) do
user
email
|> Email.Event.event_updated(actor, old_event, event, diff, locale)
|> Email.Mailer.deliver_later()
end
defp send_notification_for_event_update_to_participant(
{%Participant{metadata: %{email: email}} = _participant, %Actor{} = actor, nil},
%Event{} = old_event,
%Event{} = event,
diff
)
when not is_nil(email) do
locale = Gettext.get_locale()
email
|> Email.Event.event_updated(actor, old_event, event, diff, locale)
|> Email.Mailer.deliver_later()
end

View file

@ -837,7 +837,7 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
assert_delivered_email(
Email.Event.event_updated(
user,
user.email,
actor,
event,
new_event,
@ -847,7 +847,7 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
assert_delivered_email(
Email.Event.event_updated(
participant_user,
participant_user.email,
participant_actor,
event,
new_event,