feat: фича-флаги конфигурации — клиент не сохраняет то, чего не понимает
Конфигурация хранит feature_flags (JSON-массив, NULL = нет) — какие данные она использует. Флаги выводятся из содержимого при каждом сохранении (internal/configfeatures). Если у конфигурации есть флаг, неизвестный этой версии, клиент отказывается её изменять: все write-пути отдают 409 unsupported_config_features со списком флагов, конфигуратор показывает баннер «обновите приложение» и блокирует сохранение. Push на сервер тоже отказывается, если серверная версия несёт неизвестный флаг; такое изменение остаётся в очереди до обновления. Первый флаг: sale_row_markups. Серверная миграция 034 добавляет колонку; до её применения запись идёт без колонки (с warning). Формат имён и реестр флагов — bible-local/02-architecture.md, ADL 2026-09-24. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6b9652e3ac
commit
4e3b43dbd0
18 files changed
+579
-20
No files matched your search
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"git.mchus.pro/mchus/quoteforge/internal/appmeta"
|
||||
"git.mchus.pro/mchus/quoteforge/internal/article"
|
||||
"git.mchus.pro/mchus/quoteforge/internal/configfeatures"
|
||||
"git.mchus.pro/mchus/quoteforge/internal/localdb"
|
||||
"git.mchus.pro/mchus/quoteforge/internal/models"
|
||||
"git.mchus.pro/mchus/quoteforge/internal/services/sync"
|
||||
@@ -324,6 +325,7 @@ func (s *LocalConfigurationService) CloneToProject(configUUID string, ownerUsern
|
||||
TotalPrice: &total,
|
||||
CustomPrice: original.CustomPrice,
|
||||
Notes: original.Notes,
|
||||
FeatureFlags: original.FeatureFlags,
|
||||
IsTemplate: false,
|
||||
ServerCount: original.ServerCount,
|
||||
ServerModel: original.ServerModel,
|
||||
@@ -684,6 +686,7 @@ func (s *LocalConfigurationService) CloneNoAuthToProjectFromVersion(configUUID s
|
||||
TotalPrice: &total,
|
||||
CustomPrice: original.CustomPrice,
|
||||
Notes: original.Notes,
|
||||
FeatureFlags: original.FeatureFlags,
|
||||
IsTemplate: false,
|
||||
ServerCount: original.ServerCount,
|
||||
ServerModel: original.ServerModel,
|
||||
@@ -928,6 +931,9 @@ func (s *LocalConfigurationService) UpdateServerCount(configUUID string, serverC
|
||||
return nil, ErrConfigNotFound
|
||||
}
|
||||
|
||||
if err := applyFeatureFlags(localCfg.FeatureFlags, localCfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
localCfg.ServerCount = serverCount
|
||||
total := localCfg.Items.Total()
|
||||
if serverCount > 1 {
|
||||
@@ -1172,6 +1178,9 @@ func (s *LocalConfigurationService) createWithVersion(localCfg *localdb.LocalCon
|
||||
}
|
||||
|
||||
func (s *LocalConfigurationService) createWithVersionTx(tx *gorm.DB, localCfg *localdb.LocalConfiguration, createdBy string) error {
|
||||
if err := applyFeatureFlags(localCfg.FeatureFlags, localCfg); err != nil {
|
||||
return err
|
||||
}
|
||||
if localCfg.IsActive {
|
||||
if err := s.ensureConfigurationLineTx(tx, localCfg); err != nil {
|
||||
return err
|
||||
@@ -1217,6 +1226,9 @@ func (s *LocalConfigurationService) saveWithVersionAndPending(localCfg *localdb.
|
||||
}
|
||||
return fmt.Errorf("lock configuration row: %w", err)
|
||||
}
|
||||
if err := applyFeatureFlags(locked.FeatureFlags, localCfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if operation == "update" {
|
||||
currentVersion, err := s.loadCurrentVersionTx(tx, &locked)
|
||||
@@ -1297,6 +1309,7 @@ func hasNonRevisionConfigurationChanges(current *localdb.LocalConfiguration, nex
|
||||
}
|
||||
if current.Name != next.Name ||
|
||||
current.Notes != next.Notes ||
|
||||
strings.Join(current.FeatureFlags, ",") != strings.Join(next.FeatureFlags, ",") ||
|
||||
current.IsTemplate != next.IsTemplate ||
|
||||
current.ServerModel != next.ServerModel ||
|
||||
current.SupportCode != next.SupportCode ||
|
||||
@@ -1640,12 +1653,17 @@ func (s *LocalConfigurationService) rollbackToVersion(configurationUUID string,
|
||||
return fmt.Errorf("decode target rollback snapshot: %w", err)
|
||||
}
|
||||
|
||||
if err := configfeatures.Check(append(append([]string{}, current.FeatureFlags...), rollbackData.FeatureFlags...)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Keep stable identity/sync linkage; restore editable config content from target snapshot.
|
||||
current.Name = rollbackData.Name
|
||||
current.Items = rollbackData.Items
|
||||
current.TotalPrice = rollbackData.TotalPrice
|
||||
current.CustomPrice = rollbackData.CustomPrice
|
||||
current.Notes = rollbackData.Notes
|
||||
current.FeatureFlags = configfeatures.Detect(rollbackData.Notes)
|
||||
current.IsTemplate = rollbackData.IsTemplate
|
||||
current.ServerCount = rollbackData.ServerCount
|
||||
current.ServerModel = rollbackData.ServerModel
|
||||
@@ -1859,3 +1877,14 @@ func (s *LocalConfigurationService) resolvePricelistID(pricelistID *uint) (*uint
|
||||
}
|
||||
return &latest.ServerID, nil
|
||||
}
|
||||
|
||||
// applyFeatureFlags refuses a write when the configuration as stored carries feature
|
||||
// flags this build doesn't know (it could not round-trip the data behind them), and
|
||||
// otherwise re-derives next's flags from its content.
|
||||
func applyFeatureFlags(stored models.FeatureFlags, next *localdb.LocalConfiguration) error {
|
||||
if err := configfeatures.Check(stored); err != nil {
|
||||
return err
|
||||
}
|
||||
next.FeatureFlags = configfeatures.Detect(next.Notes)
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user