- 新增 Go 语言后端服务(server/),包含用户认证、Agent管理、数据库连接等API - 新增 Python Agent 服务(agent/),实现Agent核心逻辑和工具集 - 前端从原生HTML迁移到Vue.js框架(web/src/) - 添加 Docker Compose 支持(docker-compose.yml) - 添加项目架构文档(docs/ARCHITECTURE.md) - 添加环境变量示例(.env.example)和本地启动脚本(start-local.ps1) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// PermissionLevel 权限级别
|
|
type PermissionLevel int
|
|
|
|
const (
|
|
PermissionRead PermissionLevel = iota + 1
|
|
PermissionWrite
|
|
PermissionExecute
|
|
PermissionAdmin
|
|
)
|
|
|
|
// Role 角色
|
|
type Role struct {
|
|
ID string `json:"id" gorm:"primaryKey"`
|
|
Name string `json:"name" gorm:"uniqueIndex"`
|
|
Permissions []PermissionLevel `json:"permissions" gorm:"type:int[]"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// User 用户
|
|
type User struct {
|
|
ID string `json:"id" gorm:"primaryKey"`
|
|
Username string `json:"username" gorm:"uniqueIndex;size:50;not null"`
|
|
Password string `json:"-" gorm:"not null"`
|
|
Email string `json:"email" gorm:"index"`
|
|
RoleID string `json:"role_id" gorm:"size:50;not null"`
|
|
Role *Role `json:"role,omitempty" gorm:"foreignKey:RoleID"`
|
|
IsActive bool `json:"is_active" gorm:"default:true"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// HasPermission 检查是否有权限
|
|
func (u *User) HasPermission(level PermissionLevel) bool {
|
|
if u.Role == nil {
|
|
return false
|
|
}
|
|
for _, p := range u.Role.Permissions {
|
|
if p >= level {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|