Skip to content

Commit 90d7f19

Browse files
committed
Replace Privileges.forUser(session, context) -> forContext()
1 parent 4b841a0 commit 90d7f19

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/components/prompts/prompt-variant-response.service.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const PromptVariantResponseListService = <
8787
session: Session,
8888
): Promise<PromptVariantResponseList<TVariant>> {
8989
const context = parent as any;
90-
const edge = this.repo.edge.forUser(session, context);
90+
const edge = this.repo.edge.forContext(context);
9191
const canRead = edge.can('read');
9292
if (!canRead) {
9393
return {
@@ -97,7 +97,7 @@ export const PromptVariantResponseListService = <
9797
}
9898
const results = await this.repo.list(parent.id, session);
9999

100-
const privileges = this.resourcePrivileges.forUser(session, context);
100+
const privileges = this.resourcePrivileges.forContext(context);
101101

102102
const [secured, prompts, variants] = await Promise.all([
103103
mapListResults(results, async (dto) => await this.secure(dto, session)),
@@ -130,7 +130,7 @@ export const PromptVariantResponseListService = <
130130
session: Session,
131131
): Promise<PromptVariantResponse<TVariant>> {
132132
const context = await this.getPrivilegeContext(dto);
133-
const privileges = this.resourcePrivileges.forUser(session, context);
133+
const privileges = this.resourcePrivileges.forContext(context);
134134
const responses = mapKeys.fromList(dto.responses, (r) => r.variant).asMap;
135135
const secured = privileges.secure(dto);
136136
return {
@@ -174,8 +174,7 @@ export const PromptVariantResponseListService = <
174174
edge.resource,
175175
input.resource,
176176
);
177-
const privileges = edge.forUser(
178-
session,
177+
const privileges = edge.forContext(
179178
// @ts-expect-error yeah it's not unsecured, but none of our conditions actually needs that.
180179
parent,
181180
);
@@ -194,7 +193,7 @@ export const PromptVariantResponseListService = <
194193
): Promise<PromptVariantResponse<TVariant>> {
195194
const response = await this.repo.readOne(input.id, session);
196195
const context = await this.getPrivilegeContext(response);
197-
const privileges = this.resourcePrivileges.forUser(session, context);
196+
const privileges = this.resourcePrivileges.forContext(context);
198197
privileges.verifyCan('edit', 'prompt');
199198

200199
await this.getPromptById(input.prompt);
@@ -214,7 +213,7 @@ export const PromptVariantResponseListService = <
214213

215214
const response = await this.repo.readOne(input.id, session);
216215
const context = await this.getPrivilegeContext(response);
217-
const privileges = this.resourcePrivileges.forUser(session, context);
216+
const privileges = this.resourcePrivileges.forContext(context);
218217

219218
const perm = privileges
220219
.forContext(withVariant(privileges.context!, variant.key))
@@ -261,7 +260,7 @@ export const PromptVariantResponseListService = <
261260
const response = await this.repo.readOne(id, session);
262261

263262
const context = await this.getPrivilegeContext(response);
264-
const privileges = this.resourcePrivileges.forUser(session, context);
263+
const privileges = this.resourcePrivileges.forContext(context);
265264
privileges.verifyCan('delete');
266265

267266
await this.repo.deleteNode(id);

src/components/user/user.repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export class UserRepository extends DtoRepository<typeof User, [Session | ID]>(
216216

217217
async delete(id: ID, session: Session, object: User): Promise<void> {
218218
const user = await this.readOne(id, session);
219-
this.privileges.forUser(session, user).verifyCan('delete');
219+
this.privileges.forContext(user).verifyCan('delete');
220220
try {
221221
await this.db.deleteNode(object);
222222
} catch (exception) {

0 commit comments

Comments
 (0)