Merge branch 'use-correct-locale-for-participation-emails' into 'master'

Use correct locale for participation emails

Closes #339

See merge request framasoft/mobilizon!448
This commit is contained in:
Thomas Citharel 2020-06-09 11:05:28 +02:00
commit d25e63cabb
7 changed files with 66 additions and 47 deletions

View File

@ -1,6 +1,6 @@
<template> <template>
<section class="container section hero is-fullheight"> <section class="container section hero is-fullheight">
<div class="hero-body"> <div class="hero-body" v-if="event">
<div class="container"> <div class="container">
<form @submit.prevent="joinEvent"> <form @submit.prevent="joinEvent">
<p> <p>
@ -111,15 +111,22 @@ export default class ParticipationWithoutAccount extends Vue {
actorId: this.config.anonymous.actorId, actorId: this.config.anonymous.actorId,
email: this.anonymousParticipation.email, email: this.anonymousParticipation.email,
message: this.anonymousParticipation.message, message: this.anonymousParticipation.message,
locale: this.$i18n.locale,
}, },
update: (store, { data }) => { update: (store, { data }) => {
if (data == null) return; if (data == null) {
console.error("Cannot update event participant cache, because of data null value.");
return;
}
const cachedData = store.readQuery<{ event: IEvent }>({ const cachedData = store.readQuery<{ event: IEvent }>({
query: FETCH_EVENT, query: FETCH_EVENT,
variables: { uuid: this.event.uuid }, variables: { uuid: this.event.uuid },
}); });
if (cachedData == null) return; if (cachedData == null) {
console.error("Cannot update event participant cache, because of cached null value.");
return;
}
const { event } = cachedData; const { event } = cachedData;
if (event === null) { if (event === null) {
console.error("Cannot update event participant cache, because of null value."); console.error("Cannot update event participant cache, because of null value.");
@ -132,6 +139,7 @@ export default class ParticipationWithoutAccount extends Vue {
event.participantStats.going = event.participantStats.going + 1; event.participantStats.going = event.participantStats.going + 1;
event.participantStats.participant = event.participantStats.participant + 1; event.participantStats.participant = event.participantStats.participant + 1;
} }
console.log("just before writequery");
store.writeQuery({ store.writeQuery({
query: FETCH_EVENT, query: FETCH_EVENT,
@ -140,23 +148,26 @@ export default class ParticipationWithoutAccount extends Vue {
}); });
}, },
}); });
console.log("finished with store", data);
if (data && data.joinEvent.metadata.cancellationToken) { if (data && data.joinEvent.metadata.cancellationToken) {
await addLocalUnconfirmedAnonymousParticipation( await addLocalUnconfirmedAnonymousParticipation(
this.event, this.event,
data.joinEvent.metadata.cancellationToken data.joinEvent.metadata.cancellationToken
); );
return this.$router.push({ console.log("done with crypto stuff");
name: RouteName.EVENT,
params: { uuid: this.event.uuid },
});
} }
} catch (e) { } catch (e) {
console.log(JSON.stringify(e)); console.error(e);
if (e.message === "GraphQL error: You are already a participant of this event") { if (e.message === "GraphQL error: You are already a participant of this event") {
this.error = this.$t( this.error = this.$t(
"This email is already registered as participant for this event" "This email is already registered as participant for this event"
) as string; ) as string;
} }
} finally {
return this.$router.push({
name: RouteName.EVENT,
params: { uuid: this.event.uuid },
});
} }
} }
} }

View File

