Skip to content

Commit

Permalink
Allow paragraph creator to modify (#408)
Browse files Browse the repository at this point in the history
* Allow paragraph creator to modify

* Add tests
  • Loading branch information
minottic authored Oct 23, 2024
1 parent e0815d8 commit 60a7788
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
'[email protected]',
]),
expect(result.body.deleteACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.shareACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.adminACL).to.be.eql(['admin'])
Expand Down
2 changes: 1 addition & 1 deletion sci-log-db/src/mixins/basesnippet.repository-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
17 changes: 15 additions & 2 deletions sci-log-db/src/repositories/autoadd.repository.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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];
}

Expand Down

0 comments on commit 60a7788

Please sign in to comment.