Skip to content

Commit

Permalink
Add computed ACLS also when in payload
Browse files Browse the repository at this point in the history
  • Loading branch information
minottic committed Oct 22, 2024
1 parent e0815d8 commit 6221b2a
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions sci-log-db/src/repositories/autoadd.repository.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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,
);
}
}),
);
}
Expand Down

0 comments on commit 6221b2a

Please sign in to comment.