fix: Cannot mention users that have been explicitly added to document

This commit is contained in:
Tom Moor
2024-05-14 19:36:09 -04:00
parent 8120407bf3
commit 2ecc9009f0
3 changed files with 126 additions and 25 deletions

View File

@@ -194,6 +194,13 @@ type AdditionalFindOptions = {
],
};
},
withAllMemberships: {
include: [
{
association: "memberships",
},
],
},
}))
@Table({ tableName: "documents", modelName: "document" })
@Fix
@@ -535,6 +542,25 @@ class Document extends ParanoidModel<
@HasMany(() => View)
views: View[];
/**
* Returns an array of unique userIds that are members of a document via direct membership
*
* @param documentId
* @returns userIds
*/
static async membershipUserIds(documentId: string) {
const document = await this.scope("withAllMemberships").findOne({
where: {
id: documentId,
},
});
if (!document) {
return [];
}
return document.memberships.map((membership) => membership.userId);
}
static defaultScopeWithUser(userId: string) {
const collectionScope: Readonly<ScopeOptions> = {
method: ["withCollectionPermissions", userId],