app/auth/group.go

59 lines
1.1 KiB
Go

package auth
import (
"strings"
"time"
"gorm.io/gorm"
)
//Group enum of user permission groups
type Group struct {
ID uint `gorm:"primaryKey"`
// Name starting with '*' is reserved and starting with '_' is internal
Name string `gorm:"unique;not null"`
DisplayName string
Description string
Listeners string
Users []*User `gorm:"many2many:user_groups;"`
//extra fields
GRPF1 string
CreatedAt time.Time
UpdatedAt time.Time
}
var BeforeGroupSave func(*Group, *gorm.DB) error = nil
func (grp *Group) BeforeSave(tx *gorm.DB) (err error) {
// set displayname
if grp.DisplayName == "" {
grp.DisplayName = strings.TrimPrefix(grp.Name, SYS_AUTH_PREFIX)
}
if BeforeGroupSave != nil {
err = BeforeGroupSave(grp, tx)
}
return
}
var BeforeGroupUpdate func(*Group, *gorm.DB) error = nil
func (grp *Group) BeforeUpdate(tx *gorm.DB) (err error) {
if BeforeGroupUpdate != nil {
err = BeforeGroupUpdate(grp, tx)
}
return
}
var BeforeGroupDelete func(*Group, *gorm.DB) error = nil
func (grp *Group) BeforeDelete(tx *gorm.DB) (err error) {
if BeforeGroupDelete != nil {
err = BeforeGroupDelete(grp, tx)
}
return
}