fix(settings): keep local can_edit=0 keys in get_settings when SA omits them
Customer /api/get_settings dropped price_provider because SuperAdmin catalog did not return it. Merge SA values when present; otherwise keep the tenant copy so the app still receives the key. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -162,7 +162,7 @@ class SettingsController extends Controller
|
|||||||
private function composeSystemSettings($localRows)
|
private function composeSystemSettings($localRows)
|
||||||
{
|
{
|
||||||
$overlay = app(SuperAdminProgramSettingsOverlay::class);
|
$overlay = app(SuperAdminProgramSettingsOverlay::class);
|
||||||
$saMap = $overlay->map();
|
$saMap = $overlay->catalogMap();
|
||||||
|
|
||||||
$byKey = [];
|
$byKey = [];
|
||||||
|
|
||||||
@@ -177,7 +177,25 @@ class SettingsController extends Controller
|
|||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$byKey[(string) $key] = $this->overlayRowToSetting($item);
|
$value = $item['value'] ?? null;
|
||||||
|
if ($value !== null && $value !== '') {
|
||||||
|
$byKey[(string) $key] = $this->overlayRowToSetting($item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($localRows as $row) {
|
||||||
|
$key = (string) $row->key;
|
||||||
|
if (isset($byKey[$key])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
SuperAdminProgramSettingsOverlay::isRuntime($key)
|
||||||
|
|| SuperAdminProgramSettingsOverlay::isLocalOwned($key)
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (! $this->isEditableCanEdit($row->can_edit ?? null)) {
|
||||||
|
$byKey[$key] = $row;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foreach ($localRows as $row) {
|
foreach ($localRows as $row) {
|
||||||
@@ -219,14 +237,15 @@ class SettingsController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get_settings: کلیدهای سوپرادمین (can_edit=0) + ردیفهای جدول لوکال با can_edit=1.
|
* get_settings اپ/ادمین:
|
||||||
|
* can_edit=1 (+ runtime) از DB لوکال
|
||||||
|
* can_edit=0 از سوپرادمین؛ اگر کلید در SA نبود یا value خالی بود → کپی لوکال
|
||||||
* اگر سوپرادمین در دسترس نباشد کل جدول لوکال برمیگردد.
|
* اگر سوپرادمین در دسترس نباشد کل جدول لوکال برمیگردد.
|
||||||
* کلیدهای runtime / متعلق به پنل خانگی همیشه از جدول لوکال میآیند.
|
|
||||||
*/
|
*/
|
||||||
private function composeGetSettings($localRows)
|
private function composeGetSettings($localRows)
|
||||||
{
|
{
|
||||||
$overlay = app(SuperAdminProgramSettingsOverlay::class);
|
$overlay = app(SuperAdminProgramSettingsOverlay::class);
|
||||||
$saMap = $overlay->map();
|
$saMap = $overlay->catalogMap();
|
||||||
if ($saMap === null) {
|
if ($saMap === null) {
|
||||||
return $localRows;
|
return $localRows;
|
||||||
}
|
}
|
||||||
@@ -234,8 +253,13 @@ class SettingsController extends Controller
|
|||||||
$byKey = [];
|
$byKey = [];
|
||||||
|
|
||||||
foreach ($localRows as $row) {
|
foreach ($localRows as $row) {
|
||||||
if ($this->isEditableCanEdit($row->can_edit ?? null)) {
|
$key = (string) $row->key;
|
||||||
$byKey[(string) $row->key] = $this->normalizeTenantOwnedRow($row);
|
if (
|
||||||
|
$this->isEditableCanEdit($row->can_edit ?? null)
|
||||||
|
|| SuperAdminProgramSettingsOverlay::isRuntime($key)
|
||||||
|
|| SuperAdminProgramSettingsOverlay::isLocalOwned($key)
|
||||||
|
) {
|
||||||
|
$byKey[$key] = $this->normalizeTenantOwnedRow($row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,22 +267,34 @@ class SettingsController extends Controller
|
|||||||
if (! is_array($item)) {
|
if (! is_array($item)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
$key = (string) $key;
|
||||||
if (
|
if (
|
||||||
SuperAdminProgramSettingsOverlay::isRuntime((string) $key)
|
SuperAdminProgramSettingsOverlay::isRuntime($key)
|
||||||
|| SuperAdminProgramSettingsOverlay::isLocalOwned((string) $key)
|
|| SuperAdminProgramSettingsOverlay::isLocalOwned($key)
|
||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$byKey[(string) $key] = $this->overlayRowToSetting($item);
|
$value = $item['value'] ?? null;
|
||||||
|
if ($value !== null && $value !== '') {
|
||||||
|
$byKey[$key] = $this->overlayRowToSetting($item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($localRows as $row) {
|
foreach ($localRows as $row) {
|
||||||
$key = (string) $row->key;
|
$key = (string) $row->key;
|
||||||
|
if (isset($byKey[$key])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
SuperAdminProgramSettingsOverlay::isLocalOwned($key)
|
SuperAdminProgramSettingsOverlay::isRuntime($key)
|
||||||
|| SuperAdminProgramSettingsOverlay::isRuntime($key)
|
|| SuperAdminProgramSettingsOverlay::isLocalOwned($key)
|
||||||
) {
|
) {
|
||||||
$byKey[$key] = $this->normalizeTenantOwnedRow($row);
|
$byKey[$key] = $this->normalizeTenantOwnedRow($row);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (! $this->isEditableCanEdit($row->can_edit ?? null)) {
|
||||||
|
$byKey[$key] = $row;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* تنظیمات پیشرفته سوپرادمین برای ConfigService.
|
* تنظیمات پیشرفته سوپرادمین برای ConfigService و get_settings.
|
||||||
* کش پایدار ندارد؛ فقط یک بار در همان درخواست PHP نگه داشته میشود.
|
* کش پایدار ندارد؛ فقط یک بار در همان درخواست PHP نگه داشته میشود.
|
||||||
*/
|
*/
|
||||||
class SuperAdminProgramSettingsOverlay
|
class SuperAdminProgramSettingsOverlay
|
||||||
@@ -36,9 +36,43 @@ class SuperAdminProgramSettingsOverlay
|
|||||||
private static bool $loaded = false;
|
private static bool $loaded = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<string, array<string, mixed>>|null null = سوپرادمین در دسترس نبود
|
* همهٔ کلیدهای سوپرادمین (حتی value خالی). null = سوپرادمین در دسترس نبود.
|
||||||
|
*
|
||||||
|
* @return array<string, array<string, mixed>>|null
|
||||||
|
*/
|
||||||
|
public function catalogMap(): ?array
|
||||||
|
{
|
||||||
|
return $this->load();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* فقط کلیدهایی که سوپرادمین مقدار غیرخالی دارد — برای ConfigService.
|
||||||
|
*
|
||||||
|
* @return array<string, array<string, mixed>>|null
|
||||||
*/
|
*/
|
||||||
public function map(): ?array
|
public function map(): ?array
|
||||||
|
{
|
||||||
|
$full = $this->load();
|
||||||
|
if ($full === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$withValue = [];
|
||||||
|
foreach ($full as $key => $row) {
|
||||||
|
$value = is_array($row) ? ($row['value'] ?? null) : null;
|
||||||
|
if ($value === null || $value === '') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$withValue[$key] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $withValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, array<string, mixed>>|null
|
||||||
|
*/
|
||||||
|
private function load(): ?array
|
||||||
{
|
{
|
||||||
if (self::$loaded) {
|
if (self::$loaded) {
|
||||||
return self::$memo;
|
return self::$memo;
|
||||||
@@ -62,11 +96,6 @@ class SuperAdminProgramSettingsOverlay
|
|||||||
if ($key === '' || in_array($key, self::LOCAL_OWNED_KEYS, true) || in_array($key, self::RUNTIME_KEYS, true)) {
|
if ($key === '' || in_array($key, self::LOCAL_OWNED_KEYS, true) || in_array($key, self::RUNTIME_KEYS, true)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// مقدار خالی قالب سوپرادمین نباید value لوکال tenant را پاک کند
|
|
||||||
$value = $row['value'] ?? null;
|
|
||||||
if ($value === null || $value === '') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$map[$key] = $row;
|
$map[$key] = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user