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