forked from baron/baron-sso
40 lines
991 B
Go
40 lines
991 B
Go
package domain
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// UserGroup represents a collection of users within a tenant.
|
|
type UserGroup struct {
|
|
ID string `gorm:"primaryKey;type:uuid;default:gen_random_uuid()" json:"id"`
|
|
TenantID string `gorm:"type:uuid;index;not null" json:"tenantId"`
|
|
Name string `gorm:"not null" json:"name"`
|
|
Description string `json:"description"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
UpdatedAt time.Time `json:"updatedAt"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
|
|
// Relationships
|
|
Members []User `gorm:"-" json:"members,omitempty"`
|
|
}
|
|
|
|
type GroupRole struct {
|
|
TenantID string `json:"tenantId"`
|
|
TenantName string `json:"tenantName"`
|
|
Relation string `json:"relation"`
|
|
}
|
|
|
|
func (ug *UserGroup) TableName() string {
|
|
return "user_groups"
|
|
}
|
|
|
|
func (ug *UserGroup) BeforeCreate(tx *gorm.DB) (err error) {
|
|
if ug.ID == "" {
|
|
ug.ID = uuid.NewString()
|
|
}
|
|
return
|
|
}
|