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

946 lines (945 loc) 40.6 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RbacAdminController = void 0; const common_1 = require("@nestjs/common"); const admin_service_1 = require("./admin.service"); const admin_auth_guard_1 = require("./guards/admin-auth.guard"); const dashboard_1 = require("../admin/views/dashboard"); const users_1 = require("../admin/views/users"); const roles_1 = require("../admin/views/roles"); const features_1 = require("../admin/views/features"); const permissions_1 = require("../admin/views/permissions"); const login_1 = require("../admin/views/login"); /** * 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 {} * ``` */ let RbacAdminController = class RbacAdminController { constructor(adminService) { this.adminService = adminService; } /** * Display login page for admin authentication */ getLogin(res, error) { res.send((0, login_1.getLoginView)('/rbac-admin')); } /** * Handle admin login authentication */ postLogin(body, session, res) { return __awaiter(this, void 0, void 0, function* () { try { if (!session) { throw new Error('Session middleware not configured. Please set up express-session middleware in your main.ts file. See documentation for setup instructions.'); } const isValid = yield this.adminService.validateAdmin(body.username, body.password); if (isValid) { session.authenticated = true; session.username = body.username; res.redirect('/rbac-admin'); } else { res.redirect('/rbac-admin/login?error=Invalid credentials'); } } catch (error) { res.redirect('/rbac-admin/login?error=Session setup required'); } }); } /** * Handle admin logout */ logout(session, res) { session.destroy((err) => { if (err) { console.error('Session destruction error:', err); } res.redirect('/rbac-admin/login'); }); } /** * Dashboard home page with statistics */ getDashboard(res) { return __awaiter(this, void 0, void 0, function* () { try { const stats = yield this.adminService.getDashboardStats(); res.send((0, dashboard_1.getDashboardView)(stats)); } catch (error) { const fallbackStats = { users: 0, roles: 0, features: 0, permissions: 5 }; res.send((0, dashboard_1.getDashboardView)(fallbackStats)); } }); } /** * API endpoint for real-time dashboard statistics */ getStats() { return __awaiter(this, void 0, void 0, function* () { try { const stats = yield this.adminService.getDashboardStats(); return Object.assign(Object.assign({}, stats), { timestamp: new Date().toISOString() }); } catch (error) { throw new common_1.InternalServerErrorException({ error: 'Failed to fetch stats', message: error.message }); } }); } // ===================================== // USER MANAGEMENT ROUTES // ===================================== /** * Display users list with pagination and search */ getUsers() { return __awaiter(this, arguments, void 0, function* (page = '1', limit = '10', search = '', res) { try { const pageNum = parseInt(page) || 1; const limitNum = parseInt(limit) || 10; const skip = (pageNum - 1) * limitNum; const usersResult = yield this.adminService.getAllUsers(limitNum, skip, search); const rolesResult = yield this.adminService.getAllRoles(); const pagination = { currentPage: pageNum, totalPages: Math.ceil(usersResult.total / limitNum), totalUsers: usersResult.total, hasNext: pageNum < Math.ceil(usersResult.total / limitNum), hasPrev: pageNum > 1, limit: limitNum, search }; res.send((0, users_1.getUsersListView)(usersResult.items, rolesResult.items, pagination)); } catch (error) { throw new common_1.InternalServerErrorException('Error loading users: ' + error.message); } }); } /** * Display specific user details */ getUserDetails(userId, res) { return __awaiter(this, void 0, void 0, function* () { try { const user = yield this.adminService.findUserByUserIdWithRole(userId); if (!user) { throw new common_1.NotFoundException('User not found'); } const rolesResult = yield this.adminService.getAllRoles(); res.send((0, users_1.getUserDetailsView)(user, rolesResult.items)); } catch (error) { if (error instanceof common_1.NotFoundException) { throw error; } throw new common_1.InternalServerErrorException('Error loading user: ' + error.message); } }); } /** * Create a new user */ createUser(body, res) { return __awaiter(this, void 0, void 0, function* () { try { const { user_id, name, email } = body; const existingUser = yield this.adminService.findUserByUserId(user_id); if (existingUser) { throw new common_1.BadRequestException('User already exists'); } yield this.adminService.createUser({ user_id, name, email }); res.redirect('/rbac-admin/users'); } catch (error) { if (error instanceof common_1.BadRequestException) { throw error; } throw new common_1.InternalServerErrorException(error.message); } }); } /** * Update user information */ updateUser(userId, body, res) { return __awaiter(this, void 0, void 0, function* () { try { const { name, email } = body; yield this.adminService.updateUser(userId, { name, email }); res.redirect(`/rbac-admin/users/${userId}`); } catch (error) { throw new common_1.InternalServerErrorException(error.message); } }); } /** * Assign role to user */ assignRole(userId, body, req, res) { return __awaiter(this, void 0, void 0, function* () { try { const { roleName } = body; const user = yield this.adminService.findUserByUserId(userId); if (!user) { throw new common_1.NotFoundException('User not found'); } if (roleName) { const role = yield this.adminService.findRoleByName(roleName); if (!role) { throw new common_1.NotFoundException('Role not found'); } // Handle both MongoDB (_id) and PostgreSQL (id) const roleId = role._id || role.id; yield this.adminService.updateUser(userId, { role_id: roleId }); } else { throw new common_1.BadRequestException('Role not found'); } const referer = req.get('Referer') || '/rbac-admin/users'; res.redirect(referer); } catch (error) { if (error instanceof common_1.NotFoundException || error instanceof common_1.BadRequestException) { throw error; } throw new common_1.InternalServerErrorException(error.message); } }); } /** * Delete user */ deleteUser(userId) { return __awaiter(this, void 0, void 0, function* () { try { yield this.adminService.deleteUser(userId); return { message: 'User deleted successfully' }; } catch (error) { throw new common_1.InternalServerErrorException(error.message); } }); } // ===================================== // ROLE MANAGEMENT ROUTES // ===================================== /** * Display roles list */ getRoles(res) { return __awaiter(this, void 0, void 0, function* () { try { const rolesResult = yield this.adminService.getAllRoles(); const featuresResult = yield this.adminService.getAllFeatures(); const permissionsResult = yield this.adminService.getAllPermissions(); res.send((0, roles_1.getRolesListView)(rolesResult.items, featuresResult.items, permissionsResult.items)); } catch (error) { throw new common_1.InternalServerErrorException('Error loading roles: ' + error.message); } }); } /** * Display specific role details */ getRoleDetails(roleId, res) { return __awaiter(this, void 0, void 0, function* () { try { const role = yield this.adminService.findRoleByIdWithFeatures(roleId); if (!role) { throw new common_1.NotFoundException('Role not found'); } const featuresResult = yield this.adminService.getAllFeatures(); const permissionsResult = yield this.adminService.getAllPermissions(); res.send((0, roles_1.getRoleDetailsView)(role, featuresResult.items, permissionsResult.items)); } catch (error) { if (error instanceof common_1.NotFoundException) { throw error; } throw new common_1.InternalServerErrorException('Error loading role: ' + error.message); } }); } /** * Create a new role */ createRole(body, res) { return __awaiter(this, void 0, void 0, function* () { try { const { name, description, features } = body; const existingRole = yield this.adminService.findRoleByName(name); if (existingRole) { return res.status(400).json({ error: 'Role already exists' }); } const newRole = yield this.adminService.createRole({ name, description }); // If features are provided, assign them to the role if (features && features.length > 0) { const roleId = newRole._id || newRole.id; const featurePermissions = features.map(f => ({ feature_id: f.feature, permission_ids: f.permissions })); yield this.adminService.assignRoleFeaturePermissions(roleId, featurePermissions); } res.json({ success: true, message: 'Role created successfully' }); } catch (error) { res.status(500).json({ error: error.message }); } }); } /** * Delete role */ deleteRole(roleId) { return __awaiter(this, void 0, void 0, function* () { try { yield this.adminService.deleteRole(roleId); return { success: true, message: 'Role deleted successfully' }; } catch (error) { throw new common_1.InternalServerErrorException(error.message); } }); } /** * Assign features and permissions to role */ assignRoleFeatures(roleId, body, res) { return __awaiter(this, void 0, void 0, function* () { try { let featurePermissions = body.featurePermissions; // Handle form data: convert featureIds to featurePermissions with all permissions if (!featurePermissions && body.featureIds) { const featureIds = Array.isArray(body.featureIds) ? body.featureIds : [body.featureIds]; const allPermissions = yield this.adminService.getAllPermissions(); featurePermissions = featureIds.map(featureId => ({ feature_id: featureId, permission_ids: allPermissions.items.map(p => p._id || p.id) })); } if (!featurePermissions || featurePermissions.length === 0) { throw new common_1.BadRequestException('No features or permissions provided'); } yield this.adminService.assignRoleFeaturePermissions(roleId, featurePermissions); res.redirect(`/rbac-admin/roles/${roleId}`); } catch (error) { if (error instanceof common_1.BadRequestException || error instanceof common_1.NotFoundException) { throw error; } throw new common_1.InternalServerErrorException(error.message); } }); } /** * Remove permissions from a specific feature within a role */ removeRolePermissions(roleId, body) { return __awaiter(this, void 0, void 0, function* () { var _a; try { const { featureIds, permissionIds } = body; const featureId = Array.isArray(featureIds) ? featureIds[0] : featureIds; const permissionsToRemove = Array.isArray(permissionIds) ? permissionIds : [permissionIds]; // Get current role features const role = yield this.adminService.findRoleByIdWithFeatures(roleId); if (!role) { throw new common_1.NotFoundException('Role not found'); } // Find the existing feature assignment const existingFeature = (_a = role.features) === null || _a === void 0 ? void 0 : _a.find((f) => { var _a, _b, _c, _d; const fId = ((_a = f.feature_id) === null || _a === void 0 ? void 0 : _a.toString()) || ((_c = (_b = f.feature) === null || _b === void 0 ? void 0 : _b._id) === null || _c === void 0 ? void 0 : _c.toString()) || ((_d = f._id) === null || _d === void 0 ? void 0 : _d.toString()); return fId === featureId; }); if (!existingFeature || !existingFeature.permissions) { throw new common_1.NotFoundException('Feature or permissions not found'); } // Remove specified permissions const existingPermissionIds = Array.isArray(existingFeature.permissions) ? existingFeature.permissions.map((p) => (p._id || p.id || p).toString()) : []; const updatedPermissions = existingPermissionIds.filter((pId) => !permissionsToRemove.includes(pId)); const featurePermissions = [{ feature_id: featureId, permission_ids: updatedPermissions }]; yield this.adminService.assignRoleFeaturePermissions(roleId, featurePermissions); return { success: true, message: 'Permission removed successfully' }; } catch (error) { if (error instanceof common_1.NotFoundException) { throw error; } throw new common_1.InternalServerErrorException(error.message); } }); } /** * Add permissions to a specific feature within a role */ addRolePermissions(roleId, body, res) { return __awaiter(this, void 0, void 0, function* () { var _a; try { const { featureIds, permissionIds } = body; const featureId = Array.isArray(featureIds) ? featureIds[0] : featureIds; const permissions = Array.isArray(permissionIds) ? permissionIds : [permissionIds]; // Get current role features to merge with new permissions const role = yield this.adminService.findRoleByIdWithFeatures(roleId); if (!role) { throw new common_1.NotFoundException('Role not found'); } // Find the existing feature assignment (handle undefined features array) const existingFeature = (_a = role.features) === null || _a === void 0 ? void 0 : _a.find((f) => { var _a, _b, _c, _d; const fId = ((_a = f.feature_id) === null || _a === void 0 ? void 0 : _a.toString()) || ((_c = (_b = f.feature) === null || _b === void 0 ? void 0 : _b._id) === null || _c === void 0 ? void 0 : _c.toString()) || ((_d = f._id) === null || _d === void 0 ? void 0 : _d.toString()); return fId === featureId; }); let updatedPermissions = permissions; if (existingFeature && existingFeature.permissions) { // Merge existing permissions with new ones (handle undefined permissions array) const existingPermissionIds = Array.isArray(existingFeature.permissions) ? existingFeature.permissions.map((p) => (p._id || p.id || p).toString()) : []; updatedPermissions = [...new Set([...existingPermissionIds, ...permissions])]; } const featurePermissions = [{ feature_id: featureId, permission_ids: updatedPermissions }]; yield this.adminService.assignRoleFeaturePermissions(roleId, featurePermissions); res.redirect(`/rbac-admin/roles/${roleId}`); } catch (error) { if (error instanceof common_1.NotFoundException) { throw error; } throw new common_1.InternalServerErrorException(error.message); } }); } // ===================================== // FEATURE MANAGEMENT ROUTES // ===================================== /** * Display features list */ getFeatures(res) { return __awaiter(this, void 0, void 0, function* () { try { const featuresResult = yield this.adminService.getAllFeatures(); res.send((0, features_1.getFeaturesListView)(featuresResult.items)); } catch (error) { throw new common_1.InternalServerErrorException('Error loading features: ' + error.message); } }); } /** * Display specific feature details */ getFeatureDetails(featureId, res) { return __awaiter(this, void 0, void 0, function* () { try { const feature = yield this.adminService.findFeatureById(featureId); if (!feature) { throw new common_1.NotFoundException('Feature not found'); } const rolesResult = yield this.adminService.getAllRoles(); res.send((0, features_1.getFeatureDetailsView)(feature, rolesResult.items)); } catch (error) { if (error instanceof common_1.NotFoundException) { throw error; } throw new common_1.InternalServerErrorException('Error loading feature: ' + error.message); } }); } /** * Create a new feature */ createFeature(body, res) { return __awaiter(this, void 0, void 0, function* () { try { const { name, description } = body; const existing = yield this.adminService.findFeatureByName(name); if (existing) { throw new common_1.BadRequestException('Feature already exists'); } yield this.adminService.createFeature({ name, description }); res.redirect('/rbac-admin/features'); } catch (error) { if (error instanceof common_1.BadRequestException) { throw error; } throw new common_1.InternalServerErrorException(error.message); } }); } /** * Update feature information */ updateFeature(featureId, body) { return __awaiter(this, void 0, void 0, function* () { try { const { name, description } = body; yield this.adminService.updateFeature(featureId, { name, description }); return { success: true, message: 'Feature updated successfully' }; } catch (error) { throw new common_1.InternalServerErrorException(error.message); } }); } /** * Delete feature */ deleteFeature(featureId) { return __awaiter(this, void 0, void 0, function* () { try { yield this.adminService.deleteFeature(featureId); return { success: true, message: 'Feature deleted successfully' }; } catch (error) { throw new common_1.InternalServerErrorException(error.message); } }); } // ===================================== // PERMISSION MANAGEMENT ROUTES // ===================================== /** * Display permissions list */ getPermissions(res) { return __awaiter(this, void 0, void 0, function* () { try { const permissionsResult = yield this.adminService.getAllPermissions(); res.send((0, permissions_1.getPermissionsListView)(permissionsResult.items)); } catch (error) { throw new common_1.InternalServerErrorException('Error loading permissions: ' + error.message); } }); } /** * Display specific permission details */ getPermissionDetails(permissionId, res) { return __awaiter(this, void 0, void 0, function* () { try { const permission = yield this.adminService.findPermissionById(permissionId); if (!permission) { throw new common_1.NotFoundException('Permission not found'); } const rolesResult = yield this.adminService.getAllRoles(); res.send((0, permissions_1.getPermissionDetailsView)(permission, rolesResult.items)); } catch (error) { if (error instanceof common_1.NotFoundException) { throw error; } throw new common_1.InternalServerErrorException('Error loading permission: ' + error.message); } }); } /** * Create a new permission */ createPermission(body, res) { return __awaiter(this, void 0, void 0, function* () { try { const { name, description } = body; const existingPermission = yield this.adminService.findPermissionByName(name); if (existingPermission) { throw new common_1.BadRequestException('Permission already exists'); } yield this.adminService.createPermission({ name, description }); res.redirect('/rbac-admin/permissions'); } catch (error) { if (error instanceof common_1.BadRequestException) { throw error; } throw new common_1.InternalServerErrorException(error.message); } }); } /** * Create standard permissions (read, create, update, delete, sudo) */ createStandardPermissions(body) { return __awaiter(this, void 0, void 0, function* () { try { const { permissions } = body; const createdPermissions = []; for (const perm of permissions) { const existingPermission = yield this.adminService.findPermissionByName(perm.name); if (!existingPermission) { const created = yield this.adminService.createPermission(perm); createdPermissions.push(created); } } return { message: `Created ${createdPermissions.length} standard permissions`, permissions: createdPermissions }; } catch (error) { throw new common_1.InternalServerErrorException(error.message); } }); } /** * Update permission information */ updatePermission(permissionId, body) { return __awaiter(this, void 0, void 0, function* () { try { const { name, description } = body; yield this.adminService.updatePermission(permissionId, { name, description }); return { message: 'Permission updated successfully' }; } catch (error) { throw new common_1.InternalServerErrorException(error.message); } }); } /** * Delete permission */ deletePermission(permissionId) { return __awaiter(this, void 0, void 0, function* () { try { yield this.adminService.deletePermission(permissionId); return { message: 'Permission deleted successfully' }; } catch (error) { throw new common_1.InternalServerErrorException(error.message); } }); } }; exports.RbacAdminController = RbacAdminController; __decorate([ (0, common_1.Get)('login'), __param(0, (0, common_1.Res)()), __param(1, (0, common_1.Query)('error')), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, String]), __metadata("design:returntype", void 0) ], RbacAdminController.prototype, "getLogin", null); __decorate([ (0, common_1.Post)('login'), __param(0, (0, common_1.Body)()), __param(1, (0, common_1.Session)()), __param(2, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "postLogin", null); __decorate([ (0, common_1.Post)('logout'), __param(0, (0, common_1.Session)()), __param(1, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", void 0) ], RbacAdminController.prototype, "logout", null); __decorate([ (0, common_1.Get)(), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "getDashboard", null); __decorate([ (0, common_1.Get)('api/stats'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "getStats", null); __decorate([ (0, common_1.Get)('users'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Query)('page')), __param(1, (0, common_1.Query)('limit')), __param(2, (0, common_1.Query)('search')), __param(3, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String, String, Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "getUsers", null); __decorate([ (0, common_1.Get)('users/:userId'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Param)('userId')), __param(1, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "getUserDetails", null); __decorate([ (0, common_1.Post)('users/create'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Body)()), __param(1, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "createUser", null); __decorate([ (0, common_1.Post)('users/:userId/update'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Param)('userId')), __param(1, (0, common_1.Body)()), __param(2, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object, Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "updateUser", null); __decorate([ (0, common_1.Post)('users/:userId/assign-role'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Param)('userId')), __param(1, (0, common_1.Body)()), __param(2, (0, common_1.Req)()), __param(3, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object, Object, Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "assignRole", null); __decorate([ (0, common_1.Post)('users/:userId/delete'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Param)('userId')), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "deleteUser", null); __decorate([ (0, common_1.Get)('roles'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "getRoles", null); __decorate([ (0, common_1.Get)('roles/:roleId'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Param)('roleId')), __param(1, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "getRoleDetails", null); __decorate([ (0, common_1.Post)('roles/create'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Body)()), __param(1, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "createRole", null); __decorate([ (0, common_1.Post)('roles/:roleId/delete'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Param)('roleId')), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "deleteRole", null); __decorate([ (0, common_1.Post)('roles/:roleId/assign-features'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Param)('roleId')), __param(1, (0, common_1.Body)()), __param(2, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object, Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "assignRoleFeatures", null); __decorate([ (0, common_1.Post)('roles/:roleId/remove-permissions'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Param)('roleId')), __param(1, (0, common_1.Body)()), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "removeRolePermissions", null); __decorate([ (0, common_1.Post)('roles/:roleId/add-permissions'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Param)('roleId')), __param(1, (0, common_1.Body)()), __param(2, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object, Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "addRolePermissions", null); __decorate([ (0, common_1.Get)('features'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "getFeatures", null); __decorate([ (0, common_1.Get)('features/:featureId'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Param)('featureId')), __param(1, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "getFeatureDetails", null); __decorate([ (0, common_1.Post)('features/create'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Body)()), __param(1, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "createFeature", null); __decorate([ (0, common_1.Post)('features/:featureId/update'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Param)('featureId')), __param(1, (0, common_1.Body)()), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "updateFeature", null); __decorate([ (0, common_1.Post)('features/:featureId/delete'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Param)('featureId')), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "deleteFeature", null); __decorate([ (0, common_1.Get)('permissions'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "getPermissions", null); __decorate([ (0, common_1.Get)('permissions/:permissionId'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Param)('permissionId')), __param(1, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "getPermissionDetails", null); __decorate([ (0, common_1.Post)('permissions/create'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Body)()), __param(1, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "createPermission", null); __decorate([ (0, common_1.Post)('permissions/create-standard'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Body)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "createStandardPermissions", null); __decorate([ (0, common_1.Post)('permissions/:permissionId/update'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Param)('permissionId')), __param(1, (0, common_1.Body)()), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "updatePermission", null); __decorate([ (0, common_1.Post)('permissions/:permissionId/delete'), (0, common_1.UseGuards)(admin_auth_guard_1.AdminAuthGuard), __param(0, (0, common_1.Param)('permissionId')), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], RbacAdminController.prototype, "deletePermission", null); exports.RbacAdminController = RbacAdminController = __decorate([ (0, common_1.Controller)('rbac-admin'), __metadata("design:paramtypes", [admin_service_1.RbacAdminService]) ], RbacAdminController);