🐛 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") {
const sharedWith = content.access_info.entities.filter(
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;
@@ -791,16 +792,18 @@ export class DocumentsService {
await this.repository.save(item);
// Notify the user that the document versions have been updated
this.logger.info("Notifying user that the document has been updated: ", {
item,
notificationEmitter: context.user.id,
});
gr.services.documents.engine.notifyDocumentVersionUpdated({
context,
item,
notificationEmitter: context.user.id,
notificationReceiver: item.creator,
});
if (context.user.id !== item.creator) {
this.logger.info("Notifying user that the document has been updated: ", {
item,
notificationEmitter: context.user.id,
});
gr.services.documents.engine.notifyDocumentVersionUpdated({
context,
item,
notificationEmitter: context.user.id,
notificationReceiver: item.creator,
});
}
await updateItemSize(item.parent_id, this.repository, context);
@@ -99,7 +99,7 @@ export default class UserApi {
return filesUpload.resource;
}
private getJWTTokenForUser(userId: string): string {
public getJWTTokenForUser(userId: string): string {
const payload = {
sub: userId,
role: ""
@@ -73,6 +73,8 @@ describe("the Drive feature", () => {
it("Did notify the user after creating a new version for a file.", async () => {
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 fileUploadResult = deserialize<ResourceUpdateResponse<File>>(
ResourceUpdateResponse,
@@ -81,7 +83,7 @@ describe("the Drive feature", () => {
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();
});
@@ -40,8 +40,9 @@ export const e2e_createVersion = async (
platform: TestPlatform,
id: string,
payload: Partial<FileVersion>,
jwt?: string,
) => {
const token = await platform.auth.getJWTToken();
const token = jwt ?? (await platform.auth.getJWTToken());
return await platform.app.inject({
method: "POST",