fix(settings): list full can_edit=0 catalog on superadmin get

Merge tenant values with the deploy template catalog so every system
setting (e.g. all montzar_* can_edit=0 keys) appears like khaneghi
advanced settings, not only rows already stored for the tenant.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-19 18:57:39 +03:30
co-authored by Cursor
parent e287f8a54f
commit aa44d244d2
@@ -605,14 +605,48 @@ export class ProgramSettingsService implements OnModuleInit {
}
private async listTenantRows(tenantId: string): Promise<ProgramSettingRow[]> {
const rows = await this.prisma.setting.findMany({
where: { tenantId, deletedAt: null },
orderBy: { key: 'asc' },
await this.ensureTemplatesSeeded();
const catalogKeys = [...DEPLOY_SETTING_CATALOG_KEYS].sort();
const [tenantRows, templates] = await Promise.all([
this.prisma.setting.findMany({
where: { tenantId, deletedAt: null, key: { in: catalogKeys } },
}),
this.prisma.settingTemplate.findMany({
where: { deletedAt: null, key: { in: catalogKeys } },
}),
]);
const tenantByKey = new Map(tenantRows.map((row: Setting) => [row.key, row]));
const templateByKey = new Map(templates.map((row: SettingTemplate) => [row.key, row]));
const seedByKey = new Map(
this.readSeedRows()
.filter((row) => row.key && DEPLOY_SETTING_CATALOG_KEYS.has(String(row.key)))
.map((row) => [String(row.key), row]),
);
return catalogKeys
.filter((key) => !isRuntimeProgramSettingKey(key))
.map((key) => {
const tenant = tenantByKey.get(key);
if (tenant) return this.toApiRow(tenant);
const tpl = templateByKey.get(key);
if (tpl) return this.toApiRow(tpl);
const seed = seedByKey.get(key);
return {
key,
value: seed?.value == null ? '' : String(seed.value),
title_fa: seed?.title_fa || key,
description: seed?.description || '',
type: seed?.type || '',
type_data: '',
is_active: seed?.is_active ?? 1,
can_edit: 0,
is_exist: 0,
};
});
return rows
.filter((row: Setting) => !isRuntimeProgramSettingKey(row.key))
.filter((row: Setting) => this.isSystemProgramSettingKey(row.key))
.map((row: Setting) => this.toApiRow(row));
}
private toApiRow(row: Setting | SettingTemplate): ProgramSettingRow {