chore: initial commit of ai site platform
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
93
platform/internal/authx/roles.go
Normal file
93
platform/internal/authx/roles.go
Normal file
@@ -0,0 +1,93 @@
|
||||
package authx
|
||||
|
||||
// 平台账号角色(JWT role)——统一中文命名。
|
||||
const (
|
||||
Role超级管理员 = "超级管理员" // 平台级:可管理所有公司
|
||||
Role管理员 = "管理员" // 公司顶级
|
||||
Role编辑 = "编辑"
|
||||
Role只读 = "只读"
|
||||
Role待加入 = "待加入"
|
||||
Role智能体 = "智能体"
|
||||
)
|
||||
|
||||
// RoleAgent 智能体 JWT 角色(与 Role智能体 相同)。
|
||||
const RoleAgent = Role智能体
|
||||
|
||||
// 智能体租户角色编码(roles 表 code)——统一中文。
|
||||
const (
|
||||
AgentRole生成发布 = "生成发布"
|
||||
AgentRole只读 = "只读"
|
||||
AgentRole读写 = "读写"
|
||||
AgentRole运维 = "运维"
|
||||
)
|
||||
|
||||
// NormalizeRole 将平台角色统一为中文(兼容英文旧码)。
|
||||
func NormalizeRole(role string) string {
|
||||
switch role {
|
||||
case "platform_admin", "super_admin", Role超级管理员:
|
||||
return Role超级管理员
|
||||
case "owner", Role管理员:
|
||||
return Role管理员
|
||||
case "editor", Role编辑:
|
||||
return Role编辑
|
||||
case "viewer", Role只读:
|
||||
return Role只读
|
||||
case "pending", Role待加入:
|
||||
return Role待加入
|
||||
case "agent", Role智能体:
|
||||
return Role智能体
|
||||
default:
|
||||
return role
|
||||
}
|
||||
}
|
||||
|
||||
// NormalizeAgentRoleCode 智能体角色编码 → 中文(兼容英文旧码)。
|
||||
func NormalizeAgentRoleCode(code string) string {
|
||||
switch code {
|
||||
case "publisher", AgentRole生成发布:
|
||||
return AgentRole生成发布
|
||||
case "viewer", AgentRole只读:
|
||||
return AgentRole只读
|
||||
case "editor", AgentRole读写:
|
||||
return AgentRole读写
|
||||
case "operator", AgentRole运维:
|
||||
return AgentRole运维
|
||||
default:
|
||||
return code
|
||||
}
|
||||
}
|
||||
|
||||
// IsPlatformAdmin 是否平台超级管理员(可跨公司)。
|
||||
func IsPlatformAdmin(role string) bool {
|
||||
return NormalizeRole(role) == Role超级管理员
|
||||
}
|
||||
|
||||
// IsOwner 是否公司顶级管理员(不含超级管理员)。
|
||||
func IsOwner(role string) bool {
|
||||
return NormalizeRole(role) == Role管理员
|
||||
}
|
||||
|
||||
// IsCompanyAdmin 公司内顶级管理员(超级管理员不介入公司内部)。
|
||||
func IsCompanyAdmin(role string) bool {
|
||||
return NormalizeRole(role) == Role管理员
|
||||
}
|
||||
|
||||
// IsAgent 是否智能体账号。
|
||||
func IsAgent(role string) bool {
|
||||
return NormalizeRole(role) == Role智能体
|
||||
}
|
||||
|
||||
// RoleLabel 平台角色 → 中文显示(已是中文则原样)。
|
||||
func RoleLabel(role string) string {
|
||||
return NormalizeRole(role)
|
||||
}
|
||||
|
||||
// ValidPlatformRole 是否可赋予人类成员的角色(不含待加入/智能体/超级管理员)。
|
||||
func ValidPlatformRole(role string) bool {
|
||||
switch NormalizeRole(role) {
|
||||
case Role管理员, Role编辑, Role只读:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user