feat: User Groups admin screen with the users count and privileged codes protected
- 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
This commit is contained in:
@@ -4,7 +4,8 @@ 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.
|
||||
// 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"`
|
||||
@@ -13,6 +14,11 @@ type UserGroup struct {
|
||||
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" }
|
||||
@@ -24,6 +30,21 @@ const (
|
||||
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{})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user