feat: 实现角色定义系统
- 创建角色定义基类 RoleDefinition - 实现管理员角色 AdminRole - 实现普通用户角色 UserRole - 实现测试用户角色 TestRole - 实现角色工厂 RoleFactory - 添加完整的单元测试 - 更新 vitest 配置以包含角色定义测试 所有角色统一使用密码: Test@123
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import type { RoleDefinition } from './base.role';
|
||||
import { AdminRole } from './admin.role';
|
||||
import { UserRole } from './user.role';
|
||||
import { TestRole } from './test.role';
|
||||
|
||||
export class RoleFactory {
|
||||
private static roles: Map<string, RoleDefinition> = new Map([
|
||||
['admin', AdminRole],
|
||||
['user', UserRole],
|
||||
['test', TestRole]
|
||||
]);
|
||||
|
||||
static getRole(roleName: string): RoleDefinition {
|
||||
const role = this.roles.get(roleName);
|
||||
if (!role) {
|
||||
throw new Error(`Role '${roleName}' not found`);
|
||||
}
|
||||
return role;
|
||||
}
|
||||
|
||||
static getAllRoles(): RoleDefinition[] {
|
||||
return Array.from(this.roles.values());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user