Skip to content

Commit a5a10ea

Browse files
committed
fix: unecessary get all projects call for superadmins
1 parent 9844201 commit a5a10ea

2 files changed

Lines changed: 21 additions & 23 deletions

File tree

‎packages/api-gateway/src/modules/auth/auth.controller.ts‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,10 @@ export class AuthController implements OnModuleInit {
312312
this.apiKeyService.deleteApiKey({ id }),
313313
);
314314
if (!deleteResponse.success) {
315-
throw new HttpException('API Key deletion failed', HttpStatus.INTERNAL_SERVER_ERROR);
315+
throw new HttpException(
316+
'API Key deletion failed',
317+
HttpStatus.INTERNAL_SERVER_ERROR,
318+
);
316319
}
317320
return;
318321
}
@@ -365,27 +368,23 @@ export class AuthController implements OnModuleInit {
365368
@Query('limit', new DefaultValuePipe(10), ParseIntPipe) limit: number,
366369
) {
367370
if (limit <= 0) {
368-
throw new HttpException('limit must be a positive integer', HttpStatus.BAD_REQUEST);
371+
throw new HttpException(
372+
'limit must be a positive integer',
373+
HttpStatus.BAD_REQUEST,
374+
);
369375
}
370-
) {
376+
371377
if (!user) {
372378
throw new UnauthorizedException('User ID token is required');
373379
}
374380

375381
let obs: Observable<ApiKeyProto.GetAllApiKeysResponse>;
376382
if (user.type == CommonProto.UserType.SUPERADMIN) {
377-
// superadmins can list all projects
378-
const projects = (
379-
await lastValueFrom(
380-
this.projectService.getAllProjects({ projectIds: [] }),
381-
)
382-
).projects;
383+
// superadmins can list all keys — pass empty projects to skip filtering
383384
obs = this.apiKeyService.getAllApiKeys({
384385
offset,
385386
limit,
386-
projects: projects.map((proj) =>
387-
proj.id ? { id: proj.id } : { name: proj.name },
388-
),
387+
projects: [],
389388
});
390389
} else if (user.type == CommonProto.UserType.ADMIN && user.projectIds) {
391390
// regular users can only list keys for projects which they are an admin for

‎packages/db-service/src/modules/auth/auth.controller.ts‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,16 @@ export class ApiKeyDbController
2727
async getAllApiKeys(
2828
request: ApiKeyProto.GetAllApiKeysParams,
2929
): Promise<ApiKeyProto.GetAllApiKeysResult> {
30-
if (!request.projects || request.projects.length === 0) {
31-
return { keys: [], count: 0 };
32-
}
33-
34-
const whereClause: Prisma.ApiKeyWhereInput = {
35-
OR: request.projects.map((proj) =>
36-
proj.id != null
37-
? { projectId: Number(proj.id) }
38-
: { project: { name: proj.name } },
39-
),
40-
};
30+
const whereClause: Prisma.ApiKeyWhereInput | undefined =
31+
request.projects && request.projects.length > 0
32+
? {
33+
OR: request.projects.map((proj) =>
34+
proj.id != null
35+
? { projectId: Number(proj.id) }
36+
: { project: { name: proj.name } },
37+
),
38+
}
39+
: undefined;
4140

4241
const keys = await this.apiKeyService.apiKeys(
4342
request.offset,

0 commit comments

Comments
 (0)