@ -409,12 +409,13 @@ export const EDIT_EVENT = gql`
`; `;
export const JOIN_EVENT = gql` export const JOIN_EVENT = gql`
mutation JoinEvent($eventId: ID!, $actorId: ID!, $email: String, $message: String) { mutation JoinEvent($eventId: ID!, $actorId: ID!, $email: String, $message: String, $locale: String) {
joinEvent( joinEvent(
eventId: $eventId, eventId: $eventId,
actorId: $actorId, actorId: $actorId,
email: $email, email: $email,
message: $message message: $message,
locale: $locale
) { ) {
${participantQuery} ${participantQuery}
} }

View File

@ -1159,9 +1159,9 @@
integrity sha512-6nlq2eEh75JegDGUXis9wGTYIJpUvbori4qx++PRKQsV3YRkaqUNPNykzphniqPSZADXCouBuAnyptjUkMkhvw== integrity sha512-6nlq2eEh75JegDGUXis9wGTYIJpUvbori4qx++PRKQsV3YRkaqUNPNykzphniqPSZADXCouBuAnyptjUkMkhvw==
"@types/node@*", "@types/node@>=6": "@types/node@*", "@types/node@>=6":
version "14.0.11" version "14.0.12"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.11.tgz#61d4886e2424da73b7b25547f59fdcb534c165a3" resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.12.tgz#9c1d8ffb8084e8936603a6122a7649e40e68e04b"
integrity sha512-lCvvI24L21ZVeIiyIUHZ5Oflv1hhHQ5E1S25IRlKIXaRkVgmXpJMI3wUJkmym2bTbCe+WoIibQnMVAU3FguaOg== integrity sha512-/sjzehvjkkpvLpYtN6/2dv5kg41otMGuHQUt9T2aiAuIfleCQRQHXXzF1eAw/qkZTj5Kcf4JSTf7EIizHocy6Q==
"@types/normalize-package-data@^2.4.0": "@types/normalize-package-data@^2.4.0":
version "2.4.0" version "2.4.0"
@ -1303,13 +1303,13 @@
eslint-scope "^5.0.0" eslint-scope "^5.0.0"
eslint-utils "^2.0.0" eslint-utils "^2.0.0"
"@typescript-eslint/experimental-utils@3.1.0": "@typescript-eslint/experimental-utils@3.2.0":
version "3.1.0" version "3.2.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-3.1.0.tgz#2d5dba7c2ac2a3da3bfa3f461ff64de38587a872" resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-3.2.0.tgz#4dab8fc9f44f059ec073470a81bb4d7d7d51e6c5"
integrity sha512-Zf8JVC2K1svqPIk1CB/ehCiWPaERJBBokbMfNTNRczCbQSlQXaXtO/7OfYz9wZaecNvdSvVADt6/XQuIxhC79w== integrity sha512-UbJBsk+xO9dIFKtj16+m42EvUvsjZbbgQ2O5xSTSfVT1Z3yGkL90DVu0Hd3029FZ5/uBgl+F3Vo8FAcEcqc6aQ==
dependencies: dependencies:
"@types/json-schema" "^7.0.3" "@types/json-schema" "^7.0.3"
"@typescript-eslint/typescript-estree" "3.1.0" "@typescript-eslint/typescript-estree" "3.2.0"
eslint-scope "^5.0.0" eslint-scope "^5.0.0"
eslint-utils "^2.0.0" eslint-utils "^2.0.0"
@ -1324,13 +1324,13 @@
eslint-visitor-keys "^1.1.0" eslint-visitor-keys "^1.1.0"
"@typescript-eslint/parser@^3.0.0": "@typescript-eslint/parser@^3.0.0":
version "3.1.0" version "3.2.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-3.1.0.tgz#9c02ba5d88ad2355672f39e6cd4176f172dd47f8" resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-3.2.0.tgz#d9d7867456b1b8ecae9e724269b0bc932f06cbca"
integrity sha512-NcDSJK8qTA2tPfyGiPes9HtVKLbksmuYjlgGAUs7Ld2K0swdWibnCq9IJx9kJN8JJdgUJSorFiGaPHBgH81F/Q== integrity sha512-Vhu+wwdevDLVDjK1lIcoD6ZbuOa93fzqszkaO3iCnmrScmKwyW/AGkzc2UvfE5TCoCXqq7Jyt6SOXjsIlpqF4A==
dependencies: dependencies:
"@types/eslint-visitor-keys" "^1.0.0" "@types/eslint-visitor-keys" "^1.0.0"
"@typescript-eslint/experimental-utils" "3.1.0" "@typescript-eslint/experimental-utils" "3.2.0"
"@typescript-eslint/typescript-estree" "3.1.0" "@typescript-eslint/typescript-estree" "3.2.0"
eslint-visitor-keys "^1.1.0" eslint-visitor-keys "^1.1.0"
"@typescript-eslint/typescript-estree@2.34.0": "@typescript-eslint/typescript-estree@2.34.0":
@ -1346,10 +1346,10 @@
semver "^7.3.2" semver "^7.3.2"
tsutils "^3.17.1" tsutils "^3.17.1"
"@typescript-eslint/typescript-estree@3.1.0": "@typescript-eslint/typescript-estree@3.2.0":
version "3.1.0" version "3.2.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.1.0.tgz#eaff52d31e615e05b894f8b9d2c3d8af152a5dd2" resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.2.0.tgz#c735f1ca6b4d3cd671f30de8c9bde30843e7ead8"
integrity sha512-+4nfYauqeQvK55PgFrmBWFVYb6IskLyOosYEmhH3mSVhfBp9AIJnjExdgDmKWoOBHRcPM8Ihfm2BFpZf0euUZQ== integrity sha512-uh+Y2QO7dxNrdLw7mVnjUqkwO/InxEqwN0wF+Za6eo3coxls9aH9kQ/5rSvW2GcNanebRTmsT5w1/92lAOb1bA==
dependencies: dependencies:
debug "^4.1.1" debug "^4.1.1"
eslint-visitor-keys "^1.1.0" eslint-visitor-keys "^1.1.0"
@ -4929,9 +4929,9 @@ ejs@^2.6.1:
integrity sha512-7vmuyh5+kuUyJKePhQfRQBhXV5Ce+RnaeeQArKu1EAMpL3WbgMt5WG6uQZpEVvYSSsxMXRKOewtDk9RaTKXRlA== integrity sha512-7vmuyh5+kuUyJKePhQfRQBhXV5Ce+RnaeeQArKu1EAMpL3WbgMt5WG6uQZpEVvYSSsxMXRKOewtDk9RaTKXRlA==
electron-to-chromium@^1.3.103, electron-to-chromium@^1.3.247, electron-to-chromium@^1.3.413: electron-to-chromium@^1.3.103, electron-to-chromium@^1.3.247, electron-to-chromium@^1.3.413:
version "1.3.464" version "1.3.465"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.464.tgz#fe13feaa08f6f865d3c89d5d72e54c194f463aa5" resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.465.tgz#d692e5c383317570c2bd82092a24a0308c6ccf29"
integrity sha512-Oo+0+CN9d2z6FToQW6Hwvi9ez09Y/usKwr0tsDsyg43a871zVJCi1nR0v03djLbRNcaCKjtrnVf2XJhTxEpPCg== integrity sha512-K/lUeT3NLAsJ5SHRDhK3/zd0tw7OUllYD8w+fTOXm6ljCPsp2qq+vMzxpLo8u1M27ZjZAjRbsA6rirvne2nAMQ==
elegant-spinner@^1.0.1: elegant-spinner@^1.0.1:
version "1.0.1" version "1.0.1"
@ -6373,12 +6373,12 @@ globby@^9.2.0:
slash "^2.0.0" slash "^2.0.0"
globule@^1.0.0: globule@^1.0.0:
version "1.3.1" version "1.3.2"
resolved "https://registry.yarnpkg.com/globule/-/globule-1.3.1.tgz#90a25338f22b7fbeb527cee63c629aea754d33b9" resolved "https://registry.yarnpkg.com/globule/-/globule-1.3.2.tgz#d8bdd9e9e4eef8f96e245999a5dee7eb5d8529c4"
integrity sha512-OVyWOHgw29yosRHCHo7NncwR1hW5ew0W/UrvtwvjefVJeQ26q4/8r8FmPsSF1hJ93IgWkyv16pCTz6WblMzm/g== integrity sha512-7IDTQTIu2xzXkT+6mlluidnWo+BypnbSoEVVQCGfzqnl5Ik8d3e1d4wycb8Rj9tWW+Z39uPWsdlquqiqPCd/pA==
dependencies: dependencies:
glob "~7.1.1" glob "~7.1.1"
lodash "~4.17.12" lodash "~4.17.10"
minimatch "~3.0.2" minimatch "~3.0.2"
glogg@^1.0.2: glogg@^1.0.2:
@ -8572,7 +8572,7 @@ lodash.uniq@^4.5.0:
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M= integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=
lodash@4.17.15, lodash@^4.0.0, lodash@^4.16.4, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.2, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.2.0, lodash@~4.17.12: lodash@4.17.15, lodash@^4.0.0, lodash@^4.16.4, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.2, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.2.0, lodash@~4.17.10:
version "4.17.15" version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A== integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
@ -13323,9 +13323,9 @@ thread-loader@^2.1.3:
neo-async "^2.6.0" neo-async "^2.6.0"
throttle-debounce@^2.1.0: throttle-debounce@^2.1.0:
version "2.1.0" version "2.2.1"
resolved "https://registry.yarnpkg.com/throttle-debounce/-/throttle-debounce-2.1.0.tgz#257e648f0a56bd9e54fe0f132c4ab8611df4e1d5" resolved "https://registry.yarnpkg.com/throttle-debounce/-/throttle-debounce-2.2.1.tgz#fbd933ae6793448816f7d5b3cae259d464c98137"
integrity sha512-AOvyNahXQuU7NN+VVvOOX+uW6FPaWdAOdRP5HfwYxAfCzXTFKRMoIMk+n+po318+ktcChx+F1Dd91G3YHeMKyg== integrity sha512-i9hAVld1f+woAiyNGqWelpDD5W1tpMroL3NofTz9xzwq6acWBlO2dC8k5EFSZepU6oOINtV5Q3aSPoRg7o4+fA==
throttleit@^1.0.0: throttleit@^1.0.0:
version "1.0.0" version "1.0.0"
@ -14320,9 +14320,9 @@ vue-i18n-extract@^1.0.2:
js-yaml "^3.13.1" js-yaml "^3.13.1"
vue-i18n@^8.14.0: vue-i18n@^8.14.0:
version "8.18.1" version "8.18.2"
resolved "https://registry.yarnpkg.com/vue-i18n/-/vue-i18n-8.18.1.tgz#2e683ac93a15617bdcd210f99359d6034e8425dd" resolved "https://registry.yarnpkg.com/vue-i18n/-/vue-i18n-8.18.2.tgz#cd7c12f2e178e6faa23b0e3cfd2f7bac9305f8fc"
integrity sha512-K+hFQJksF8Ph23pnhbwSyoQx+4Y1q/rh2o7GiXI/3rLCCrwanUbzudC8+trp0Mb8rn9y83DYF6RXNrMd+VsuCw== integrity sha512-0X5nBTCZAVjlwcrPaYJwNs3iipBBTv0AUHwQUOa8yP3XbQGWKbRHqBb3OhCYtum/IHDD21d/df5Xd2VgyxbxfA==
vue-inbrowser-compiler-utils@^4.23.3: vue-inbrowser-compiler-utils@^4.23.3:
version "4.23.3" version "4.23.3"

View File

@ -69,7 +69,10 @@ defmodule Mobilizon.GraphQL.Resolvers.Participant do
Config.anonymous_participation_email_confirmation_required?() do Config.anonymous_participation_email_confirmation_required?() do
args args
|> Map.get(:email) |> Map.get(:email)
|> Email.Participation.anonymous_participation_confirmation(participant) |> Email.Participation.anonymous_participation_confirmation(
participant,
Map.get(args, :locale, "en")
)
|> Email.Mailer.deliver_later() |> Email.Mailer.deliver_later()
end end

View File

@ -43,6 +43,7 @@ defmodule Mobilizon.GraphQL.Schema.Events.ParticipantType do
) )
field(:message, :string, description: "The eventual message the participant left") field(:message, :string, description: "The eventual message the participant left")
field(:locale, :string, description: "The participant's locale")
end end
object :paginated_participant_list do object :paginated_participant_list do
@ -74,6 +75,7 @@ defmodule Mobilizon.GraphQL.Schema.Events.ParticipantType do
arg(:actor_id, non_null(:id)) arg(:actor_id, non_null(:id))
arg(:email, :string) arg(:email, :string)
arg(:message, :string) arg(:message, :string)
arg(:locale, :string)
resolve(&Participant.actor_join_event/3) resolve(&Participant.actor_join_event/3)
end end

View File

@ -24,7 +24,7 @@ defmodule Mobilizon.Events.Participant do
@required_attrs [:url, :role, :event_id, :actor_id] @required_attrs [:url, :role, :event_id, :actor_id]
@attrs @required_attrs @attrs @required_attrs
@metadata_attrs [:email, :confirmation_token, :cancellation_token, :message] @metadata_attrs [:email, :confirmation_token, :cancellation_token, :message, :locale]
@timestamps_opts [type: :utc_datetime] @timestamps_opts [type: :utc_datetime]
@ -38,6 +38,7 @@ defmodule Mobilizon.Events.Participant do
field(:confirmation_token, :string) field(:confirmation_token, :string)
field(:cancellation_token, :string) field(:cancellation_token, :string)
field(:message, :string) field(:message, :string)
field(:locale, :string)
end end
belongs_to(:event, Event, primary_key: true) belongs_to(:event, Event, primary_key: true)

View File

@ -21,10 +21,11 @@ defmodule Mobilizon.Web.Email.Participation do
%Participant{actor: %Actor{user_id: nil, id: actor_id} = _actor} = participation %Participant{actor: %Actor{user_id: nil, id: actor_id} = _actor} = participation
) do ) do
if actor_id == Config.anonymous_actor_id() do if actor_id == Config.anonymous_actor_id() do
%{email: email} = Map.get(participation, :metadata) %{email: email, locale: locale} = Map.get(participation, :metadata)
locale = locale || "en"
email email
|> participation_updated(participation) |> participation_updated(participation, locale)
|> Email.Mailer.deliver_later() |> Email.Mailer.deliver_later()
end end
@ -37,9 +38,9 @@ defmodule Mobilizon.Web.Email.Participation do
def send_emails_to_local_user( def send_emails_to_local_user(
%Participant{actor: %Actor{user_id: user_id} = _actor} = participation %Participant{actor: %Actor{user_id: user_id} = _actor} = participation
) do ) do
with %User{} = user <- Users.get_user!(user_id) do with %User{locale: locale} = user <- Users.get_user!(user_id) do
user user
|> participation_updated(participation) |> participation_updated(participation, locale)
|> Email.Mailer.deliver_later() |> Email.Mailer.deliver_later()
:ok :ok