fix(09): WR-09 scaffold admin controllers with a required permission and a record source placeholder
This commit is contained in:
@@ -90,12 +90,31 @@ package controllers
|
||||
|
||||
import "git.golem15.com/golem15/summercms/modules/pact"
|
||||
|
||||
var (
|
||||
_ pact.AdminController = {{.Worker}}{}
|
||||
_ pact.AdminRecordSource = {{.Worker}}{}
|
||||
_ pact.AdminPermissioned = {{.Worker}}{}
|
||||
)
|
||||
|
||||
type {{.Worker}} struct{}
|
||||
|
||||
func ({{.Worker}}) ID() string { return {{printf "%q" .Kind}} }
|
||||
func ({{.Worker}}) ModelName() string { return {{printf "%q" .Ident}} }
|
||||
func ({{.Worker}}) ConfigDir() string { return {{printf "%q" .ConfigDir}} }
|
||||
|
||||
// NewRecord returns the model the generic admin handlers query and fill.
|
||||
// TODO: return a pointer to the plugin's model, such as &models.{{.Ident}}{}.
|
||||
// Until then the list and every write answer 500, so nothing is exposed.
|
||||
func ({{.Worker}}) NewRecord() any { return nil }
|
||||
|
||||
// RequiredPermissions is checked before any schema or record is served. Keep
|
||||
// it: a controller without one is open to every administrator. Declare the
|
||||
// code in the plugin's Permissions() (pact.HasPermissions), or the admin API
|
||||
// refuses to start with an unknown-permission error that names this controller.
|
||||
func ({{.Worker}}) RequiredPermissions() []string {
|
||||
return []string{ {{printf "%q" .Permission}} }
|
||||
}
|
||||
|
||||
// {{.Func}} returns the {{.Kind}} admin controller.
|
||||
func {{.Func}}() pact.AdminController { return {{.Worker}}{} }
|
||||
{{end}}
|
||||
|
||||
Reference in New Issue
Block a user