fix: an unknown redirect status, match or query is refused, not defaulted (WR-17)

The API, MCP, batches and the CSV import copied any value and Normalize
replaced it with the default, answering 201 for a 307 saved as a 301.
RedirectFields.Problems refuses values outside {301, 302, 410}, {exact,
pattern, regex} and {ignore, pass} with value_invalid; the import marks
such rows refused.
This commit is contained in:
2026-10-27 15:36:21 +01:00
parent c8e0961740
commit 24e6f384ca
6 changed files with 68 additions and 0 deletions

View File

@@ -422,6 +422,16 @@ func (s *Service) planRedirect(ctx context.Context, tx *gorm.DB, row CSVRow) (pl
f.TrailingSlash = &b
}
}
if problems := f.Problems(); len(problems) > 0 {
p.status = "refused"
for _, column := range []string{"status", "match", "query"} {
if _, bad := problems[column]; bad {
v, _ := cell(row, column)
p.notes = append(p.notes, s.PhraseCtx(ctx, "golem15.seo::lang.transfer.row_invalid", map[string]string{"field": column, "message": v}))
}
}
return p, nil, nil
}
var rows []models.Redirect
if err := tx.Where("source = ? AND match = ?", strings.TrimSpace(source), strings.TrimSpace(match)).Limit(1).Find(&rows).Error; err != nil {
return p, nil, err