🐛 Fix files notifications on shared folder (#369)
This commit is contained in:
@@ -369,19 +369,17 @@ export class DocumentsService {
|
|||||||
)
|
)
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
if (sharedWith.length > 0) {
|
if (context.user.id !== parentItem?.creator && sharedWith.length > 0) {
|
||||||
// Notify the user that the document has been shared with them
|
// Notify the owner that the document has been shared with them
|
||||||
this.logger.info("Notifying users that the document has been shared with them: ", {
|
this.logger.info("Notifying the onwer that the document has been shared with them: ", {
|
||||||
sharedWith,
|
sharedWith,
|
||||||
});
|
});
|
||||||
for (const info of sharedWith) {
|
gr.services.documents.engine.notifyDocumentShared({
|
||||||
gr.services.documents.engine.notifyDocumentShared({
|
context,
|
||||||
context,
|
item: driveItem,
|
||||||
item: driveItem,
|
notificationEmitter: context.user.id,
|
||||||
notificationEmitter: context.user.id,
|
notificationReceiver: parentItem.creator,
|
||||||
notificationReceiver: info.id,
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -49,7 +49,6 @@ describe("the Drive feature", () => {
|
|||||||
platform = null;
|
platform = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it("Did notify the user after sharing a file.", async () => {
|
it("Did notify the user after sharing a file.", async () => {
|
||||||
// jest.setTimeout(20000);
|
// jest.setTimeout(20000);
|
||||||
//given:: user uploaded one doc and give permission to another user
|
//given:: user uploaded one doc and give permission to another user
|
||||||
@@ -86,4 +85,45 @@ describe("the Drive feature", () => {
|
|||||||
|
|
||||||
expect(notifyDocumentVersionUpdated).toHaveBeenCalled();
|
expect(notifyDocumentVersionUpdated).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Did notify the owner after a user uploaded a file to a shared directory.", async () => {
|
||||||
|
const oneUser = await UserApi.getInstance(platform, true, { companyRole: "admin" });
|
||||||
|
const anotherUser = await UserApi.getInstance(platform, true, { companyRole: "admin" });
|
||||||
|
const thridUser = await UserApi.getInstance(platform, true, { companyRole: "admin" });
|
||||||
|
|
||||||
|
const directory = await oneUser.createDirectory();
|
||||||
|
directory.access_info.entities.push({
|
||||||
|
type: "user",
|
||||||
|
id: anotherUser.user.id,
|
||||||
|
level: "write",
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore
|
||||||
|
grantor: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
directory.access_info.entities.push({
|
||||||
|
type: "user",
|
||||||
|
id: thridUser.user.id,
|
||||||
|
level: "write",
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore
|
||||||
|
grantor: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
await anotherUser.uploadRandomFileAndCreateDocument(directory.id);
|
||||||
|
// expect the owner to be notified
|
||||||
|
expect(notifyDocumentShared).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
notificationEmitter: anotherUser.user.id,
|
||||||
|
notificationReceiver: oneUser.user.id,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
// expect only one notification went through (the owner only notified)
|
||||||
|
expect(notifyDocumentShared).not.toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
notificationEmitter: oneUser.user.id,
|
||||||
|
notificationReceiver: thridUser.user.id,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user