fix: set_url_seo and record imports refuse a locale the record does not have (WR-18)

A locale given with a URL write overrode the matched one unchecked, so
"xx" created an entry nothing ever reads while the answer reported
success. SetURLSEO (API, MCP, batch set_seo, records import) now requires
one of the record's locales and refuses others with api.locale_unknown.
This commit is contained in:
2026-10-27 15:37:31 +01:00
parent 24e6f384ca
commit cff2d29fdd
5 changed files with 23 additions and 2 deletions

View File

@@ -156,7 +156,15 @@ func (s *Service) SetURLSEO(ctx context.Context, tx *gorm.DB, in URLSEOWrite) (U
}
if owner.WrittenTo == WrittenToRecord {
locale := owner.Locale
if l := strings.TrimSpace(in.Locale); l != "" {
if l := strings.TrimSpace(in.Locale); l != "" && l != locale {
// Another locale must be one the record describes (WR-18): an
// entry in any other would never be read by the resolver or the
// SEO tab.
if _, known := s.recordLocales(ctx, typ.Key, owner.ID)[l]; !known {
return URLSEOResult{}, &ProblemsError{Problems: map[string][]models.Problem{
"locale": {{Key: "golem15.seo::lang.api.locale_unknown", Params: map[string]string{"locale": l}}},
}}
}
locale = l
}
owner.Locale = locale