feat(17-04): menu plugin admin with registry types, URL checks and tree reorder
- golem15.menu plugin, tables golem15_menu_menus and golem15_menu_menu_entries with the PHP columns plus a nullable url_pattern (D-02) - MenuEntry BeforeSave ports PHP beforeSave: nest columns 0, menu from the parent, sort_order after the menu's last - entry type dropdown: url, divider and the signpost registry types; reference depends on type through signpost.ReferenceOptions - URL scheme allowlist (errors.url_scheme), target _self or _blank, menu and parent cycle checks - menu filter, toolbar reorder/create/delete and config_reorder.yaml partitioned by menu - navigation Menus with Menus and Menu entries, permission golem15.menu.manage_menu, en and pl phrasebooks - TestMenuAdminSmoke
This commit is contained in:
33
updates/202610110001_create_golem15_menu_menus.go
Normal file
33
updates/202610110001_create_golem15_menu_menus.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package updates
|
||||
|
||||
import (
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// createMenus creates golem15_menu_menus with the PHP columns (v1.0.2
|
||||
// create_menus_table): a unique code, the active flag (default true) and an
|
||||
// optional CSS class.
|
||||
var createMenus = []*gormigrate.Migration{
|
||||
{
|
||||
ID: "202610110001_create_golem15_menu_menus",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
return tx.Exec(`CREATE TABLE golem15_menu_menus (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
code VARCHAR(255) NOT NULL UNIQUE,
|
||||
is_active BOOLEAN NOT NULL DEFAULT true,
|
||||
css_class VARCHAR(255) NULL,
|
||||
created_at TIMESTAMPTZ NULL,
|
||||
updated_at TIMESTAMPTZ NULL
|
||||
)`).Error
|
||||
},
|
||||
Rollback: func(tx *gorm.DB) error {
|
||||
return tx.Exec(`DROP TABLE IF EXISTS golem15_menu_menus`).Error
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
Register(createMenus...)
|
||||
}
|
||||
53
updates/202610110002_create_golem15_menu_menu_entries.go
Normal file
53
updates/202610110002_create_golem15_menu_menu_entries.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package updates
|
||||
|
||||
import (
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// createMenuEntries creates golem15_menu_menu_entries with the PHP columns
|
||||
// (v1.0.1 create_menu_entries_table): the menu, the tree columns (parent_id,
|
||||
// the NestedTree nest columns and sort_order), the entry's type, title, URL
|
||||
// and reference, and its display attributes.
|
||||
var createMenuEntries = []*gormigrate.Migration{
|
||||
{
|
||||
ID: "202610110002_create_golem15_menu_menu_entries",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
for _, stmt := range []string{
|
||||
`CREATE TABLE golem15_menu_menu_entries (
|
||||
id SERIAL PRIMARY KEY,
|
||||
menu_id INTEGER NOT NULL,
|
||||
parent_id INTEGER NULL,
|
||||
nest_left INTEGER NOT NULL,
|
||||
nest_right INTEGER NOT NULL,
|
||||
nest_depth INTEGER NOT NULL,
|
||||
sort_order INTEGER NULL,
|
||||
type VARCHAR(255) NOT NULL,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
url VARCHAR(255) NULL,
|
||||
reference VARCHAR(255) NULL,
|
||||
code VARCHAR(255) NULL,
|
||||
icon VARCHAR(255) NULL,
|
||||
css_class VARCHAR(255) NULL,
|
||||
target VARCHAR(255) NULL,
|
||||
is_published BOOLEAN NOT NULL DEFAULT true,
|
||||
created_at TIMESTAMPTZ NULL,
|
||||
updated_at TIMESTAMPTZ NULL
|
||||
)`,
|
||||
`CREATE INDEX golem15_menu_menu_entries_menu_parent_sort_index ON golem15_menu_menu_entries (menu_id, parent_id, sort_order)`,
|
||||
} {
|
||||
if err := tx.Exec(stmt).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Rollback: func(tx *gorm.DB) error {
|
||||
return tx.Exec(`DROP TABLE IF EXISTS golem15_menu_menu_entries`).Error
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
Register(createMenuEntries...)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package updates
|
||||
|
||||
import (
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// addURLPattern adds the one column the PHP table lacks: a nullable
|
||||
// url_pattern, the entry's own URL pattern override for registry types
|
||||
// (D-02). Rows copied from PHP keep NULL there.
|
||||
var addURLPattern = []*gormigrate.Migration{
|
||||
{
|
||||
ID: "202610110003_add_url_pattern_to_golem15_menu_menu_entries",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
return tx.Exec(`ALTER TABLE golem15_menu_menu_entries ADD COLUMN url_pattern VARCHAR(255) NULL`).Error
|
||||
},
|
||||
Rollback: func(tx *gorm.DB) error {
|
||||
return tx.Exec(`ALTER TABLE golem15_menu_menu_entries DROP COLUMN IF EXISTS url_pattern`).Error
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
Register(addURLPattern...)
|
||||
}
|
||||
17
updates/registry.go
Normal file
17
updates/registry.go
Normal file
@@ -0,0 +1,17 @@
|
||||
// Package updates holds the menu plugin's migrations.
|
||||
package updates
|
||||
|
||||
import "github.com/go-gormigrate/gormigrate/v2"
|
||||
|
||||
var all []*gormigrate.Migration
|
||||
|
||||
// Register appends gormigrate steps so later files add migrations without
|
||||
// editing plugin.go.
|
||||
func Register(ms ...*gormigrate.Migration) {
|
||||
all = append(all, ms...)
|
||||
}
|
||||
|
||||
// All returns every migration registered by this package.
|
||||
func All() []*gormigrate.Migration {
|
||||
return all
|
||||
}
|
||||
Reference in New Issue
Block a user