✨ Translate notifications (#581)
Co-authored-by: Monta <monta@HP-ProBook-445-14-inch-G9-Notebook-PC-505aadfc.localdomain> Co-authored-by: Eric Doughty-Papassideris <edoughtypapassideris@linagora.com>
This commit is contained in:
@@ -95,7 +95,6 @@ export default class EmailPusherClass
|
|||||||
if (!existsSync(subjectPath)) {
|
if (!existsSync(subjectPath)) {
|
||||||
throw Error(`subject template not found: ${subjectPath}`);
|
throw Error(`subject template not found: ${subjectPath}`);
|
||||||
}
|
}
|
||||||
console.log("🚀 FILE LINK: ", encodedUrl);
|
|
||||||
const html = await Eta.renderFile(templatePath, {
|
const html = await Eta.renderFile(templatePath, {
|
||||||
...data,
|
...data,
|
||||||
encodedUrl,
|
encodedUrl,
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
Notifications manquées dans votre Twake Drive
|
Notifications non reçues dans votre Twake Drive
|
||||||
+1
-1
@@ -1 +1 @@
|
|||||||
Notifications manquées dans votre Twake Drive
|
Notifications non reçues dans votre Twake Drive
|
||||||
+1
-1
@@ -1 +1 @@
|
|||||||
Notifications manquées dans votre Twake Drive
|
Notifications non reçues dans votre Twake Drive
|
||||||
@@ -16,6 +16,7 @@ export class DocumentsEngine implements Initializable {
|
|||||||
const company = await globalResolver.services.companies.getCompany({
|
const company = await globalResolver.services.companies.getCompany({
|
||||||
id: e.context.company.id,
|
id: e.context.company.id,
|
||||||
});
|
});
|
||||||
|
const language = receiver.preferences?.language || "en";
|
||||||
const emailTemplate =
|
const emailTemplate =
|
||||||
event === DocumentEvents.DOCUMENT_SAHRED
|
event === DocumentEvents.DOCUMENT_SAHRED
|
||||||
? "notification-document-shared"
|
? "notification-document-shared"
|
||||||
@@ -23,7 +24,7 @@ export class DocumentsEngine implements Initializable {
|
|||||||
try {
|
try {
|
||||||
const { html, text, subject } = await globalResolver.platformServices.emailPusher.build(
|
const { html, text, subject } = await globalResolver.platformServices.emailPusher.build(
|
||||||
emailTemplate,
|
emailTemplate,
|
||||||
receiver.language || "en",
|
language,
|
||||||
{
|
{
|
||||||
sender,
|
sender,
|
||||||
receiver,
|
receiver,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { describe, beforeEach, it, expect, afterAll, jest } from "@jest/globals"
|
|||||||
import { init, TestPlatform } from "../setup";
|
import { init, TestPlatform } from "../setup";
|
||||||
import UserApi from "../common/user-api";
|
import UserApi from "../common/user-api";
|
||||||
import { DocumentsEngine } from "../../../src/services/documents/services/engine";
|
import { DocumentsEngine } from "../../../src/services/documents/services/engine";
|
||||||
|
import EmailPusherClass from "../../../src/core/platform/services/email-pusher";
|
||||||
import { deserialize } from "class-transformer";
|
import { deserialize } from "class-transformer";
|
||||||
import { File } from "../../../src/services/files/entities/file";
|
import { File } from "../../../src/services/files/entities/file";
|
||||||
import { ResourceUpdateResponse } from "../../../src/utils/types";
|
import { ResourceUpdateResponse } from "../../../src/utils/types";
|
||||||
@@ -14,6 +15,8 @@ describe("the Drive feature", () => {
|
|||||||
DocumentsEngine.prototype,
|
DocumentsEngine.prototype,
|
||||||
"notifyDocumentVersionUpdated",
|
"notifyDocumentVersionUpdated",
|
||||||
);
|
);
|
||||||
|
const DispatchDocumentEvent = jest.spyOn(DocumentsEngine.prototype, "DispatchDocumentEvent");
|
||||||
|
const buildEmailSpy = jest.spyOn(EmailPusherClass.prototype, "build");
|
||||||
let currentUser: UserApi;
|
let currentUser: UserApi;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
@@ -35,6 +38,7 @@ describe("the Drive feature", () => {
|
|||||||
"statistics",
|
"statistics",
|
||||||
"platform-services",
|
"platform-services",
|
||||||
"documents",
|
"documents",
|
||||||
|
"email-pusher"
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
currentUser = await UserApi.getInstance(platform);
|
currentUser = await UserApi.getInstance(platform);
|
||||||
@@ -126,4 +130,39 @@ describe("the Drive feature", () => {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Test the email language based on the user's language and the email subject
|
||||||
|
it("Did notify the user after sharing a file in the user's language.", async () => {
|
||||||
|
const oneUser = await UserApi.getInstance(platform, true, { companyRole: "admin", preferences: { language: "en" } });
|
||||||
|
const anotherUser = await UserApi.getInstance(platform, true, { companyRole: "admin", preferences: { language: "fr" }});
|
||||||
|
//upload files
|
||||||
|
const doc = await oneUser.uploadRandomFileAndCreateDocument();
|
||||||
|
const doc2 = await anotherUser.uploadRandomFileAndCreateDocument();
|
||||||
|
|
||||||
|
// shared the file
|
||||||
|
await oneUser.shareWithPermissions(doc, anotherUser.user.id, "read");
|
||||||
|
|
||||||
|
// expect the email to be sent in the receiver's language "fr"
|
||||||
|
expect(buildEmailSpy).toHaveBeenCalledWith(
|
||||||
|
// ignore the template name
|
||||||
|
expect.any(String),
|
||||||
|
// expect the language to be the receiver's language
|
||||||
|
anotherUser.user.preferences?.language || "fr",
|
||||||
|
// ignore the email context
|
||||||
|
expect.any(Object),
|
||||||
|
);
|
||||||
|
|
||||||
|
// do the same for the other user
|
||||||
|
await anotherUser.shareWithPermissions(doc2, oneUser.user.id, "read");
|
||||||
|
|
||||||
|
// expect the email to be sent in the receiver's language "en"
|
||||||
|
expect(buildEmailSpy).toHaveBeenCalledWith(
|
||||||
|
// ignore the template name
|
||||||
|
expect.any(String),
|
||||||
|
// expect the language to be the receiver's language
|
||||||
|
anotherUser.user.preferences?.language || "en",
|
||||||
|
// ignore the email context
|
||||||
|
expect.any(Object),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {FileServiceImpl} from "../../../src/services/files/services";
|
|||||||
import StorageAPI from "../../../src/core/platform/services/storage/provider";
|
import StorageAPI from "../../../src/core/platform/services/storage/provider";
|
||||||
import {SearchServiceAPI} from "../../../src/core/platform/services/search/api";
|
import {SearchServiceAPI} from "../../../src/core/platform/services/search/api";
|
||||||
import Session from "../../../src/services/console/entities/session";
|
import Session from "../../../src/services/console/entities/session";
|
||||||
|
import EmailPusherAPI from "../../../src/core/platform/services/email-pusher/provider";
|
||||||
|
|
||||||
type TokenPayload = {
|
type TokenPayload = {
|
||||||
sub: string;
|
sub: string;
|
||||||
@@ -30,6 +31,9 @@ export type User = {
|
|||||||
id: string;
|
id: string;
|
||||||
first_name?: string;
|
first_name?: string;
|
||||||
isWorkspaceModerator?: boolean;
|
isWorkspaceModerator?: boolean;
|
||||||
|
preferences?: {
|
||||||
|
language?: string;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface TestPlatform {
|
export interface TestPlatform {
|
||||||
@@ -40,6 +44,7 @@ export interface TestPlatform {
|
|||||||
app: FastifyInstance;
|
app: FastifyInstance;
|
||||||
database: DatabaseServiceAPI;
|
database: DatabaseServiceAPI;
|
||||||
storage: StorageAPI;
|
storage: StorageAPI;
|
||||||
|
emailPusher: EmailPusherAPI;
|
||||||
messageQueue: MessageQueueServiceAPI;
|
messageQueue: MessageQueueServiceAPI;
|
||||||
authService: AuthServiceAPI;
|
authService: AuthServiceAPI;
|
||||||
filesService: FileServiceImpl;
|
filesService: FileServiceImpl;
|
||||||
@@ -83,6 +88,7 @@ export async function init(
|
|||||||
const auth = platform.getProvider<AuthServiceAPI>("auth");
|
const auth = platform.getProvider<AuthServiceAPI>("auth");
|
||||||
const storage: StorageAPI = platform.getProvider<StorageAPI>("storage");
|
const storage: StorageAPI = platform.getProvider<StorageAPI>("storage");
|
||||||
const search: SearchServiceAPI = platform.getProvider<SearchServiceAPI>("search");
|
const search: SearchServiceAPI = platform.getProvider<SearchServiceAPI>("search");
|
||||||
|
const emailPusher: EmailPusherAPI = platform.getProvider<EmailPusherAPI>("email-pusher");
|
||||||
|
|
||||||
testPlatform = {
|
testPlatform = {
|
||||||
platform,
|
platform,
|
||||||
@@ -90,6 +96,7 @@ export async function init(
|
|||||||
messageQueue,
|
messageQueue,
|
||||||
database,
|
database,
|
||||||
storage,
|
storage,
|
||||||
|
emailPusher,
|
||||||
workspace: { company_id: "", workspace_id: "" },
|
workspace: { company_id: "", workspace_id: "" },
|
||||||
currentUser: { id: "" },
|
currentUser: { id: "" },
|
||||||
currentSession: uuidv1(),
|
currentSession: uuidv1(),
|
||||||
|
|||||||
@@ -130,6 +130,7 @@ export class TestDbService {
|
|||||||
cache?: User["cache"];
|
cache?: User["cache"];
|
||||||
identity_provider?: string;
|
identity_provider?: string;
|
||||||
type?: UserType;
|
type?: UserType;
|
||||||
|
preferences?: User["preferences"];
|
||||||
} = {},
|
} = {},
|
||||||
id: string = uuidv1(),
|
id: string = uuidv1(),
|
||||||
): Promise<User> {
|
): Promise<User> {
|
||||||
@@ -144,6 +145,10 @@ export class TestDbService {
|
|||||||
user.cache = options.cache || user.cache || { companies: [] };
|
user.cache = options.cache || user.cache || { companies: [] };
|
||||||
user.identity_provider = options.identity_provider || "console";
|
user.identity_provider = options.identity_provider || "console";
|
||||||
user.type = options.type || "regular";
|
user.type = options.type || "regular";
|
||||||
|
user.preferences = options.preferences || {
|
||||||
|
locale: "en",
|
||||||
|
timezone: 0,
|
||||||
|
};
|
||||||
|
|
||||||
//Fixme this is cheating, we should correctly set the cache in internal mode in the code
|
//Fixme this is cheating, we should correctly set the cache in internal mode in the code
|
||||||
user.cache.companies = [
|
user.cache.companies = [
|
||||||
|
|||||||
Reference in New Issue
Block a user