fix: merge SuperAdmin settings over local can_edit locks
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -26,16 +26,16 @@ function parseSettingsPayload(data: unknown): SuperAdminSettingRow[] {
|
||||
return []
|
||||
}
|
||||
|
||||
/** کلید قفلشده در get_settings محلی — باید از سوپرادمین بیاید */
|
||||
export function isLockedCanEdit(canEdit: unknown): boolean {
|
||||
return canEdit === 0 || canEdit === false || canEdit === '0'
|
||||
}
|
||||
|
||||
/** تنظیمات پیشرفته نسخه از سوپرادمین — فقط GET /api/public/program-settings?domain= */
|
||||
export async function fetchSuperAdminProgramSettings(): Promise<SuperAdminSettingRow[]> {
|
||||
const domain = encodeURIComponent(resolveTenantDomain())
|
||||
try {
|
||||
const data = await fetchSuperAdminJson(
|
||||
(base) => `${base}${SA_PROGRAM_SETTINGS_PATH}?domain=${domain}`,
|
||||
)
|
||||
return parseSettingsPayload(data)
|
||||
} catch (error) {
|
||||
console.warn('SuperAdmin program-settings failed after retries:', error)
|
||||
return []
|
||||
}
|
||||
const data = await fetchSuperAdminJson(
|
||||
(base) => `${base}${SA_PROGRAM_SETTINGS_PATH}?domain=${domain}`,
|
||||
)
|
||||
return parseSettingsPayload(data)
|
||||
}
|
||||
|
||||
+13
-16
@@ -1,7 +1,7 @@
|
||||
import { computed, ref } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import { getSettings } from '@/api/configuration'
|
||||
import { fetchSuperAdminProgramSettings } from '@/api/superadminSettings'
|
||||
import { fetchSuperAdminProgramSettings, isLockedCanEdit } from '@/api/superadminSettings'
|
||||
import { resolveMeltedGoldLabel, resolveMetalTypeLabel } from '@/utils/metalLabels'
|
||||
import { resolveTradeWeightUnit } from '@/utils/weightUnit'
|
||||
|
||||
@@ -13,6 +13,7 @@ export interface AppSetting {
|
||||
description?: string
|
||||
is_active?: boolean
|
||||
type?: string
|
||||
can_edit?: number | boolean | string
|
||||
}
|
||||
|
||||
export const useSettingsStore = defineStore('settings', () => {
|
||||
@@ -66,23 +67,19 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
|
||||
fetchPromise = (async () => {
|
||||
try {
|
||||
const [local, remote] = await Promise.all([
|
||||
getSettings().catch(() => []),
|
||||
fetchSuperAdminProgramSettings(),
|
||||
])
|
||||
if (Array.isArray(local)) {
|
||||
mergeSettings(local)
|
||||
}
|
||||
if (remote.length) {
|
||||
mergeSettings(remote as AppSetting[])
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
} finally {
|
||||
const localRaw = await getSettings().catch(() => [])
|
||||
const remote = await fetchSuperAdminProgramSettings()
|
||||
const local = Array.isArray(localRaw) ? localRaw : []
|
||||
const editable = local.filter((row) => !isLockedCanEdit(row?.can_edit))
|
||||
settings.value = []
|
||||
mergeSettings(remote as AppSetting[])
|
||||
mergeSettings(editable)
|
||||
loaded.value = true
|
||||
return settings.value
|
||||
} catch (error) {
|
||||
fetchPromise = null
|
||||
throw error
|
||||
}
|
||||
|
||||
return settings.value
|
||||
})()
|
||||
|
||||
return fetchPromise
|
||||
|
||||
Reference in New Issue
Block a user