From b9ca3580510449efadcb609ae62875b6d2c16ca0 Mon Sep 17 00:00:00 2001
From: Denis Bykhov
Date: Sat, 6 Jan 2024 22:43:57 +0600
Subject: [PATCH] UBERF-4845 (#4309)
Signed-off-by: Denis Bykhov
---
pods/account/src/index.ts | 10 ++++--
server/account/lang/en.json | 13 +++++++
server/account/lang/ru.json | 13 +++++++
server/account/src/index.ts | 68 ++++++++----------------------------
server/account/src/plugin.ts | 30 ++++++++++++++++
5 files changed, 79 insertions(+), 55 deletions(-)
create mode 100644 server/account/lang/en.json
create mode 100644 server/account/lang/ru.json
create mode 100644 server/account/src/plugin.ts
diff --git a/pods/account/src/index.ts b/pods/account/src/index.ts
index bb3073403f..e1a1cf4b4c 100644
--- a/pods/account/src/index.ts
+++ b/pods/account/src/index.ts
@@ -14,8 +14,8 @@
// limitations under the License.
//
-import account, { ACCOUNT_DB, AccountMethod } from '@hcengineering/account'
-import platform, { Severity, Status, setMetadata } from '@hcengineering/platform'
+import account, { ACCOUNT_DB, AccountMethod, accountId } from '@hcengineering/account'
+import platform, { Severity, Status, addStringsLoader, setMetadata } from '@hcengineering/platform'
import serverToken from '@hcengineering/server-token'
import toolPlugin from '@hcengineering/server-tool'
import cors from '@koa/cors'
@@ -50,9 +50,15 @@ export function serveAccount (methods: Record, productId
process.exit(1)
}
+ addStringsLoader(accountId, async (lang: string) => await import(`@hcengineering/account/lang/${lang}.json`))
+
const ses = process.env.SES_URL
const frontURL = process.env.FRONT_URL
+ const productName = process.env.PRODUCT_NAME
+ const lang = process.env.LANGUAGE ?? 'en'
+ setMetadata(platform.metadata.locale, lang)
+ setMetadata(account.metadata.ProductName, productName)
setMetadata(account.metadata.SES_URL, ses)
setMetadata(account.metadata.FrontURL, frontURL)
diff --git a/server/account/lang/en.json b/server/account/lang/en.json
new file mode 100644
index 0000000000..356727fdf3
--- /dev/null
+++ b/server/account/lang/en.json
@@ -0,0 +1,13 @@
+{
+ "string": {
+ "ConfirmationText": "Thank you for your interest in {name}. To complete the sign up process please copy the following link into your browser's URL bar {link}. Regards, {name} Team.",
+ "ConfirmationHTML": "Hello,
Thank you for your interest in {name}. To complete the sign up process please follow this link or copy the following link into your browser's URL bar.
{link}
Regards,
{name} Team.
",
+ "ConfirmationSubject": "Confirm your email address to sign up for {name}",
+ "RecoveryText": "We received a request to reset the password for your account. To reset your password, please paste the following link in your web browser's address bar: {link}. If you have not ordered a password recovery just ignore this letter.",
+ "RecoveryHTML": "We received a request to reset the password for your account. To reset your password, please click the link below: Reset password
If the Reset password link above does not work, paste the following link in your web browser's address bar: {link}
If you have not ordered a password recovery just ignore this letter.
",
+ "RecoverySubject": "Password recovery",
+ "InviteText": "You were invited to {ws}. To join please paste the following link in your web browser's address bar: {link}. Link valid for {expHours} hours.",
+ "InviteHTML": "You were invited to ${ws}. To join, please click the link below: Join
If the invite link above does not work, paste the following link in your web browser's address bar: {link}
Link valid for {expHours} hours.
",
+ "InviteSubject": "Invitation to {ws}"
+ }
+}
\ No newline at end of file
diff --git a/server/account/lang/ru.json b/server/account/lang/ru.json
new file mode 100644
index 0000000000..634fd21807
--- /dev/null
+++ b/server/account/lang/ru.json
@@ -0,0 +1,13 @@
+{
+ "string": {
+ "ConfirmationText": "Спасибо за ваш интерес к {name}. Для завершения регистрации скопируйте ссылку в адресную строку вашего браузера {link}. С уважением, Команда {name}.",
+ "ConfirmationHTML": "Здравствуйте,
Спасибо за ваш интерес к {name}. Для завершения регистрации пройдите по этой ссылке или скопируйте ссылку ниже в адресную строку вашего браузера.
{link}
С уважением,
Команда {name}.
",
+ "ConfirmationSubject": "Подтвердите адрес электронной почты для регистрации на {name}",
+ "RecoveryText": "Мы получили запрос на сброс пароля для вашей учетной записи. Чтобы сбросить пароль, пожалуйста, перейдите по ссылке ниже: {link}. Если вы не заказывали восстановление пароля, просто проигнорируйте это письмо.",
+ "RecoveryHTML": "Мы получили запрос на сброс пароля для вашей учетной записи. Чтобы сбросить пароль, пожалуйста, перейдите по ссылке ниже: Сбросить пароль
Если ссылка выше не работает, скопируйте следующую ссылку в адресную строку вашего браузера: {link}
Если вы не заказывали восстановление пароля, просто проигнорируйте это письмо.
",
+ "RecoverySubject": "Восстановление пароля",
+ "InviteText": "Вы были приглашены в {ws}. Чтобы присоединиться, пожалуйста, скопируйте ссылку ниже в адресную строку вашего браузера: {link}. Ссылка действительна в течение {expHours} ч.",
+ "InviteHTML": "Вы были приглашены в {ws}. Чтобы присоединиться, пожалуйста, скопируйте ссылку ниже в адресную строку вашего браузера: Присоединиться
Если ссылка выше не работает, скопируйте следующую ссылку в адресную строку вашего браузера: {link}
Ссылка действительна в течение {expHours} ч.
",
+ "InviteSubjectRU": "Приглашение в {ws}"
+ }
+}
\ No newline at end of file
diff --git a/server/account/src/index.ts b/server/account/src/index.ts
index 5c3d518ef1..f0f35204d2 100644
--- a/server/account/src/index.ts
+++ b/server/account/src/index.ts
@@ -36,21 +36,14 @@ import core, {
WorkspaceId
} from '@hcengineering/core'
import { consoleModelLogger, MigrateOperation, ModelLogger } from '@hcengineering/model'
-import platform, {
- getMetadata,
- Metadata,
- PlatformError,
- Plugin,
- plugin,
- Severity,
- Status
-} from '@hcengineering/platform'
+import platform, { getMetadata, PlatformError, Severity, Status, translate } from '@hcengineering/platform'
import { cloneWorkspace } from '@hcengineering/server-backup'
import { decodeToken, generateToken } from '@hcengineering/server-token'
import toolPlugin, { connect, initModel, upgradeModel } from '@hcengineering/server-tool'
import { pbkdf2Sync, randomBytes } from 'crypto'
import { Binary, Db, Filter, ObjectId } from 'mongodb'
import fetch from 'node-fetch'
+import accountPlugin, { accountId } from './plugin'
const WORKSPACE_COLLECTION = 'workspace'
const ACCOUNT_COLLECTION = 'account'
@@ -61,21 +54,6 @@ const INVITE_COLLECTION = 'invite'
*/
export const ACCOUNT_DB = 'account'
-/**
- * @public
- */
-export const accountId = 'account' as Plugin
-
-/**
- * @public
- */
-const accountPlugin = plugin(accountId, {
- metadata: {
- FrontURL: '' as Metadata,
- SES_URL: '' as Metadata
- }
-})
-
const getEndpoint = (): string => {
const endpoint = getMetadata(toolPlugin.metadata.Endpoint)
if (endpoint === undefined) {
@@ -433,25 +411,10 @@ async function sendConfirmation (productId: string, account: Account): PromiseЗдравствуйте,
- Спасибо за ваш интерес к Bold. Для завершения регистрации пройдите по этой ссылке или скопируйте ссылку ниже в адресную строку вашего браузера.
- ${link}
- С уважением,
- Команда Bold.
`
- let subject = 'Подтвердите адрес электронной почты для регистрации на Bold.ru'
-
- // A quick workaround for now to have confirmation email in english for ezqms.
- // Remove as soon as sever i18n is there.
- if (productId === 'ezqms') {
- text = `Thank you for your interest in ezQMS. To complete the sign up process please copy the following link into your browser's URL bar ${link}. Regards, ezQMS Team.`
- html = `Hello,
- Thank you for your interest in ezQMS. To complete the sign up process please follow this link or copy the following link into your browser's URL bar.
- ${link}
- Regards,
- ezQMS Team.
`
- subject = 'Confirm your email address to sign up for ezQMS'
- }
+ const name = getMetadata(accountPlugin.metadata.ProductName)
+ const text = await translate(accountPlugin.string.ConfirmationText, { name, link })
+ const html = await translate(accountPlugin.string.ConfirmationHTML, { name, link })
+ const subject = await translate(accountPlugin.string.ConfirmationSubject, { name })
if (sesURL !== undefined && sesURL !== '') {
const to = account.email
@@ -985,11 +948,10 @@ export async function requestPassword (db: Db, productId: string, _email: string
const link = concatLink(front, `/login/recovery?id=${token}`)
- const text = `We received a request to reset the password for your account. To reset your password, please paste the following link in your web browser's address bar: ${link}. If you have not ordered a password recovery just ignore this letter.`
- const html = `We received a request to reset the password for your account. To reset your password, please click the link below: Reset password
- If the Reset password link above does not work, paste the following link in your web browser's address bar: ${link}
-
If you have not ordered a password recovery just ignore this letter.
`
- const subject = 'Password recovery'
+ const text = await translate(accountPlugin.string.RecoveryText, { link })
+ const html = await translate(accountPlugin.string.RecoveryHTML, { link })
+ const subject = await translate(accountPlugin.string.RecoverySubject, {})
+
const to = account.email
await fetch(concatLink(sesURL, '/send'), {
method: 'post',
@@ -1161,12 +1123,11 @@ export async function sendInvite (db: Db, productId: string, token: string, emai
const inviteId = await getInviteLink(db, productId, token, exp, email, 1)
const link = concatLink(front, `/login/join?inviteId=${inviteId.toString()}`)
- const text = `You were invited to ${workspace.workspace}. To join please paste the following link in your web browser's address bar: ${link}. Link valid for ${expHours} hours.`
+ const ws = workspace.workspace
+ const text = await translate(accountPlugin.string.InviteText, { link, ws, expHours })
+ const html = await translate(accountPlugin.string.InviteHTML, { link, ws, expHours })
+ const subject = await translate(accountPlugin.string.InviteSubject, { ws })
- const html = `You were invited to ${workspace.workspace}. To join, please click the link below: Join
- If the invite link above does not work, paste the following link in your web browser's address bar: ${link}
-
Link valid for ${expHours} hours.
`
- const subject = `Invite to ${workspace.workspace}`
const to = email
await fetch(concatLink(sesURL, '/send'), {
method: 'post',
@@ -1257,4 +1218,5 @@ export function getMethods (
}
}
+export * from './plugin'
export default accountPlugin
diff --git a/server/account/src/plugin.ts b/server/account/src/plugin.ts
new file mode 100644
index 0000000000..03c92c913a
--- /dev/null
+++ b/server/account/src/plugin.ts
@@ -0,0 +1,30 @@
+import { IntlString, Metadata, plugin, Plugin } from '@hcengineering/platform'
+
+/**
+ * @public
+ */
+export const accountId = 'account' as Plugin
+
+/**
+ * @public
+ */
+const accountPlugin = plugin(accountId, {
+ metadata: {
+ FrontURL: '' as Metadata,
+ SES_URL: '' as Metadata,
+ ProductName: '' as Metadata
+ },
+ string: {
+ ConfirmationText: '' as IntlString,
+ ConfirmationHTML: '' as IntlString,
+ ConfirmationSubject: '' as IntlString,
+ RecoveryText: '' as IntlString,
+ RecoveryHTML: '' as IntlString,
+ RecoverySubject: '' as IntlString,
+ InviteText: '' as IntlString,
+ InviteHTML: '' as IntlString,
+ InviteSubject: '' as IntlString
+ }
+})
+
+export default accountPlugin