diff --git a/sci-log-db/src/__tests__/acceptance/basesnippet.controller.acceptance.ts b/sci-log-db/src/__tests__/acceptance/basesnippet.controller.acceptance.ts index fd1bbf92..12eaf633 100644 --- a/sci-log-db/src/__tests__/acceptance/basesnippet.controller.acceptance.ts +++ b/sci-log-db/src/__tests__/acceptance/basesnippet.controller.acceptance.ts @@ -461,11 +461,16 @@ describe('Basesnippet', function (this: Suite) { .expect(200) .then( result => ( - expect(result.body).to.containEql(_.omit(baseSnippet, 'ownerGroup')), + expect(result.body).to.containEql( + _.omit(baseSnippet, ['ownerGroup', 'updateACL']), + ), expect(result.body.snippetType).to.be.eql('base'), expect(result.body.readACL).to.be.eql(['basesnippetAcceptance']), expect(result.body.createACL).to.be.eql(['basesnippetAcceptance']), - expect(result.body.updateACL).to.be.eql(['basesnippetAcceptance']), + expect(result.body.updateACL).to.be.eql([ + 'basesnippetAcceptance', + 'test@loopback.io', + ]), expect(result.body.deleteACL).to.be.eql(['basesnippetAcceptance']), expect(result.body.shareACL).to.be.eql(['basesnippetAcceptance']), expect(result.body.adminACL).to.be.eql(['admin']) diff --git a/sci-log-db/src/mixins/basesnippet.repository-mixin.ts b/sci-log-db/src/mixins/basesnippet.repository-mixin.ts index 06bbd417..c3f087d1 100644 --- a/sci-log-db/src/mixins/basesnippet.repository-mixin.ts +++ b/sci-log-db/src/mixins/basesnippet.repository-mixin.ts @@ -146,7 +146,7 @@ function UpdateAndDeleteRepositoryMixin< acl => basesnippet[acl as keyof typeof basesnippet], ) ) - await self['aclDefaultOnCreation'](merge); + await self['aclDefaultOnCreation'](merge, false); return this.getChanged(merge, snippet); } diff --git a/sci-log-db/src/repositories/autoadd.repository.base.ts b/sci-log-db/src/repositories/autoadd.repository.base.ts index d1365786..90bf917a 100644 --- a/sci-log-db/src/repositories/autoadd.repository.base.ts +++ b/sci-log-db/src/repositories/autoadd.repository.base.ts @@ -85,6 +85,7 @@ export class AutoAddRepository< ownerGroup?: string; accessGroups?: string[]; }, + isNewInstance = true, ) { const emptyAcls = this.acls.filter(acl => !data[acl as keyof Basesnippet]); if (emptyAcls) { @@ -108,7 +109,13 @@ export class AutoAddRepository< await this.addToACLIfNotEmpty( emptyAcls, data, - _.partial(this.defaultAllButLocationLogbookACL.bind(this), parent), + _.partial( + this.defaultAllButLocationLogbookACL.bind(this), + parent, + _, + _, + isNewInstance, + ), ); } delete data.ownerGroup; @@ -173,12 +180,18 @@ export class AutoAddRepository< private defaultAllButLocationLogbookACL( parent: Basesnippet, aclType: string, - data: {accessGroups?: string[]}, + data: { + accessGroups?: string[]; + createdBy?: string[]; + }, + isNewInstance = true, ) { if (aclType === 'shareACL') return arrayOfUniqueFrom(parent.shareACL, parent.readACL); if (aclType === 'readACL') return arrayOfUniqueFrom(parent.readACL, data.accessGroups); + if (aclType === 'updateACL' && isNewInstance) + return arrayOfUniqueFrom(parent.updateACL, data.createdBy); return parent[aclType as keyof Basesnippet]; }