feat: 发布权限 RBAC + PipelineEditor 修复 + 菜单优化
- 新增 DeployRBAC 页面: Jenkins-style Item Role 权限管理 - 正则匹配流水线 code,实时命中预览 - 内置用户分配面板,无需跳转系统管理 - 支持创建/编辑/删除/启用禁用 Item Role - 修复 PipelineEditor 成员管理 http 双解包 bug - 修复 PipelineManager 前端 code 路由迁移(delete/trigger/stop/loadRuns) - 新增批量删除流水线运行记录 API - Sidebar: 应用发布下新增「发布权限」, 仓库认证→发布配置, 移除用户组 - 恢复系统管理菜单(不受发布权限改动影响) - 后端 ItemRole CRUD handler + 正则匹配中间件已就绪
This commit is contained in:
1 parent
0fea0ccc20
commit
24f955832e
40 files changed
+7530
-1032
No files matched your search
@@ -0,0 +1,193 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// ============================================
|
||||
// PipelineRepo Git 仓库认证配置
|
||||
// ============================================
|
||||
|
||||
// RepoAuthType 仓库认证方式
|
||||
type RepoAuthType string
|
||||
|
||||
const (
|
||||
RepoAuthToken RepoAuthType = "token" // Personal Access Token
|
||||
RepoAuthSSH RepoAuthType = "ssh" // SSH Key
|
||||
RepoAuthPassword RepoAuthType = "password" // 用户名+密码
|
||||
)
|
||||
|
||||
// PipelineRepo Git 仓库认证配置表
|
||||
type PipelineRepo struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;comment:配置名称" json:"name"`
|
||||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||||
URL string `gorm:"type:varchar(512);not null;comment:仓库 URL" json:"url"`
|
||||
AuthType RepoAuthType `gorm:"type:varchar(16);default:'token';comment:认证方式: token/ssh/password" json:"auth_type"`
|
||||
CredentialID *uint `gorm:"index;comment:凭据ID(关联 iam_credentials)" json:"credential_id,omitempty"`
|
||||
Enabled bool `gorm:"default:true;comment:是否启用" json:"enabled"`
|
||||
CreatedBy string `gorm:"type:varchar(64);comment:创建人" json:"created_by,omitempty"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (PipelineRepo) TableName() string {
|
||||
return "deploy_pipeline_repos"
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// PipelineRegistry 镜像仓库认证配置
|
||||
// ============================================
|
||||
|
||||
// RegistryAuthType 镜像仓库认证方式
|
||||
type RegistryAuthType string
|
||||
|
||||
const (
|
||||
RegistryAuthToken RegistryAuthType = "token" // Access Token
|
||||
RegistryAuthPassword RegistryAuthType = "password" // 用户名+密码
|
||||
)
|
||||
|
||||
// PipelineRegistry 镜像仓库认证配置表
|
||||
type PipelineRegistry struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(128);not null;comment:配置名称" json:"name"`
|
||||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||||
RegistryURL string `gorm:"type:varchar(512);not null;comment:镜像仓库地址" json:"registry_url"`
|
||||
Namespace string `gorm:"type:varchar(128);comment:默认命名空间" json:"namespace,omitempty"`
|
||||
AuthType RegistryAuthType `gorm:"type:varchar(16);default:'password';comment:认证方式: token/password" json:"auth_type"`
|
||||
CredentialID *uint `gorm:"index;comment:凭据ID(关联 iam_credentials)" json:"credential_id,omitempty"`
|
||||
Enabled bool `gorm:"default:true;comment:是否启用" json:"enabled"`
|
||||
CreatedBy string `gorm:"type:varchar(64);comment:创建人" json:"created_by,omitempty"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (PipelineRegistry) TableName() string {
|
||||
return "deploy_pipeline_registries"
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// PipelineStage 流水线阶段定义(JSON)
|
||||
// ============================================
|
||||
|
||||
// PipelineStage 一个阶段包含多个任务
|
||||
type PipelineStage struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"` // source/build/deploy/test/custom
|
||||
Tasks []PipelineTask `json:"tasks"`
|
||||
}
|
||||
|
||||
// PipelineTask 阶段内的任务
|
||||
type PipelineTask struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"` // build/deploy/test/custom
|
||||
Icon string `json:"icon,omitempty"`
|
||||
Config map[string]string `json:"config,omitempty"`
|
||||
Script string `json:"script,omitempty"`
|
||||
ScriptType string `json:"script_type,omitempty"` // shell/python
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// DeployEnvironment 发布环境分组
|
||||
// ============================================
|
||||
|
||||
type EnvironmentType string
|
||||
|
||||
const (
|
||||
EnvProduction EnvironmentType = "production"
|
||||
EnvStaging EnvironmentType = "staging"
|
||||
EnvTesting EnvironmentType = "testing"
|
||||
EnvDev EnvironmentType = "development"
|
||||
)
|
||||
|
||||
// DeployEnvironment 环境分组表(生产/测试/预发布/开发)
|
||||
type DeployEnvironment struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(64);not null;uniqueIndex;comment:环境名称" json:"name"`
|
||||
DisplayName string `gorm:"type:varchar(128);not null;comment:显示名称" json:"display_name"`
|
||||
Type EnvironmentType `gorm:"type:varchar(16);not null;index;comment:环境类型: production/staging/testing/development" json:"type"`
|
||||
Color string `gorm:"type:varchar(16);default:'#3B82F6';comment:标识颜色" json:"color"`
|
||||
SortOrder int `gorm:"default:0;comment:排序" json:"sort_order"`
|
||||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||||
Enabled bool `gorm:"default:true;comment:是否启用" json:"enabled"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
}
|
||||
|
||||
func (DeployEnvironment) TableName() string {
|
||||
return "deploy_environments"
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// DeployPipelineMember 流水线成员
|
||||
// ============================================
|
||||
|
||||
type MemberRole string
|
||||
|
||||
const (
|
||||
MemberOwner MemberRole = "owner" // 拥有者
|
||||
MemberEditor MemberRole = "editor" // 编辑者
|
||||
MemberViewer MemberRole = "viewer" // 查看者
|
||||
)
|
||||
|
||||
// DeployPipelineMember 流水线成员表
|
||||
// 支持两种授权方式:直接用户授权(username 非空)和用户组授权(group_id 非空)
|
||||
type DeployPipelineMember struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
PipelineID uint `gorm:"index:idx_pipeline_user,unique,priority:1;index:idx_pipeline_group,unique,priority:1;not null;comment:流水线ID" json:"pipeline_id"`
|
||||
Username *string `gorm:"type:varchar(64);index:idx_pipeline_user,unique,priority:2;comment:用户名(直接授权)" json:"username,omitempty"`
|
||||
GroupID *uint `gorm:"index:idx_pipeline_group,unique,priority:2;comment:用户组ID(组授权)" json:"group_id,omitempty"`
|
||||
Role MemberRole `gorm:"type:varchar(16);default:'editor';comment:角色: owner/editor/viewer" json:"role"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
Pipeline *Pipeline `json:"pipeline,omitempty" gorm:"foreignKey:PipelineID"`
|
||||
Group *DeployUserGroup `json:"group,omitempty" gorm:"foreignKey:GroupID"`
|
||||
}
|
||||
|
||||
func (DeployPipelineMember) TableName() string {
|
||||
return "deploy_pipeline_members"
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// DeployUserGroup 发布系统用户组
|
||||
// ============================================
|
||||
|
||||
// DeployUserGroup 用户组(用于流水线权限分组授权)
|
||||
type DeployUserGroup struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
Name string `gorm:"type:varchar(64);uniqueIndex;not null;comment:组名称" json:"name"`
|
||||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||||
CreatedBy string `gorm:"type:varchar(64);comment:创建人" json:"created_by,omitempty"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
Members []DeployUserGroupMember `json:"members,omitempty" gorm:"foreignKey:GroupID"`
|
||||
}
|
||||
|
||||
func (DeployUserGroup) TableName() string {
|
||||
return "deploy_user_groups"
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// DeployUserGroupMember 用户组成员
|
||||
// ============================================
|
||||
|
||||
// DeployUserGroupMember 用户组成员关联表
|
||||
type DeployUserGroupMember struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||||
GroupID uint `gorm:"uniqueIndex:idx_group_user;not null;comment:组ID" json:"group_id"`
|
||||
Username string `gorm:"type:varchar(64);uniqueIndex:idx_group_user;not null;comment:用户名" json:"username"`
|
||||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||||
|
||||
// 关联
|
||||
Group *DeployUserGroup `json:"group,omitempty" gorm:"foreignKey:GroupID"`
|
||||
}
|
||||
|
||||
func (DeployUserGroupMember) TableName() string {
|
||||
return "deploy_user_group_members"
|
||||
}
|
||||
Reference in new issue
Block a user