From 6221b2a3d7df3a07d6e7ce434ef99be3e30796e4 Mon Sep 17 00:00:00 2001 From: minottic Date: Tue, 22 Oct 2024 15:09:50 +0200 Subject: [PATCH] Add computed ACLS also when in payload --- .../repositories/autoadd.repository.base.ts | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/sci-log-db/src/repositories/autoadd.repository.base.ts b/sci-log-db/src/repositories/autoadd.repository.base.ts index d1365786..969fb683 100644 --- a/sci-log-db/src/repositories/autoadd.repository.base.ts +++ b/sci-log-db/src/repositories/autoadd.repository.base.ts @@ -86,31 +86,29 @@ export class AutoAddRepository< accessGroups?: string[]; }, ) { - const emptyAcls = this.acls.filter(acl => !data[acl as keyof Basesnippet]); - if (emptyAcls) { - const parent = await this.getParent(data); - if (data.snippetType === 'location') - await this.addToACLIfNotEmpty( - emptyAcls, - data, - this.defaultLocationACL.bind(this), - ); - else if (data.snippetType === 'logbook') { - const users = await this.getUnxGroupsEmail( - (parent as Location).location ?? '', - ); - await this.addToACLIfNotEmpty( - emptyAcls, - data, - _.partial(this.defaultLogbookACL.bind(this), users), - ); - } else - await this.addToACLIfNotEmpty( - emptyAcls, - data, - _.partial(this.defaultAllButLocationLogbookACL.bind(this), parent), - ); - } + const parent = await this.getParent(data); + const acls = [...this.acls]; + if (data.snippetType === 'location') + await this.addToACLIfNotEmpty( + acls, + data, + this.defaultLocationACL.bind(this), + ); + else if (data.snippetType === 'logbook') { + const users = await this.getUnxGroupsEmail( + (parent as Location).location ?? '', + ); + await this.addToACLIfNotEmpty( + acls, + data, + _.partial(this.defaultLogbookACL.bind(this), users), + ); + } else + await this.addToACLIfNotEmpty( + acls, + data, + _.partial(this.defaultAllButLocationLogbookACL.bind(this), parent), + ); delete data.ownerGroup; delete data.accessGroups; } @@ -126,8 +124,13 @@ export class AutoAddRepository< await callableFunction(k, data), [], ) as string[]; - if (aclValue.length > 0) - (data[k as keyof Basesnippet] as string[]) = aclValue; + if (aclValue.length > 0) { + const keyWithType = k as keyof Basesnippet; + (data[keyWithType] as string[]) = arrayOfUniqueFrom( + data[keyWithType], + aclValue, + ); + } }), ); }