app/auth/group.go

50 lines
1.0 KiB
Go
Raw Normal View History

2021-12-16 04:11:33 +00:00
package auth
import (
"strings"
"time"
"gorm.io/gorm"
)
//Group enum of user permission groups
type Group struct {
2021-12-19 06:17:10 +00:00
ID uint `gorm:"primaryKey"`
2021-12-16 04:11:33 +00:00
// Name starting with '*' is reserved and starting with '_' is internal
Name string `gorm:"unique;not null"`
DisplayName string
Description string
2021-12-19 13:49:30 +00:00
Listeners string
2021-12-16 04:11:33 +00:00
Users []*User `gorm:"many2many:user_groups;"`
2021-12-18 19:23:21 +00:00
//extra fields
GRPF1 string
2021-12-19 06:17:10 +00:00
CreatedAt time.Time
UpdatedAt time.Time
2021-12-16 04:11:33 +00:00
}
2021-12-19 13:42:28 +00:00
var BeforeGroupSave func(*Group, *gorm.DB) error = nil
2021-12-19 13:30:50 +00:00
2021-12-16 04:11:33 +00:00
func (grp *Group) BeforeSave(tx *gorm.DB) (err error) {
// set displayname
if grp.DisplayName == "" {
2021-12-18 17:37:44 +00:00
grp.DisplayName = strings.TrimPrefix(grp.Name, SYS_AUTH_PREFIX)
2021-12-16 04:11:33 +00:00
}
2021-12-19 13:42:28 +00:00
return BeforeGroupSave(grp, tx)
2021-12-16 04:11:33 +00:00
}
2021-12-19 13:32:09 +00:00
2021-12-19 13:42:28 +00:00
var BeforeGroupUpdate func(*Group, *gorm.DB) error = nil
2021-12-19 13:32:09 +00:00
func (grp *Group) BeforeUpdate(tx *gorm.DB) (err error) {
2021-12-19 13:42:28 +00:00
return BeforeGroupUpdate(grp, tx)
2021-12-19 13:32:09 +00:00
}
2021-12-19 13:33:11 +00:00
2021-12-19 13:42:28 +00:00
var BeforeGroupDelete func(*Group, *gorm.DB) error = nil
2021-12-19 13:33:11 +00:00
func (grp *Group) BeforeDelete(tx *gorm.DB) (err error) {
2021-12-19 13:42:28 +00:00
return BeforeGroupDelete(grp, tx)
2021-12-19 13:33:11 +00:00
}