- controller golem15.user.usergroups behind golem15.users.access_groups - list with users_count from the list's own query; form with the checkbox permission editor stored in user_groups.permissions - creating a group with a privileged code, changing a code to or from one and deleting a privileged group need golem15.users.manage_privileged_groups - a group delete removes its users_groups rows in the same transaction - UserGroup gains Fillable, Rules and the read-only UsersCount; PermissionSet.Text - TestAdminGroups and the D-06 matrix in TestAdminPrivilegedGroups
51 lines
1.7 KiB
Go
51 lines
1.7 KiB
Go
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{})
|
|
}
|