后端: - 新增 GET /user/permissions 端点返回当前用户权限码 - Login 响应附带 permissions 数组 - collectUserPermissionCodes 用 raw SQL JOIN 避免 GORM many2many 表名问题 - admin 用户返回 ['*'] 通配符 前端: - usePermission hook (hasPermission/hasAnyPermission/hasAllPermissions) - <HasPermission> 组件 (permission/anyOf/allOf + fallback) - zustand store 新增 permissions 字段 - Sidebar 菜单递归过滤 (42 菜单项全部标注 permission) - ServerManager: 添加/导入/批量删除按钮按权限显隐 - ServerTableRow: 终端/编辑/文件/删除按权限显隐 - SystemUserTab: 新建/导入/编辑/删除按钮按权限显隐 - MainLayout: 页面刷新自动拉取权限 - Login: 登录时存储 permissions 验证: - admin: permissions=['*'] 通配符 - viewer: 7 个只读权限 (dashboard:view/server:view/...) - viewer 无 server:create/delete - 10/10 回归测试通过 - npm run build 零错误
109 lines
4.1 KiB
Go
109 lines
4.1 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
)
|
|
|
|
// ApprovalTemplate 审批模板模型
|
|
type ApprovalTemplate struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
Name string `gorm:"size:128;not null" json:"name"`
|
|
Code string `gorm:"size:64;uniqueIndex;not null" json:"code"`
|
|
Description string `gorm:"size:500" json:"description"`
|
|
Type string `gorm:"size:32;not null" json:"type"` // release, server_apply, app_deploy, permission_request
|
|
FormSchema string `gorm:"type:text" json:"form_schema"` // JSON form fields config
|
|
FlowConfig string `gorm:"type:text" json:"flow_config"` // JSON approval flow steps
|
|
Category string `gorm:"size:32;default:resource" json:"category"` // resource, app, permission
|
|
Enabled bool `gorm:"default:true" json:"enabled"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (ApprovalTemplate) TableName() string {
|
|
return "sys_approval_templates"
|
|
}
|
|
|
|
// ApprovalProcess 审批流程模型
|
|
type ApprovalProcess struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
TemplateID uint `json:"template_id"`
|
|
Title string `gorm:"size:255;not null" json:"title"`
|
|
Applicant uint `json:"applicant"`
|
|
Status string `gorm:"size:32;default:pending" json:"status"` // pending, approved, rejected
|
|
FormData string `gorm:"type:text" json:"form_data"` // JSON
|
|
CurrentStep int `gorm:"default:0" json:"current_step"`
|
|
TotalSteps int `json:"total_steps"`
|
|
ApprovedAt *time.Time `json:"approved_at"`
|
|
RejectedAt *time.Time `json:"rejected_at"`
|
|
RejectReason string `gorm:"size:500" json:"reject_reason"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
|
|
// 关联
|
|
Template *ApprovalTemplate `gorm:"foreignKey:TemplateID" json:"template,omitempty"`
|
|
ApplicantUser *User `gorm:"foreignKey:Applicant" json:"applicant_user,omitempty"`
|
|
Steps []ApprovalStep `gorm:"foreignKey:ProcessID" json:"steps,omitempty"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (ApprovalProcess) TableName() string {
|
|
return "approval_processes"
|
|
}
|
|
|
|
// ApprovalStep 审批步骤模型
|
|
type ApprovalStep struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
ProcessID uint `json:"process_id"`
|
|
Step int `json:"step"`
|
|
StepType string `gorm:"size:32;default:audit" json:"step_type"` // audit, execute
|
|
Approver uint `json:"approver"`
|
|
Status string `gorm:"size:32;default:pending" json:"status"` // pending, approved, rejected
|
|
Comment string `gorm:"size:500" json:"comment"`
|
|
ApprovedAt *time.Time `json:"approved_at"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
|
|
// 关联
|
|
ApproverUser *User `gorm:"foreignKey:Approver" json:"approver_user,omitempty"`
|
|
}
|
|
|
|
// TableName 表名
|
|
func (ApprovalStep) TableName() string {
|
|
return "approval_steps"
|
|
}
|
|
|
|
// CreateApprovalTemplateRequest 创建审批模板请求
|
|
type CreateApprovalTemplateRequest struct {
|
|
Name string `json:"name" binding:"required"`
|
|
Code string `json:"code" binding:"required"`
|
|
Description string `json:"description"`
|
|
Type string `json:"type" binding:"required,oneof=server_apply app_deploy permission_request"`
|
|
Category string `json:"category"` // resource, app, permission
|
|
FormSchema string `json:"form_schema"`
|
|
FlowConfig string `json:"flow_config"`
|
|
}
|
|
|
|
// CreateApprovalProcessRequest 创建审批流程请求
|
|
type CreateApprovalProcessRequest struct {
|
|
TemplateID uint `json:"template_id" binding:"required"`
|
|
Title string `json:"title" binding:"required"`
|
|
FormData string `json:"form_data"`
|
|
}
|
|
|
|
// ApproveRequest 审批请求
|
|
type ApproveRequest struct {
|
|
Status string `json:"status"`
|
|
Comment string `json:"comment"`
|
|
}
|
|
|
|
// ApprovalStats 审批统计
|
|
type ApprovalStats struct {
|
|
Pending int64 `json:"pending"`
|
|
Approved int64 `json:"approved"`
|
|
Rejected int64 `json:"rejected"`
|
|
Total int64 `json:"total"`
|
|
MyPending int64 `json:"my_pending"`
|
|
}
|