mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Feat: model/policy
This commit is contained in:
@@ -8,18 +8,16 @@ import (
|
||||
// Group 用户组模型
|
||||
type Group struct {
|
||||
gorm.Model
|
||||
Name string
|
||||
Policies string
|
||||
MaxStorage uint64
|
||||
SpeedLimit int
|
||||
ShareEnabled bool
|
||||
RangeTransferEnabled bool
|
||||
WebDAVEnabled bool
|
||||
Aria2Option string
|
||||
Color string
|
||||
Name string
|
||||
Policies string
|
||||
MaxStorage uint64
|
||||
ShareEnabled bool
|
||||
WebDAVEnabled bool
|
||||
Aria2Option string
|
||||
Color string
|
||||
|
||||
// 数据库忽略字段
|
||||
PolicyList []int `gorm:"-"`
|
||||
PolicyList []uint `gorm:"-"`
|
||||
}
|
||||
|
||||
// GetGroupByID 用ID获取用户组
|
||||
@@ -35,3 +33,16 @@ func (group *Group) AfterFind() (err error) {
|
||||
err = json.Unmarshal([]byte(group.Policies), &group.PolicyList)
|
||||
return err
|
||||
}
|
||||
|
||||
// BeforeSave Save用户前的钩子
|
||||
func (group *Group) BeforeSave() (err error) {
|
||||
err = group.SerializePolicyList()
|
||||
return err
|
||||
}
|
||||
|
||||
//SerializePolicyList 将序列后的可选策略列表写入数据库字段
|
||||
func (group *Group) SerializePolicyList() (err error) {
|
||||
optionsValue, err := json.Marshal(&group.PolicyList)
|
||||
group.Policies = string(optionsValue)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user