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, email: this.anonymousParticipation.email,
message: this.anonymousParticipation.message, message: this.anonymousParticipation.message,
locale: this.$i18n.locale, locale: this.$i18n.locale,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
}, },
update: ( update: (
store: ApolloCache<{ joinEvent: IParticipant }>, store: ApolloCache<{ joinEvent: IParticipant }>,

View File

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

View File

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

View File

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

View File

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

View File

@ -59,7 +59,7 @@ defmodule Mobilizon.Web.Email.Participation do
def participation_updated( def participation_updated(
email, email,
%Participant{event: event, role: :rejected}, %Participant{event: event, role: :rejected} = participant,
locale locale
) do ) do
Gettext.put_locale(locale) Gettext.put_locale(locale)
@ -73,13 +73,15 @@ defmodule Mobilizon.Web.Email.Participation do
Email.base_email(to: email, subject: subject) Email.base_email(to: email, subject: subject)
|> assign(:locale, locale) |> assign(:locale, locale)
|> assign(:event, event) |> assign(:event, event)
|> assign(:jsonLDMetadata, json_ld(participant))
|> assign(:subject, subject) |> assign(:subject, subject)
|> render(:event_participation_rejected) |> render(:event_participation_rejected)
end end
def participation_updated( def participation_updated(
email, email,
%Participant{event: %Event{join_options: :free} = event, role: :participant}, %Participant{event: %Event{join_options: :free} = event, role: :participant} =
participant,
locale locale
) do ) do
Gettext.put_locale(locale) Gettext.put_locale(locale)
@ -94,12 +96,13 @@ defmodule Mobilizon.Web.Email.Participation do
|> assign(:locale, locale) |> assign(:locale, locale)
|> assign(:event, event) |> assign(:event, event)
|> assign(:subject, subject) |> assign(:subject, subject)
|> assign(:jsonLDMetadata, json_ld(participant))
|> render(:event_participation_confirmed) |> render(:event_participation_confirmed)
end end
def participation_updated( def participation_updated(
email, email,
%Participant{event: event, role: :participant}, %Participant{event: event, role: :participant} = participant,
locale locale
) do ) do
Gettext.put_locale(locale) 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 test "update_event/3 updates an event", %{conn: conn, actor: actor, user: user} do
event = insert(:event, organizer_actor: actor) 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_user = insert(:user)
participant_actor = insert(:actor, user: participant_user) participant_actor = insert(:actor, user: participant_user)
_participant = participant =
insert(:participant, event: event, actor: participant_actor, role: :participant) insert(:participant, event: event, actor: participant_actor, role: :participant)
address = insert(:address) address = insert(:address)
@ -1009,6 +1009,7 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
assert_delivered_email( assert_delivered_email(
Email.Event.event_updated( Email.Event.event_updated(
creator,
user.email, user.email,
actor, actor,
event, event,
@ -1019,6 +1020,7 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
assert_delivered_email( assert_delivered_email(
Email.Event.event_updated( Email.Event.event_updated(
participant,
participant_user.email, participant_user.email,
participant_actor, participant_actor,
event, event,