fix(09): WR-03 refuse writes that the compiled list and form do not declare
This commit is contained in:
@@ -107,6 +107,29 @@ func compileRegistry(items []controllerRef) (*Registry, error) {
|
||||
return &Registry{byID: byID, assets: assets}, nil
|
||||
}
|
||||
|
||||
// operationDeclared reports whether the controller's compiled list and form
|
||||
// declare the write operation: create, update, delete or bulk-delete.
|
||||
func (cc *CompiledController) operationDeclared(op string) bool {
|
||||
switch op {
|
||||
case "create":
|
||||
return cc.Form != nil && (cc.List == nil || hasToolbarButton(cc.List, "create"))
|
||||
case "update", "delete":
|
||||
return cc.Form != nil
|
||||
case "bulk-delete":
|
||||
return cc.List != nil && hasToolbarButton(cc.List, "delete")
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func hasToolbarButton(list *ListSchema, name string) bool {
|
||||
for _, button := range list.ToolbarButtons {
|
||||
if button == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func withoutAction(actions []string, drop string) []string {
|
||||
out := make([]string, 0, len(actions))
|
||||
for _, action := range actions {
|
||||
|
||||
Reference in New Issue
Block a user