fix(settings): honor last-price switch and overlay only SuperAdmin access flags

Stored DB prices were treated as live quotes, and SuperAdmin overlay overwrote tenant keys like trading hours. Keep overlay to the 14 access flags and hide fallback prices when the panel says so.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-25 03:01:07 +03:30
co-authored by Cursor
parent 8984899042
commit b21b136711
9 changed files with 327 additions and 97 deletions
@@ -0,0 +1,79 @@
<?php
namespace Tests\Unit;
use App\Services\ConfigService;
use App\Services\SuperAdminProgramSettingsOverlay;
use PHPUnit\Framework\TestCase;
class SuperAdminProgramSettingsOverlayTest extends TestCase
{
public function test_owned_keys_match_the_access_flag_list(): void
{
$expected = [
'customer_direct_sms',
'customer_special_pricing',
'enable_automation',
'enable_conditional_order',
'enable_customer_level_profit',
'enable_product_funds',
'group_sms',
'has_page_earn_money',
'has_page_gift_card',
'has_page_notification',
'has_page_price_trigger',
'jibit_enabled',
'permision__enabled',
'show_to_users_chat',
];
$this->assertSame($expected, SuperAdminProgramSettingsOverlay::SUPERADMIN_OWNED_KEYS);
$this->assertCount(14, SuperAdminProgramSettingsOverlay::SUPERADMIN_OWNED_KEYS);
}
public function test_overlay_keeps_only_access_keys(): void
{
$map = SuperAdminProgramSettingsOverlay::ownedItemsMap([
['key' => 'enable_automation', 'value' => 'true'],
['key' => 'jibit_enabled', 'value' => 'false'],
['key' => 'price_provider', 'value' => 'zaarbox'],
['key' => 'show_last_price', 'value' => 'false'],
['key' => 'close_price', 'value' => 'true'],
['key' => 'startDay', 'value' => '11:00'],
['key' => 'endDay', 'value' => '20:30'],
['key' => 'name_fa', 'value' => 'طلا'],
['key' => 'montzar_live_price', 'value' => '168000000'],
['key' => 'tracking_systems', 'value' => '[]'],
['key' => '', 'value' => 'x'],
'not-an-array',
]);
$this->assertSame(['enable_automation', 'jibit_enabled'], array_keys($map));
$this->assertSame('true', $map['enable_automation']['value']);
$this->assertArrayNotHasKey('price_provider', $map);
$this->assertArrayNotHasKey('show_last_price', $map);
}
public function test_tenant_keys_are_never_superadmin_owned(): void
{
$tenantKeys = array_merge(
ConfigService::TRADING_HOURS_CLIENT_KEYS,
SuperAdminProgramSettingsOverlay::RUNTIME_KEYS,
SuperAdminProgramSettingsOverlay::LOCAL_OWNED_KEYS,
[
'price_provider',
'zaarbox_price_key',
'montzar_base_url',
'name_fa',
'name_en',
]
);
foreach ($tenantKeys as $key) {
$this->assertFalse(
SuperAdminProgramSettingsOverlay::isSuperAdminOwned($key),
"{$key} نباید از سوپرادمین خوانده شود"
);
}
}
}