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:
@@ -309,18 +309,48 @@ class SuperAdminProgramSettingsClient
|
||||
|
||||
$out = [];
|
||||
foreach ($candidates as $host) {
|
||||
if ($host === '' || in_array($host, $out, true)) {
|
||||
continue;
|
||||
foreach ($this->expandDomainAliases($host) as $alias) {
|
||||
if ($alias === '' || in_array($alias, $out, true)) {
|
||||
continue;
|
||||
}
|
||||
if (in_array($alias, ['localhost', '127.0.0.1', '::1'], true)) {
|
||||
continue;
|
||||
}
|
||||
$out[] = $alias;
|
||||
}
|
||||
if (in_array($host, ['localhost', '127.0.0.1', '::1'], true)) {
|
||||
continue;
|
||||
}
|
||||
$out[] = $host;
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* admin.example.com / www.example.com → example.com هم امتحان شود.
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
private function expandDomainAliases(string $host): array
|
||||
{
|
||||
$host = $this->normalizeHost($host);
|
||||
if ($host === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
$aliases = [$host];
|
||||
foreach (['www.', 'admin.', 'panel.', 'app.'] as $prefix) {
|
||||
if (str_starts_with($host, $prefix)) {
|
||||
$bare = substr($host, strlen($prefix));
|
||||
if ($bare !== '') {
|
||||
$aliases[] = $bare;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (! str_starts_with($host, 'www.')) {
|
||||
$aliases[] = 'www.'.$host;
|
||||
}
|
||||
|
||||
return array_values(array_unique($aliases));
|
||||
}
|
||||
|
||||
private function normalizeHost(string $value): string
|
||||
{
|
||||
$host = strtolower(trim($value));
|
||||
|
||||
@@ -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 = سوپرادمین در دسترس نبود.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user