package models import "time" // UserGroup is a row of user_groups, the PHP UserGroup model. Membership // lives in the users_groups pivot (User.Groups). Permissions is the raw // jsonable text column; ParsePermissionSet reads it and PermissionSet.Text // writes it. type UserGroup struct { ID uint `gorm:"column:id;primaryKey"` Name string `gorm:"column:name"` Code *string `gorm:"column:code"` Description *string `gorm:"column:description"` Permissions *string `gorm:"column:permissions"` CreatedAt *time.Time `gorm:"column:created_at"` UpdatedAt *time.Time `gorm:"column:updated_at"` // UsersCount is the number of members, the PHP users_count relation. It // is not a column of user_groups: only a query that selects an expression // named users_count fills it (the admin list does), it is never written, // and it is zero everywhere else. UsersCount int64 `gorm:"column:users_count;->" json:"-"` } func (UserGroup) TableName() string { return "user_groups" } // The PHP UserGroup::GROUP_GUEST and GROUP_REGISTERED codes, seeded by the // create_user_groups migration. const ( GroupGuest = "guest" GroupRegistered = "registered" ) // Fillable is the field list an admin save may set. Permissions is written // through the permission editor, not by a fill. func (UserGroup) Fillable() []string { return []string{"name", "code", "description"} } // Rules is the PHP UserGroup rule set without its regex on code, which the // rule engine does not know: the admin controller checks the code's format. func (UserGroup) Rules() map[string]string { return map[string]string{ "name": "required|between:3,64", "code": "required|unique:user_groups", } } func init() { Register(UserGroup{}) }