feat(auth): 完成租户用户角色资源核心模块

This commit is contained in:
OpenClaw
2026-03-01 10:58:53 +08:00
parent fc7138786b
commit 1de4524b5e
12 changed files with 1619 additions and 51 deletions

View File

@@ -0,0 +1,38 @@
package models
import (
"time"
)
// Role 角色模型(基于租户)
type Role struct {
ID uint `gorm:"primaryKey" json:"id"`
TenantID uint `gorm:"not null;index:idx_tenant_role" json:"tenant_id"`
Name string `gorm:"size:50;not null;uniqueIndex:idx_tenant_role_name" json:"name"` // admin, manager, agent, viewer 等
DisplayName string `gorm:"size:100" json:"display_name"` // 显示名称
Description string `gorm:"type:text" json:"description"`
// 权限配置
Code string `gorm:"size:50;uniqueIndex" json:"code"` // 角色代码
Level int `gorm:"default:1" json:"level"` // 权限等级 1-100
Permissions JSONMap `gorm:"type:jsonb" json:"permissions"` // 权限列表
// 状态
IsGlobal bool `gorm:"default:false" json:"is_global"` // 是否全局角色
Status string `gorm:"size:20;default:'active'" json:"status"` // active, inactive
// 资源配置
Resources []Resource `gorm:"many2many:role_resources;" json:"resources,omitempty"`
// 时间戳
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt *time.Time `gorm:"index" json:"deleted_at,omitempty"`
// 关联
Tenant Tenant `gorm:"foreignKey:TenantID" json:"tenant,omitempty"`
Users []User `gorm:"foreignKey:RoleID" json:"users,omitempty"`
}
// RoleID 添加到 User 模型
// 需要在 User 模型中添加 RoleID 字段