Fix SuperAdmin access sync for tenant domains and persist flags locally.

Expand www/admin domain aliases when resolving program-settings, and save owned keys to local settings after a successful refresh so menu flags like customer_special_pricing stay applied.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-29 23:35:37 +03:30
co-authored by Cursor
parent 63195718a2
commit 9f6203075a
2 changed files with 74 additions and 6 deletions
@@ -2,6 +2,8 @@
namespace App\Services;
use App\Models\Setting;
/**
* تنظیمات پیشرفته سوپرادمین برای ConfigService و get_settings.
* هر درخواست HTTP یک بار از سوپرادمین می‌خواند (memo فقط داخل همان درخواست) — بدون کش Redis.
@@ -102,6 +104,9 @@ class SuperAdminProgramSettingsOverlay
$items[(string) $key] = (string) $value;
}
// در DB لوکال هم بنویس تا اگر درخواست بعدی به سوپرادمین نرسد، منو/فلگ‌ها از آخرین مقدار درست بمانند
$this->persistOwnedToLocal($map);
return [
'ok' => true,
'count' => count($items),
@@ -111,6 +116,39 @@ class SuperAdminProgramSettingsOverlay
];
}
/**
* آخرین مقادیر ۱۴ دسترسی را در settings لوکال ذخیره می‌کند (can_edit=0).
*
* @param array<string, array<string, mixed>> $map
*/
private function persistOwnedToLocal(array $map): void
{
foreach ($map as $key => $row) {
if (! is_array($row) || ! self::isSuperAdminOwned((string) $key)) {
continue;
}
$value = $row['value'] ?? null;
if ($value === null || $value === '') {
continue;
}
$setting = Setting::query()->firstOrNew(['key' => (string) $key]);
$setting->value = (string) $value;
$setting->can_edit = 0;
$setting->is_active = 1;
if (Setting::hasTypeColumn()) {
$setting->type = (string) ($row['type'] ?? $setting->type ?? 'switch');
}
if (! $setting->exists || trim((string) ($setting->title_fa ?? '')) === '') {
$setting->title_fa = (string) ($row['title_fa'] ?? $key);
}
if (array_key_exists('description', $row) && $row['description'] !== null && $row['description'] !== '') {
$setting->description = (string) $row['description'];
}
$setting->save();
}
}
/**
* همهٔ کلیدهای سوپرادمین (حتی value خالی). null = سوپرادمین در دسترس نبود.
*