Allow anonymous participants to have timezone metadata

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-10-13 12:55:49 +02:00
parent 44f90c7b0b
commit 4de78f58e0
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
7 changed files with 38 additions and 13 deletions

View File

@ -200,6 +200,7 @@ export default class ParticipationWithoutAccount extends Vue {
email: this.anonymousParticipation.email,
message: this.anonymousParticipation.message,
locale: this.$i18n.locale,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
},
update: (
store: ApolloCache<{ joinEvent: IParticipant }>,

View File

@ -380,6 +380,7 @@ export const JOIN_EVENT = gql`
$email: String
$message: String
$locale: String
$timezone: String
) {
joinEvent(
eventId: $eventId
@ -387,6 +388,7 @@ export const JOIN_EVENT = gql`
email: $email
message: $message
locale: $locale
timezone: $timezone
) {
...ParticipantQuery
}

View File

@ -91,6 +91,7 @@ defmodule Mobilizon.GraphQL.Schema.Events.ParticipantType do
arg(:email, :string, description: "The anonymous participant's email")
arg(:message, :string, description: "The anonymous participant's message")
arg(:locale, :string, description: "The anonymous participant's locale")
arg(:timezone, :string, description: "The anonymous participant's timezone")
resolve(&Participant.actor_join_event/3)
end

View File

@ -15,7 +15,7 @@ defmodule Mobilizon.Events.Participant.Metadata do
locale: String.t()
}
@attrs [:email, :confirmation_token, :cancellation_token, :message, :locale]
@attrs [:email, :confirmation_token, :cancellation_token, :message, :locale, :timezone]
@derive Jason.Encoder
embedded_schema do
@ -24,6 +24,7 @@ defmodule Mobilizon.Events.Participant.Metadata do
field(:cancellation_token, :string)
field(:message, :string)
field(:locale, :string)
field(:timezone, :string)
end
@doc false

View File

@ -14,15 +14,24 @@ defmodule Mobilizon.Web.Email.Event do
alias Mobilizon.Events.{Event, Participant}
alias Mobilizon.Storage.Repo
alias Mobilizon.Users.{Setting, User}
alias Mobilizon.Web.Email
alias Mobilizon.Web.JsonLD.ObjectView
@important_changes [:title, :begins_on, :ends_on, :status, :physical_address]
@spec event_updated(String.t(), Actor.t(), Event.t(), Event.t(), MapSet.t(), String.t()) ::
@spec event_updated(
Participant.t(),
String.t(),
Actor.t(),
Event.t(),
Event.t(),
MapSet.t(),
String.t()
) ::
Bamboo.Email.t()
def event_updated(
email,
%Participant{} = participant,
%Actor{} = actor,
%Event{} = old_event,
%Event{} = event,
@ -83,13 +92,14 @@ defmodule Mobilizon.Web.Email.Event do
MapSet.t()
) :: Bamboo.Email.t()
defp send_notification_for_event_update_to_participant(
{%Participant{} = _participant, %Actor{} = actor,
{%Participant{} = participant, %Actor{} = actor,
%User{locale: locale, email: email} = _user, %Setting{timezone: timezone}},
%Event{} = old_event,
%Event{} = event,
diff
) do
do_send_notification_for_event_update_to_participant(
participant,
email,
actor,
old_event,
@ -101,13 +111,14 @@ defmodule Mobilizon.Web.Email.Event do
end
defp send_notification_for_event_update_to_participant(
{%Participant{} = _participant, %Actor{} = actor,
{%Participant{} = participant, %Actor{} = actor,
%User{locale: locale, email: email} = _user, nil},
%Event{} = old_event,
%Event{} = event,
diff
) do
do_send_notification_for_event_update_to_participant(
participant,
email,
actor,
old_event,
@ -119,7 +130,8 @@ defmodule Mobilizon.Web.Email.Event do
end
defp send_notification_for_event_update_to_participant(
{%Participant{metadata: %{email: email}} = _participant, %Actor{} = actor, nil, nil},
{%Participant{metadata: %{email: email} = participant_metadata} = participant,
%Actor{} = actor, nil, nil},
%Event{} = old_event,
%Event{} = event,
diff
@ -128,17 +140,19 @@ defmodule Mobilizon.Web.Email.Event do
locale = Gettext.get_locale()
do_send_notification_for_event_update_to_participant(
participant,
email,
actor,
old_event,
event,
diff,
"Etc/UTC",
Map.get(participant_metadata, :timezone, "Etc/UTC"),
locale
)
end
@spec do_send_notification_for_event_update_to_participant(
Participant.t(),
String.t(),
Actor.t(),
Event.t(),
@ -148,6 +162,7 @@ defmodule Mobilizon.Web.Email.Event do
String.t()
) :: Bamboo.Email.t()
defp do_send_notification_for_event_update_to_participant(
participant,
email,
actor,
old_event,
@ -157,7 +172,7 @@ defmodule Mobilizon.Web.Email.Event do
locale
) do
email
|> Email.Event.event_updated(actor, old_event, event, diff, timezone, locale)
|> Email.Event.event_updated(participant, actor, old_event, event, diff, timezone, locale)
|> Email.Mailer.send_email_later()
end
end

View File

@ -59,7 +59,7 @@ defmodule Mobilizon.Web.Email.Participation do
def participation_updated(
email,
%Participant{event: event, role: :rejected},
%Participant{event: event, role: :rejected} = participant,
locale
) do
Gettext.put_locale(locale)
@ -73,13 +73,15 @@ defmodule Mobilizon.Web.Email.Participation do
Email.base_email(to: email, subject: subject)
|> assign(:locale, locale)
|> assign(:event, event)
|> assign(:jsonLDMetadata, json_ld(participant))
|> assign(:subject, subject)
|> render(:event_participation_rejected)
end
def participation_updated(
email,
%Participant{event: %Event{join_options: :free} = event, role: :participant},
%Participant{event: %Event{join_options: :free} = event, role: :participant} =
participant,
locale
) do
Gettext.put_locale(locale)
@ -94,12 +96,13 @@ defmodule Mobilizon.Web.Email.Participation do
|> assign(:locale, locale)
|> assign(:event, event)
|> assign(:subject, subject)
|> assign(:jsonLDMetadata, json_ld(participant))
|> render(:event_participation_confirmed)
end
def participation_updated(
email,
%Participant{event: event, role: :participant},
%Participant{event: event, role: :participant} = participant,
locale
) do
Gettext.put_locale(locale)

View File

@ -932,11 +932,11 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
test "update_event/3 updates an event", %{conn: conn, actor: actor, user: user} do
event = insert(:event, organizer_actor: actor)
_creator = insert(:participant, event: event, actor: actor, role: :creator)
creator = insert(:participant, event: event, actor: actor, role: :creator)
participant_user = insert(:user)
participant_actor = insert(:actor, user: participant_user)
_participant =
participant =
insert(:participant, event: event, actor: participant_actor, role: :participant)
address = insert(:address)
@ -1009,6 +1009,7 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
assert_delivered_email(
Email.Event.event_updated(
creator,
user.email,
actor,
event,
@ -1019,6 +1020,7 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
assert_delivered_email(
Email.Event.event_updated(
participant,
participant_user.email,
participant_actor,
event,