feat(32-01): form extension placement rules, boot errors and owner-aware branches

- placement: tabs before/after tab anchors, anchor cursor for plugin
  order, own-field anchors sorted with cycle detection, Requires() rule,
  anchor tab inheritance, Hide with reference checks, zone refusal (D-101)
- boot errors name plugin, controller and offending name; fileupload is
  refused (D-100); localized tab label collisions checked in Activate
- extension widgets dispatch to AdminFormExtension.Actions, partials
  render from the contributor's Dir through PartialData, plugin field
  types decode for Save and load after Load, translatable values reach
  Save as locale maps and never the owner's translations
- Permissions and Visible apply to schema, show, save, widgets and
  partials; AdminFormErrors answer 422, Save notices join meta.notices
This commit is contained in:
2026-10-26 22:00:51 +01:00
parent 4bb22a85dd
commit e7423bd21f
10 changed files with 1096 additions and 130 deletions

View File

@@ -11,6 +11,7 @@ import (
"strconv"
"strings"
"git.golem15.com/golem15/summercms/modules/bouncer"
"git.golem15.com/golem15/summercms/modules/pact"
"git.golem15.com/golem15/summercms/modules/phrasebook"
"git.golem15.com/golem15/summercms/modules/towel"
@@ -500,8 +501,23 @@ func (s *service) partial(w http.ResponseWriter, r *http.Request) {
s.protect(w, r, func(cc *CompiledController) {
name := r.PathValue("name")
compiled, ok := cc.partials[name]
provider, isProvider := cc.Controller.(pact.AdminPartialData)
if !ok || !isProvider || provider == nil {
var data func(ctx context.Context, name string, record any) (any, error)
if provider, isProvider := cc.Controller.(pact.AdminPartialData); isProvider && provider != nil {
data = provider.PartialData
}
formPartial := cc.formPartials[name]
// D-91: a form extension's partial renders from the contributing
// plugin's template through its PartialData, only for an
// administrator who sees the extension.
if ext := cc.extensionPartials[name]; ext != nil {
principal, _ := bouncer.User(r.Context())
if !extensionVisible(r.Context(), principal, ext) {
WriteError(w, http.StatusNotFound, "not_found", msgNotFound)
return
}
compiled, ok, data, formPartial = ext.partials[name], true, ext.def.PartialData, true
}
if !ok || data == nil {
WriteError(w, http.StatusNotFound, "not_found", msgNotFound)
return
}
@@ -509,7 +525,7 @@ func (s *service) partial(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
if query.Has("id") {
id, err := strconv.ParseUint(query.Get("id"), 10, 64)
if err != nil || id == 0 || !cc.formPartials[name] {
if err != nil || id == 0 || !formPartial {
WriteError(w, http.StatusNotFound, "not_found", msgNotFound)
return
}
@@ -530,7 +546,7 @@ func (s *service) partial(w http.ResponseWriter, r *http.Request) {
moduleLog.Error("cabana: admin partial failed", "controller", controllerID(cc), "partial", name, "reason", reason, "error", err)
WriteError(w, http.StatusInternalServerError, "error", msgServerError)
}
vm, err := provider.PartialData(ctx, name, record)
vm, err := data(ctx, name, record)
if err != nil {
fail("view model", err)
return