Skip to content

Commit

Permalink
feat(api): Add ADMIN authority for API keys (keyshade-xyz#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdip-b authored Jan 9, 2025
1 parent 0ddfa59 commit fb6aba7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/validate-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ jobs:
run: |
pnpm run lint:api
- name: Build deps
run: |
pnpm run db:generate-types
pnpm run build:schema
- name: Unit tests
run: |
pnpm run db:generate-types
Expand Down
4 changes: 4 additions & 0 deletions apps/api/src/auth/guard/api-key/api-key.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export class ApiKeyGuard implements CanActivate {
throw new UnauthorizedException('The API key has no authorities.')
}

if (user.apiKeyAuthorities.has(Authority.ADMIN)) {
return true
}

for (const requiredAuthority of requiredAuthorities) {
if (!user.apiKeyAuthorities.has(requiredAuthority)) {
throw new UnauthorizedException(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "Authority" ADD VALUE 'ADMIN';
3 changes: 3 additions & 0 deletions apps/api/src/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ enum Authority {
READ_SELF
UPDATE_SELF
READ_EVENT
// Master authority
ADMIN
}

enum NotificationType {
Expand Down

0 comments on commit fb6aba7

Please sign in to comment.