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:
47
controllers/app_access.go
Normal file
47
controllers/app_access.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"git.golem15.com/golem15/summercms/modules/backpack"
|
||||
"git.golem15.com/golem15/summercms/modules/compass"
|
||||
"git.golem15.com/golem15/summercms/modules/phrasebook"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// appAccess resolves the booted application on every call, so an admin
|
||||
// controller never keeps a database handle or a config of its own.
|
||||
type appAccess func() *backpack.App
|
||||
|
||||
// application returns the booted app, or nil before boot.
|
||||
func (a appAccess) application() *backpack.App {
|
||||
if a == nil {
|
||||
return nil
|
||||
}
|
||||
return a()
|
||||
}
|
||||
|
||||
// db is the application pool, or nil when the app has none.
|
||||
func (a appAccess) db() *gorm.DB {
|
||||
app := a.application()
|
||||
if app == nil {
|
||||
return nil
|
||||
}
|
||||
gdb, ok := app.Lookup[*gorm.DB]()
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return gdb
|
||||
}
|
||||
|
||||
// config is the application config, or nil before boot.
|
||||
func (a appAccess) config() *compass.Config {
|
||||
app := a.application()
|
||||
if app == nil {
|
||||
return nil
|
||||
}
|
||||
return app.Config
|
||||
}
|
||||
|
||||
// translator is the application translator, or nil when none is published.
|
||||
func (a appAccess) translator() *phrasebook.Translator {
|
||||
return appTranslator(a.application())
|
||||
}
|
||||
Reference in New Issue
Block a user