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
@@ -37,13 +37,24 @@
|
||||
title="Настройки цен">
|
||||
Цены
|
||||
</button>
|
||||
<button onclick="saveConfig()" class="px-4 py-2 bg-green-600 text-white rounded hover:bg-green-700">
|
||||
<button id="save-config-btn" onclick="saveConfig()" class="px-4 py-2 bg-green-600 text-white rounded hover:bg-green-700 disabled:opacity-50 disabled:cursor-not-allowed">
|
||||
Сохранить
|
||||
</button>
|
||||
<span id="price-update-date" class="text-sm text-gray-500"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Shown when the config carries feature flags this build doesn't know: saving is refused
|
||||
(see setConfigUnsupportedFeatures / internal/configfeatures). -->
|
||||
<div id="config-unsupported-banner" class="hidden bg-red-50 border border-red-200 text-red-800 rounded-lg px-4 py-3 text-sm" role="alert">
|
||||
<div class="font-semibold">Эта конфигурация создана в более новой версии QuoteForge</div>
|
||||
<div class="mt-1">
|
||||
Она использует функции, которых нет в вашей версии:
|
||||
<span id="config-unsupported-list" class="font-mono"></span>.
|
||||
Сохранение отключено, чтобы не потерять эти данные. Обновите приложение, чтобы редактировать конфигурацию.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Server count input -->
|
||||
<div class="bg-white rounded-lg shadow p-4 mb-4">
|
||||
<div class="flex items-center space-x-4">
|
||||
@@ -623,6 +634,25 @@ const PricingMarkup = {
|
||||
// reads it live rather than relying on per-render input state.
|
||||
let saleRowMarkups = {};
|
||||
|
||||
// Feature flags of this configuration unknown to this build (server-computed
|
||||
// unsupported_features). Non-empty → saving is refused both here and by the backend.
|
||||
let configUnsupportedFeatures = [];
|
||||
|
||||
function setConfigUnsupportedFeatures(flags) {
|
||||
configUnsupportedFeatures = Array.isArray(flags) ? flags.filter(Boolean) : [];
|
||||
const blocked = configUnsupportedFeatures.length > 0;
|
||||
document.getElementById('config-unsupported-banner')?.classList.toggle('hidden', !blocked);
|
||||
const list = document.getElementById('config-unsupported-list');
|
||||
if (list) list.textContent = configUnsupportedFeatures.join(', ');
|
||||
const btn = document.getElementById('save-config-btn');
|
||||
if (btn) btn.disabled = blocked;
|
||||
}
|
||||
|
||||
function unsupportedFeaturesMessage() {
|
||||
return 'Сохранение невозможно: конфигурация использует функции, неизвестные этой версии ('
|
||||
+ configUnsupportedFeatures.join(', ') + '). Обновите приложение.';
|
||||
}
|
||||
|
||||
// Notes keys this client doesn't understand (top-level and inside pricing_ui), kept from
|
||||
// the last restorePricingStateFromNotes() and written back verbatim on save — otherwise
|
||||
// an older client re-saving a config silently drops fields added by a newer one.
|
||||
@@ -1043,6 +1073,7 @@ document.addEventListener('DOMContentLoaded', async function() {
|
||||
supportCode = parseSupportCodeFromLotName((cart.find(i => (i.lot_name || '').toUpperCase().startsWith('SVC_')) || {}).lot_name);
|
||||
currentArticle = config.article || '';
|
||||
restorePricingStateFromNotes(config.notes || '');
|
||||
setConfigUnsupportedFeatures(config.unsupported_features);
|
||||
|
||||
// Restore custom price if saved
|
||||
if (config.custom_price) {
|
||||
@@ -2770,7 +2801,7 @@ function restoreAutosaveDraftIfAny() {
|
||||
}
|
||||
|
||||
function saveConfigOnExit() {
|
||||
if (!configUUID || !hasUnsavedChanges || exitSaveStarted) return;
|
||||
if (!configUUID || !hasUnsavedChanges || exitSaveStarted || configUnsupportedFeatures.length) return;
|
||||
exitSaveStarted = true;
|
||||
try {
|
||||
fetch('/api/configs/' + configUUID, {
|
||||
@@ -2800,6 +2831,10 @@ function triggerAutoSave() {
|
||||
async function saveConfig(showNotification = true) {
|
||||
// RBAC disabled - no token check required
|
||||
if (!configUUID) return;
|
||||
if (configUnsupportedFeatures.length) {
|
||||
if (showNotification) showToast(unsupportedFeaturesMessage(), 'error');
|
||||
return;
|
||||
}
|
||||
if (priceLevelsRefreshTimer) {
|
||||
clearTimeout(priceLevelsRefreshTimer);
|
||||
priceLevelsRefreshTimer = null;
|
||||
@@ -2817,6 +2852,14 @@ async function saveConfig(showNotification = true) {
|
||||
});
|
||||
|
||||
if (!resp.ok) {
|
||||
// 409 unsupported_config_features: a newer client added data this build can't
|
||||
// round-trip (possibly since this page was opened) — lock the page.
|
||||
const errBody = await resp.json().catch(() => null);
|
||||
if (errBody && errBody.code === 'unsupported_config_features') {
|
||||
setConfigUnsupportedFeatures(errBody.unsupported_features);
|
||||
if (showNotification) showToast(unsupportedFeaturesMessage(), 'error');
|
||||
return;
|
||||
}
|
||||
if (showNotification) {
|
||||
showToast('Ошибка сохранения', 'error');
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user