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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user