fix(17): WR-01 keep a menu entry's subtree and parent in its menu

- The admin refuses a parent from another menu than the one the form
  names (errors.parent_menu) instead of moving the entry to the parent's
  menu without a word; BeforeSave records the named menu
  (MenuEntry.RequestedMenuID).
- An entry moved to another menu moves its descendants in the same
  transaction, so the public tree no longer drops them.
This commit is contained in:
2026-10-12 21:30:36 +02:00
parent 43267de323
commit 7255d34ae0
6 changed files with 69 additions and 6 deletions

View File

@@ -378,6 +378,25 @@ func TestMenuAdminSmoke(t *testing.T) {
t.Fatalf("reorder with a foreign entry: %d %s", rec.Code, rec.Body.String())
}
// WR-01: a parent from another menu than the one the entry names is
// refused, and an entry moved to another menu takes its subtree along.
e.expect422(t, token, http.MethodPut, fmt.Sprintf("%s/%d", entriesPath, divider), map[string]any{"menu": mainID, "parent": foreign}, "parent", "golem15.menu::lang.errors.parent_menu")
if dv := e.entry(t, divider); dv.MenuID != mainID || dv.ParentID != nil {
t.Fatalf("a refused move changed the divider: %+v", dv)
}
rec = e.call(t, http.MethodPut, fmt.Sprintf("%s/%d", entriesPath, home), token, map[string]any{"menu": footerID})
if rec.Code != http.StatusOK {
t.Fatalf("move Home to the footer: %d %s", rec.Code, rec.Body.String())
}
for _, id := range []uint{home, child, page} {
if got := e.entry(t, id); got.MenuID != footerID {
t.Fatalf("entry %d stayed in menu %d after its root moved to %d", id, got.MenuID, footerID)
}
}
if dv := e.entry(t, divider); dv.MenuID != mainID {
t.Fatalf("the divider moved with Home: %+v", dv)
}
// Without the permission the screens answer 403.
other := e.admin(t)
for _, path := range []string{menusPath, entriesPath} {