fix(17): WR-03 require a reference for a sitemap row whose type takes one
A registry row saved without a reference resolved to nothing and was left out of /sitemap.xml without a word. The definitions form now refuses it on the row (data.<i>.reference, item.reference_required). The admin smoke test also covers the CR-01 row refusals.
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.golem15.com/golem15/sm-sitemap-plugin/classes"
|
||||
"git.golem15.com/golem15/sm-sitemap-plugin/models"
|
||||
@@ -30,6 +31,7 @@ const typeURLLabel = "golem15.sitemap::lang.item.url"
|
||||
const (
|
||||
errURLScheme = "golem15.sitemap::lang.errors.url_scheme"
|
||||
errURLPattern = "golem15.sitemap::lang.errors.url_pattern"
|
||||
errReference = "golem15.sitemap::lang.item.reference_required"
|
||||
)
|
||||
|
||||
// definitionsAdminController edits the one sitemap definition of the
|
||||
@@ -116,17 +118,25 @@ func (c definitionsAdminController) FormBeforeUpdate(_ context.Context, model an
|
||||
}
|
||||
|
||||
// checkItems refuses, per row, a url outside classes.AllowedItemURL
|
||||
// (data.<i>.url) and a URL pattern that is not a path
|
||||
// (signpost.ValidItemPattern, data.<i>.urlPattern). The PHP plugin checked
|
||||
// neither; a javascript: URL would reach <loc>, which sitemap.xsl renders as
|
||||
// a link.
|
||||
func (definitionsAdminController) checkItems(model any) error {
|
||||
// (data.<i>.url), a URL pattern that is not a path
|
||||
// (signpost.ValidItemPattern, data.<i>.urlPattern) and a missing reference
|
||||
// for a registry type that takes one (data.<i>.reference). The PHP plugin
|
||||
// checked none of them: a javascript: URL would reach <loc>, which
|
||||
// sitemap.xsl renders as a link, and a row without its reference resolves to
|
||||
// nothing and is left out of the sitemap without a word.
|
||||
func (c definitionsAdminController) checkItems(model any) error {
|
||||
def, ok := model.(*models.Definition)
|
||||
if !ok || def == nil {
|
||||
return nil
|
||||
}
|
||||
reg := c.registry()
|
||||
details := map[string]any{}
|
||||
for i, item := range def.Items() {
|
||||
if item.Type != models.ItemTypeURL {
|
||||
if t, known := reg.Type(item.Type); known && t.References != nil && strings.TrimSpace(models.Text(item.Reference)) == "" {
|
||||
details[fmt.Sprintf("data.%d.reference", i)] = []string{errReference}
|
||||
}
|
||||
}
|
||||
if !classes.AllowedItemURL(models.Text(item.URL)) {
|
||||
details[fmt.Sprintf("data.%d.url", i)] = []string{errURLScheme}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user