🐛 Fix item version update related notification (#470)

* version notification
* updated version notification e2e test

---------

Co-authored-by: Monta <monta@HP-ProBook-445-14-inch-G9-Notebook-PC-505aadfc.localdomain>
This commit is contained in:
Montassar Ghanmy
2024-03-22 17:16:08 +01:00
committed by GitHub
parent 574d6438b2
commit 01145bbe83
4 changed files with 21 additions and 15 deletions
@@ -477,8 +477,9 @@ export class DocumentsService {
if (key === "access_info") { if (key === "access_info") {
const sharedWith = content.access_info.entities.filter( const sharedWith = content.access_info.entities.filter(
info => info =>
!item.access_info.entities.find(entity => entity.id === info.id) && info.type === "user" &&
info.type === "user", info.id !== context.user.id &&
!item.access_info.entities.find(entity => entity.id === info.id),
); );
item.access_info = content.access_info; item.access_info = content.access_info;
@@ -791,16 +792,18 @@ export class DocumentsService {
await this.repository.save(item); await this.repository.save(item);
// Notify the user that the document versions have been updated // Notify the user that the document versions have been updated
this.logger.info("Notifying user that the document has been updated: ", { if (context.user.id !== item.creator) {
item, this.logger.info("Notifying user that the document has been updated: ", {
notificationEmitter: context.user.id, item,
}); notificationEmitter: context.user.id,
gr.services.documents.engine.notifyDocumentVersionUpdated({ });
context, gr.services.documents.engine.notifyDocumentVersionUpdated({
item, context,
notificationEmitter: context.user.id, item,
notificationReceiver: item.creator, notificationEmitter: context.user.id,
}); notificationReceiver: item.creator,
});
}
await updateItemSize(item.parent_id, this.repository, context); await updateItemSize(item.parent_id, this.repository, context);
@@ -99,7 +99,7 @@ export default class UserApi {
return filesUpload.resource; return filesUpload.resource;
} }
private getJWTTokenForUser(userId: string): string { public getJWTTokenForUser(userId: string): string {
const payload = { const payload = {
sub: userId, sub: userId,
role: "" role: ""
@@ -73,6 +73,8 @@ describe("the Drive feature", () => {
it("Did notify the user after creating a new version for a file.", async () => { it("Did notify the user after creating a new version for a file.", async () => {
const item = await currentUser.createDefaultDocument(); const item = await currentUser.createDefaultDocument();
const oneUser = await UserApi.getInstance(platform, true, { companyRole: "admin" });
const oneUserJWT = await platform.auth.getJWTToken({ sub: oneUser.user.id });
const fileUploadResponse = await e2e_createDocumentFile(platform); const fileUploadResponse = await e2e_createDocumentFile(platform);
const fileUploadResult = deserialize<ResourceUpdateResponse<File>>( const fileUploadResult = deserialize<ResourceUpdateResponse<File>>(
ResourceUpdateResponse, ResourceUpdateResponse,
@@ -81,7 +83,7 @@ describe("the Drive feature", () => {
const file_metadata = { external_id: fileUploadResult.resource.id }; const file_metadata = { external_id: fileUploadResult.resource.id };
await e2e_createVersion(platform, item.id, { filename: "file2", file_metadata }); await e2e_createVersion(platform, item.id, { filename: "file2", file_metadata }, oneUserJWT);
expect(notifyDocumentVersionUpdated).toHaveBeenCalled(); expect(notifyDocumentVersionUpdated).toHaveBeenCalled();
}); });
@@ -40,8 +40,9 @@ export const e2e_createVersion = async (
platform: TestPlatform, platform: TestPlatform,
id: string, id: string,
payload: Partial<FileVersion>, payload: Partial<FileVersion>,
jwt?: string,
) => { ) => {
const token = await platform.auth.getJWTToken(); const token = jwt ?? (await platform.auth.getJWTToken());
return await platform.app.inject({ return await platform.app.inject({
method: "POST", method: "POST",