refactor(auth): delegate access control to be-system
Remove Agent Desk users, roles, login sessions, tokens, and local permission persistence. Expose the backend as an embeddable ai-agent module with host-provided subject lookup and operation authorization callbacks, and complete the frontend/backend repository split.
This commit is contained in:
+1
-128
@@ -1,26 +1,17 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"agent-desk/internal/pkg/enums"
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/enums"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Models 注册所有需要迁移和代码生成的模型。
|
||||
var Models = []any{
|
||||
&Migration{},
|
||||
&User{},
|
||||
&UserIdentity{},
|
||||
&Company{},
|
||||
&Customer{},
|
||||
&CustomerIdentity{},
|
||||
&CustomerContact{},
|
||||
&Role{},
|
||||
&Permission{},
|
||||
&UserRole{},
|
||||
&RolePermission{},
|
||||
&UserPermission{},
|
||||
&LoginSession{},
|
||||
&LoginCredentialLog{},
|
||||
&Asset{},
|
||||
&Tag{},
|
||||
&Conversation{},
|
||||
@@ -156,39 +147,6 @@ type AuditFields struct {
|
||||
UpdateUserName string `gorm:"type:varchar(100);not null;default:''"` // UpdateUserName 记录最后更新人名称;系统任务写system。
|
||||
}
|
||||
|
||||
// User 后台用户账号。
|
||||
type User struct {
|
||||
ID int64 `gorm:"primaryKey;autoIncrement"`
|
||||
Username string `gorm:"type:varchar(100);not null;uniqueIndex"`
|
||||
Nickname string `gorm:"type:varchar(100);not null;default:'';index"`
|
||||
Avatar string `gorm:"type:varchar(255);not null;default:''"`
|
||||
Mobile *string `gorm:"type:varchar(32);uniqueIndex"`
|
||||
Email *string `gorm:"type:varchar(100);uniqueIndex"`
|
||||
Password string `gorm:"type:varchar(255);not null;default:''"`
|
||||
PasswordSalt string `gorm:"type:varchar(64);not null;default:''"`
|
||||
Status enums.Status `gorm:"type:int;not null;default:0;index"`
|
||||
LastLoginAt *time.Time
|
||||
LastLoginIP string `gorm:"type:varchar(64);not null;default:''"`
|
||||
Remark string `gorm:"type:text"`
|
||||
DeletedAt *time.Time `gorm:"index"`
|
||||
AuditFields
|
||||
}
|
||||
|
||||
// UserIdentity 第三方身份绑定信息。
|
||||
type UserIdentity struct {
|
||||
ID int64 `gorm:"primaryKey;autoIncrement"`
|
||||
UserID int64 `gorm:"type:bigint;not null;index;uniqueIndex:uk_provider_user"`
|
||||
Provider enums.ThirdProvider `gorm:"type:varchar(50);not null;default:'';index;uniqueIndex:uk_provider_user;uniqueIndex:uk_provider_union"`
|
||||
ProviderUserID string `gorm:"type:varchar(128);not null;default:'';uniqueIndex:uk_provider_user"`
|
||||
ProviderUnionID *string `gorm:"type:varchar(128);uniqueIndex:uk_provider_union"`
|
||||
ProviderCorpID string `gorm:"type:varchar(128);not null;default:'';index"`
|
||||
ProviderName string `gorm:"type:varchar(100);not null;default:''"`
|
||||
RawProfile string `gorm:"type:text"`
|
||||
Status enums.Status `gorm:"type:int;not null;default:0;index"`
|
||||
LastAuthAt *time.Time
|
||||
AuditFields
|
||||
}
|
||||
|
||||
// Company 客户公司(组织)表。
|
||||
//
|
||||
// 用于存储公司主体信息;Customer(人)可通过 CompanyID 关联到所属公司。
|
||||
@@ -245,91 +203,6 @@ type CustomerContact struct {
|
||||
AuditFields
|
||||
}
|
||||
|
||||
// Role 角色定义。
|
||||
type Role struct {
|
||||
ID int64 `gorm:"primaryKey;autoIncrement"`
|
||||
Name string `gorm:"type:varchar(100);not null;default:'';index"`
|
||||
Code string `gorm:"type:varchar(100);not null;uniqueIndex"`
|
||||
Status enums.Status `gorm:"type:int;not null;default:0;index"`
|
||||
IsSystem bool `gorm:"not null;default:false;index"`
|
||||
SortNo int `gorm:"type:int;not null;default:0;index"`
|
||||
Remark string `gorm:"type:text"`
|
||||
AuditFields
|
||||
}
|
||||
|
||||
// Permission 权限点定义。
|
||||
type Permission struct {
|
||||
ID int64 `gorm:"primaryKey;autoIncrement"`
|
||||
Name string `gorm:"type:varchar(100);not null;default:''"`
|
||||
Code string `gorm:"type:varchar(150);not null;uniqueIndex"`
|
||||
Type string `gorm:"type:varchar(20);not null;default:'';index"`
|
||||
GroupName string `gorm:"type:varchar(100);not null;default:'';index"`
|
||||
ParentID int64 `gorm:"type:bigint;not null;default:0;index"`
|
||||
Path string `gorm:"type:varchar(255);not null;default:''"`
|
||||
Method string `gorm:"type:varchar(20);not null;default:''"`
|
||||
APIPath string `gorm:"type:varchar(255);not null;default:''"`
|
||||
SortNo int `gorm:"type:int;not null;default:0;index"`
|
||||
Status enums.Status `gorm:"type:int;not null;default:0;index"`
|
||||
IsBuiltin bool `gorm:"not null;default:true;index"`
|
||||
Remark string `gorm:"type:text"`
|
||||
AuditFields
|
||||
}
|
||||
|
||||
// UserRole 用户和角色关联。
|
||||
type UserRole struct {
|
||||
ID int64 `gorm:"primaryKey;autoIncrement"`
|
||||
UserID int64 `gorm:"type:bigint;not null;index;uniqueIndex:uk_user_role"`
|
||||
RoleID int64 `gorm:"type:bigint;not null;index;uniqueIndex:uk_user_role"`
|
||||
AuditFields
|
||||
}
|
||||
|
||||
// RolePermission 角色和权限关联。
|
||||
type RolePermission struct {
|
||||
ID int64 `gorm:"primaryKey;autoIncrement"`
|
||||
RoleID int64 `gorm:"type:bigint;not null;index;uniqueIndex:uk_role_permission"`
|
||||
PermissionID int64 `gorm:"type:bigint;not null;index;uniqueIndex:uk_role_permission"`
|
||||
AuditFields
|
||||
}
|
||||
|
||||
// UserPermission 用户级例外权限。
|
||||
//
|
||||
// 用于处理少量临时授权或拒绝授权场景。
|
||||
type UserPermission struct {
|
||||
ID int64 `gorm:"primaryKey;autoIncrement"`
|
||||
UserID int64 `gorm:"type:bigint;not null;index;uniqueIndex:uk_user_permission"`
|
||||
PermissionID int64 `gorm:"type:bigint;not null;index;uniqueIndex:uk_user_permission"`
|
||||
Effect int `gorm:"type:int;not null;default:1;index"` // Effect 表示权限生效方式:1允许 -1拒绝。
|
||||
ExpiredAt *time.Time
|
||||
Remark string `gorm:"type:text"`
|
||||
AuditFields
|
||||
}
|
||||
|
||||
// LoginSession 表示一次后台登录会话。
|
||||
type LoginSession struct {
|
||||
ID int64 `gorm:"primaryKey;autoIncrement"` // ID 为登录会话主键。
|
||||
UserID int64 `gorm:"type:bigint;not null;index"` // UserID 为登录用户 ID。
|
||||
Token string `gorm:"type:varchar(128);not null;uniqueIndex"` // Token 为随机不透明登录凭证,使用 ak_ 前缀。
|
||||
ClientType string `gorm:"type:varchar(50);not null;default:'';index"` // ClientType 为客户端类型,后台 Web 端固定为 admin_web。
|
||||
ClientIP string `gorm:"type:varchar(64);not null;default:''"` // ClientIP 为登录请求来源 IP。
|
||||
UserAgent string `gorm:"type:varchar(255);not null;default:''"` // UserAgent 为登录请求浏览器或客户端 UA。
|
||||
ExpiredAt time.Time `gorm:"not null;index"` // ExpiredAt 为 token 过期时间。
|
||||
RevokedAt *time.Time `gorm:"index"` // RevokedAt 为主动注销或踢下线时间,非空表示已失效。
|
||||
LastSeenAt *time.Time // LastSeenAt 为最近一次成功鉴权时间。
|
||||
AuditFields
|
||||
}
|
||||
|
||||
// LoginCredentialLog 记录一次后台登录凭证校验结果。
|
||||
type LoginCredentialLog struct {
|
||||
ID int64 `gorm:"primaryKey;autoIncrement"` // ID 为登录凭证日志主键。
|
||||
Principal string `gorm:"type:varchar(100);not null;default:'';index"` // Principal 为用户输入的登录名。
|
||||
UserID int64 `gorm:"type:bigint;not null;default:0;index"` // UserID 为匹配到的用户 ID,未匹配时为 0。
|
||||
Success bool `gorm:"not null;default:false;index"` // Success 表示本次凭证校验是否成功。
|
||||
ClientIP string `gorm:"type:varchar(64);not null;default:''"` // ClientIP 为登录请求来源 IP。
|
||||
UserAgent string `gorm:"type:varchar(255);not null;default:''"` // UserAgent 为登录请求浏览器或客户端 UA。
|
||||
Reason string `gorm:"type:varchar(255);not null;default:''"` // Reason 为校验结果原因。
|
||||
CreatedAt time.Time `gorm:"not null;index"` // CreatedAt 为日志创建时间。
|
||||
}
|
||||
|
||||
// Asset 存储的文件资源,如上传的附件等。
|
||||
type Asset struct {
|
||||
ID int64 `gorm:"primaryKey;autoIncrement"`
|
||||
|
||||
Reference in New Issue
Block a user