Add privilege management system with related migrations and guards
- Introduced a new `PrivilegesModule` to manage user privileges and access control. - Added `RequirePrivilege` decorator to enforce privilege checks on controller handlers. - Implemented `PrivilegesGuard` to handle authorization based on user privileges. - Created database migrations for `privileges`, `privilege_keys`, and `privilege_details` tables. - Updated user model to include `is_superadmin` field for enhanced access control. - Added unit tests for the new privileges functionality and guards to ensure correct behavior.
This commit is contained in:
@@ -5,6 +5,8 @@ import { JwtModule } from '@nestjs/jwt';
|
||||
import { PassportModule } from '@nestjs/passport';
|
||||
import { ThrottlerGuard, ThrottlerModule } from '@nestjs/throttler';
|
||||
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
|
||||
import { PrivilegesGuard } from '../../common/guards/privileges.guard';
|
||||
import { PrivilegesModule } from '../privileges/privileges.module';
|
||||
import { UsersModule } from '../users/users.module';
|
||||
import { AuthController } from './auth.controller';
|
||||
import { AuthService } from './auth.service';
|
||||
@@ -15,6 +17,7 @@ import { JwtStrategy } from './strategies/jwt.strategy';
|
||||
@Module({
|
||||
imports: [
|
||||
UsersModule,
|
||||
PrivilegesModule,
|
||||
PassportModule.register({ defaultStrategy: 'jwt' }),
|
||||
JwtModule.registerAsync({
|
||||
imports: [ConfigModule],
|
||||
@@ -36,7 +39,9 @@ import { JwtStrategy } from './strategies/jwt.strategy';
|
||||
RefreshTokensRepository,
|
||||
RevokedAccessTokensRepository,
|
||||
JwtStrategy,
|
||||
// Registration order = execution order: JWT before privileges.
|
||||
{ provide: APP_GUARD, useClass: JwtAuthGuard },
|
||||
{ provide: APP_GUARD, useClass: PrivilegesGuard },
|
||||
{ provide: APP_GUARD, useClass: ThrottlerGuard },
|
||||
],
|
||||
exports: [AuthService],
|
||||
|
||||
Reference in New Issue
Block a user