UNPKG

@mamoorali295/rbac

Version:

Complete RBAC (Role-Based Access Control) system for Node.js with Express middleware, NestJS integration, GraphQL support, MongoDB & PostgreSQL support, modern admin dashboard, TypeScript support, and dynamic permission management

232 lines (231 loc) 6.06 kB
import { Request, Response } from 'express'; import { RbacAdminService } from './admin.service'; /** * NestJS Admin Controller for RBAC Dashboard * Provides web-based admin interface for managing users, roles, features, and permissions. * * Features: * - Session-based authentication * - User management with pagination and search * - Role and permission management * - Feature management * - Real-time dashboard statistics * * @example * ```typescript * // In your app.module.ts * @Module({ * imports: [ * RbacModule.forRoot({ * database: { type: 'mongodb', connection: mongooseConnection }, * authAdapter: async (req) => ({ user_id: req.user.id }), * defaultRole: 'user' * }), * RbacAdminModule.forRoot({ * adminCredentials: { * username: 'admin', * password: 'secure-password' * }, * sessionSecret: 'your-secret-key' * }) * ], * controllers: [RbacAdminController] * }) * export class AppModule {} * ``` */ export declare class RbacAdminController { private readonly adminService; constructor(adminService: RbacAdminService); /** * Display login page for admin authentication */ getLogin(res: Response, error?: string): void; /** * Handle admin login authentication */ postLogin(body: { username: string; password: string; }, session: any, res: Response): Promise<void>; /** * Handle admin logout */ logout(session: any, res: Response): void; /** * Dashboard home page with statistics */ getDashboard(res: Response): Promise<void>; /** * API endpoint for real-time dashboard statistics */ getStats(): Promise<{ timestamp: string; users: number; roles: number; features: number; permissions: number; }>; /** * Display users list with pagination and search */ getUsers(page: string | undefined, limit: string | undefined, search: string | undefined, res: Response): Promise<void>; /** * Display specific user details */ getUserDetails(userId: string, res: Response): Promise<void>; /** * Create a new user */ createUser(body: { user_id: string; name: string; email: string; }, res: Response): Promise<void>; /** * Update user information */ updateUser(userId: string, body: { name: string; email: string; }, res: Response): Promise<void>; /** * Assign role to user */ assignRole(userId: string, body: { roleName: string; }, req: Request, res: Response): Promise<void>; /** * Delete user */ deleteUser(userId: string): Promise<{ message: string; }>; /** * Display roles list */ getRoles(res: Response): Promise<void>; /** * Display specific role details */ getRoleDetails(roleId: string, res: Response): Promise<void>; /** * Create a new role */ createRole(body: { name: string; description: string; features?: Array<{ feature: string; permissions: string[]; }>; }, res: Response): Promise<Response<any, Record<string, any>> | undefined>; /** * Delete role */ deleteRole(roleId: string): Promise<{ success: boolean; message: string; }>; /** * Assign features and permissions to role */ assignRoleFeatures(roleId: string, body: { featurePermissions?: Array<{ feature_id: string; permission_ids: string[]; }>; featureIds?: string | string[]; }, res: Response): Promise<void>; /** * Remove permissions from a specific feature within a role */ removeRolePermissions(roleId: string, body: { featureIds: string | string[]; permissionIds: string | string[]; }): Promise<{ success: boolean; message: string; }>; /** * Add permissions to a specific feature within a role */ addRolePermissions(roleId: string, body: { featureIds: string | string[]; permissionIds: string | string[]; }, res: Response): Promise<void>; /** * Display features list */ getFeatures(res: Response): Promise<void>; /** * Display specific feature details */ getFeatureDetails(featureId: string, res: Response): Promise<void>; /** * Create a new feature */ createFeature(body: { name: string; description: string; }, res: Response): Promise<void>; /** * Update feature information */ updateFeature(featureId: string, body: { name: string; description: string; }): Promise<{ success: boolean; message: string; }>; /** * Delete feature */ deleteFeature(featureId: string): Promise<{ success: boolean; message: string; }>; /** * Display permissions list */ getPermissions(res: Response): Promise<void>; /** * Display specific permission details */ getPermissionDetails(permissionId: string, res: Response): Promise<void>; /** * Create a new permission */ createPermission(body: { name: string; description: string; }, res: Response): Promise<void>; /** * Create standard permissions (read, create, update, delete, sudo) */ createStandardPermissions(body: { permissions: Array<{ name: string; description: string; }>; }): Promise<{ message: string; permissions: any[]; }>; /** * Update permission information */ updatePermission(permissionId: string, body: { name: string; description: string; }): Promise<{ message: string; }>; /** * Delete permission */ deletePermission(permissionId: string): Promise<{ message: string; }>; }