Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
fix(frontend): resolve latest value for high-risk settings
wizardchenbf53cacf75ae
diff --git a/frontend/src/views/system/SystemSettings.vue b/frontend/src/views/system/SystemSettings.vueindex df2c5741f..ad56acdcd 100644--- a/frontend/src/views/system/SystemSettings.vue+++ b/frontend/src/views/system/SystemSettings.vue@@ -496,6 +496,7 @@ import {type SystemSettingItem,} from '@/api/system'import { useAuthStore } from '@/stores/auth'+import { isSettingValueDirty, resolveCurrentSetting } from './systemSettingsEdit'const authStore = useAuthStore()const currentUserId = computed(() => authStore.currentUserId)@@ -866,16 +867,7 @@ async function snapSsrfWhitelistToSaved(item: SystemSettingItem) {}function isDirty(item: SystemSettingItem): boolean {- const cur = editValues[item.key]- const orig = item.value- if (Array.isArray(cur) && Array.isArray(orig)) {- if (cur.length !== orig.length) return true- for (let i = 0; i < cur.length; i++) {- if (cur[i] !== orig[i]) return true- }- return false- }- return cur !== orig+ return isSettingValueDirty(editValues[item.key], item.value)}function formatDate(isoString: string): string {@@ -929,7 +921,7 @@ async function loadSettings() {// onChange persists non-SSRF settings. SSRF whitelist and system admins// have dedicated handlers with inline popconfirm.async function onChange(item: SystemSettingItem) {- const currentItem = settingsByKey.value.get(item.key)+ const currentItem = resolveCurrentSetting(settingsByKey.value, item.key)if (!currentItem) returnif (!isDirty(currentItem)) return@@ -943,15 +935,17 @@ async function onChange(item: SystemSettingItem) {}async function onHighRiskSelectChange(item: SystemSettingItem) {+ const currentItem = resolveCurrentSetting(settingsByKey.value, item.key)+ if (!currentItem) returnconst newValue = editValues[item.key]- if (newValue === item.value) return+ if (!isDirty(currentItem)) return// Revert the select immediately so cancel leaves the saved value// visible; re-apply only after the inline popconfirm is confirmed.- editValues[item.key] = item.value+ editValues[item.key] = currentItem.valueconst ok = await highRiskPopconfirm.ask({- content: highRiskConfirmBody(item, newValue),+ content: highRiskConfirmBody(currentItem, newValue),theme: 'danger',confirmBtn: {content: t('system.globalSettings.confirm.confirmBtn'),@@ -961,7 +955,7 @@ async function onHighRiskSelectChange(item: SystemSettingItem) {if (!ok) returneditValues[item.key] = newValue- await persistSetting(item)+ await persistSetting(currentItem)}function confirmSsrfListEntryChange(diff --git a/frontend/src/views/system/systemSettingsEdit.test.ts b/frontend/src/views/system/systemSettingsEdit.test.tsnew file mode 100644index 000000000..daaa9a272--- /dev/null+++ b/frontend/src/views/system/systemSettingsEdit.test.ts@@ -0,0 +1,41 @@+import assert from 'node:assert/strict'+import test from 'node:test'++import { isSettingValueDirty, resolveCurrentSetting } from './systemSettingsEdit.ts'++test('treats scalar edits as dirty', () => {+ assert.equal(isSettingValueDirty(true, false), true)+ assert.equal(isSettingValueDirty(false, false), false)+ assert.equal(isSettingValueDirty('invite', 'open'), true)+})++test('treats list edits as dirty by value, not by reference', () => {+ assert.equal(isSettingValueDirty(['a'], ['a']), false)+ assert.equal(isSettingValueDirty(['a', 'b'], ['a']), true)+ assert.equal(isSettingValueDirty(['a'], ['b']), true)+})++test('resolves the latest setting so a reused row does not keep the pre-save value', () => {+ const stale = { key: 'tenant.auto_create_api_key', value: false }+ const current = { key: 'tenant.auto_create_api_key', value: true }+ const settingsByKey = new Map([[current.key, current]])++ const resolved = resolveCurrentSetting(settingsByKey, stale.key)+ assert.equal(resolved, current)++ // User toggled back to the original loaded value. The stale object looks+ // clean; the canonical post-save object is dirty and must PUT.+ const editValue = false+ assert.equal(isSettingValueDirty(editValue, stale.value), false)+ assert.equal(isSettingValueDirty(editValue, resolved?.value), true)+})++test('high-risk cancel restores the latest saved value, not the first-loaded object', () => {+ const stale = { key: 'auth.registration_mode', value: 'open' }+ const current = { key: 'auth.registration_mode', value: 'invite' }+ const settingsByKey = new Map([[current.key, current]])++ const resolved = resolveCurrentSetting(settingsByKey, stale.key)+ assert.equal(resolved?.value, 'invite')+ assert.notEqual(stale.value, resolved?.value)+})diff --git a/frontend/src/views/system/systemSettingsEdit.ts b/frontend/src/views/system/systemSettingsEdit.tsnew file mode 100644index 000000000..9eba41581--- /dev/null+++ b/frontend/src/views/system/systemSettingsEdit.ts@@ -0,0 +1,23 @@+// Setting rows keep a stable Vue key (`item.key`) while persistSetting+// replaces the object in `settings`. Reused TDesign controls can therefore+// fire @change/@blur with a stale item whose `.value` is the pre-save+// snapshot. Event handlers must resolve by key from the latest map before+// dirty-checking or reverting the control.++export function resolveCurrentSetting<T extends { key: string }>(+ settingsByKey: ReadonlyMap<string, T>,+ key: string,+): T | undefined {+ return settingsByKey.get(key)+}++export function isSettingValueDirty(current: unknown, original: unknown): boolean {+ if (Array.isArray(current) && Array.isArray(original)) {+ if (current.length !== original.length) return true+ for (let i = 0; i < current.length; i++) {+ if (current[i] !== original[i]) return true+ }+ return false+ }+ return current !== original+}