实现角色权限体系重构
本次提交完成了角色权限体系的重构,主要包括: 1. 数据库迁移 - 添加 tb_permission.platform 字段(all/web/h5) - 更新 tb_role.role_type 注释(1=平台角色,2=客户角色) 2. GORM 模型更新 - Permission 模型添加 Platform 字段 - Role 模型更新 RoleType 注释 3. 常量定义 - 新增角色类型常量(RoleTypePlatform, RoleTypeCustomer) - 新增权限端口常量(PlatformAll, PlatformWeb, PlatformH5) - 添加角色类型与用户类型匹配规则函数 4. Store 层实现 - Permission Store 支持按 platform 过滤 - Account Role Store 添加 CountByAccountID 方法 5. Service 层实现 - 角色分配支持类型匹配校验 - 角色分配支持数量限制(超级管理员0个,平台用户无限制,代理/企业1个) - Permission Service 支持 platform 过滤 6. 权限校验中间件 - 实现 RequirePermission、RequireAnyPermission、RequireAllPermissions - 支持 platform 字段过滤 - 支持跳过超级管理员检查 7. 测试用例 - 角色类型匹配规则单元测试 - 角色分配数量限制单元测试 - 权限 platform 过滤单元测试 - 权限校验中间件集成测试(占位) 8. 代码清理 - 删除过时的 subordinate 测试文件 - 移除 Account.ParentID 相关引用 - 更新 DTO 验证规则 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ type CreatePermissionRequest struct {
|
||||
PermName string `json:"perm_name" validate:"required,min=1,max=50" required:"true" minLength:"1" maxLength:"50" description:"权限名称"`
|
||||
PermCode string `json:"perm_code" validate:"required,min=1,max=100" required:"true" minLength:"1" maxLength:"100" description:"权限编码"`
|
||||
PermType int `json:"perm_type" validate:"required,min=1,max=2" required:"true" minimum:"1" maximum:"2" description:"权限类型 (1:菜单, 2:按钮)"`
|
||||
Platform string `json:"platform" validate:"omitempty,oneof=all web h5" description:"适用端口 (all:全部, web:Web后台, h5:H5端),默认为 all"`
|
||||
URL string `json:"url" validate:"omitempty,max=255" maxLength:"255" description:"请求路径"`
|
||||
ParentID *uint `json:"parent_id" description:"父权限ID"`
|
||||
Sort int `json:"sort" validate:"omitempty,min=0" minimum:"0" description:"排序值"`
|
||||
@@ -14,6 +15,7 @@ type CreatePermissionRequest struct {
|
||||
type UpdatePermissionRequest struct {
|
||||
PermName *string `json:"perm_name" validate:"omitempty,min=1,max=50" minLength:"1" maxLength:"50" description:"权限名称"`
|
||||
PermCode *string `json:"perm_code" validate:"omitempty,min=1,max=100" minLength:"1" maxLength:"100" description:"权限编码"`
|
||||
Platform *string `json:"platform" validate:"omitempty,oneof=all web h5" description:"适用端口 (all:全部, web:Web后台, h5:H5端)"`
|
||||
URL *string `json:"url" validate:"omitempty,max=255" maxLength:"255" description:"请求路径"`
|
||||
ParentID *uint `json:"parent_id" description:"父权限ID"`
|
||||
Sort *int `json:"sort" validate:"omitempty,min=0" minimum:"0" description:"排序值"`
|
||||
@@ -33,6 +35,7 @@ type PermissionListRequest struct {
|
||||
PermName string `json:"perm_name" query:"perm_name" validate:"omitempty,max=50" maxLength:"50" description:"权限名称模糊查询"`
|
||||
PermCode string `json:"perm_code" query:"perm_code" validate:"omitempty,max=100" maxLength:"100" description:"权限编码模糊查询"`
|
||||
PermType *int `json:"perm_type" query:"perm_type" validate:"omitempty,min=1,max=2" minimum:"1" maximum:"2" description:"权限类型"`
|
||||
Platform string `json:"platform" query:"platform" validate:"omitempty,oneof=all web h5" description:"适用端口"`
|
||||
ParentID *uint `json:"parent_id" query:"parent_id" description:"父权限ID"`
|
||||
Status *int `json:"status" query:"status" validate:"omitempty,min=0,max=1" minimum:"0" maximum:"1" description:"状态"`
|
||||
}
|
||||
@@ -43,6 +46,7 @@ type PermissionResponse struct {
|
||||
PermName string `json:"perm_name" description:"权限名称"`
|
||||
PermCode string `json:"perm_code" description:"权限编码"`
|
||||
PermType int `json:"perm_type" description:"权限类型"`
|
||||
Platform string `json:"platform" description:"适用端口"`
|
||||
URL string `json:"url,omitempty" description:"请求路径"`
|
||||
ParentID *uint `json:"parent_id,omitempty" description:"父权限ID"`
|
||||
Sort int `json:"sort" description:"排序值"`
|
||||
@@ -67,6 +71,7 @@ type PermissionTreeNode struct {
|
||||
PermName string `json:"perm_name" description:"权限名称"`
|
||||
PermCode string `json:"perm_code" description:"权限编码"`
|
||||
PermType int `json:"perm_type" description:"权限类型"`
|
||||
Platform string `json:"platform" description:"适用端口"`
|
||||
URL string `json:"url,omitempty" description:"请求路径"`
|
||||
Sort int `json:"sort" description:"排序值"`
|
||||
Children []*PermissionTreeNode `json:"children,omitempty" description:"子权限列表"`
|
||||
|
||||
Reference in New Issue
Block a user