29 lines
918 B
Go
29 lines
918 B
Go
package urbac
|
|
|
|
import "context"
|
|
|
|
type Scope struct {
|
|
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"`
|
|
Name string `json:"name" gorm:"primaryKey;column:name"`
|
|
Label string `json:"label" gorm:"column:label"`
|
|
Parent string `json:"parent" gorm:"column:parent"`
|
|
}
|
|
|
|
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
|
|
}
|