uauth/model/scope.go
2024-11-01 17:53:47 +08:00

28 lines
983 B
Go

package model
// 用户权限作用域
type Scope struct {
Code string `json:"code" gorm:"column:code;type:varchar(8);not null;primaryKey"`
CreatedAt int64 `json:"created_at" gorm:"column:created_at;autoCreateTime:milli"`
UpdatedAt int64 `json:"updated_at" gorm:"column:updated_at;autoUpdateTime:milli"`
DeletedAt int64 `json:"deleted_at" gorm:"index;column:deleted_at;default:0"`
Label string `json:"label" gorm:"column:label;type:varchar(64)"`
Parent string `json:"parent" gorm:"column:parent;type:varchar(8)"`
}
func (u *Urbac) newScope(ctx context.Context, name, label, parent string) (*Scope, error) {
s := &Scope{Name: name, Label: label, Parent: parent}
if err := u.store.Session(ctx).Create(s).Error; err != nil {
return nil, err
}
return s, nil
}
func (u *Urbac) GetScopeGroup(ctx context.Context, name string) (*Scope, error) {
scope := new(Scope)
err := u.store.Session(ctx).Where("name = ?", name).Take(scope).Error
return scope, err
}