fix: 已有账号自动显示费比监控入口 (#902)

This commit is contained in:
renshen 2026-11-05 19:38:43 +08:00
parent 3e202ca9bf
commit eaac7c68c4
2 changed files with 49 additions and 4 deletions

View File

@ -66,13 +66,17 @@ class SidebarPermissions
$settings = self::settings();
$userSubject = 'user_' . $user->id;
if (in_array($userSubject, $settings['configured'] ?? [], true)) {
return self::normalizeAllowedKeys((array) ($settings['subjects'][$userSubject] ?? []));
return self::withFinanceMonitoringAccess(
self::normalizeAllowedKeys((array) ($settings['subjects'][$userSubject] ?? [])),
);
}
$groups = UserAccessGroup::forUser($user);
if ($groups->isNotEmpty()) {
return self::normalizeAllowedKeys(
$groups->flatMap(fn ($group) => $group->page_permissions ?? [])->all()
return self::withFinanceMonitoringAccess(
self::normalizeAllowedKeys(
$groups->flatMap(fn ($group) => $group->page_permissions ?? [])->all()
),
);
}
@ -82,7 +86,19 @@ class SidebarPermissions
return null;
}
return self::normalizeAllowedKeys((array) ($settings['subjects'][$subject] ?? []));
return self::withFinanceMonitoringAccess(
self::normalizeAllowedKeys((array) ($settings['subjects'][$subject] ?? [])),
);
}
/** @param list<string> $allowed */
private static function withFinanceMonitoringAccess(array $allowed): array
{
if (! in_array('fee-ratio-monitoring/overview', $allowed, true)) {
$allowed[] = 'fee-ratio-monitoring/overview';
}
return $allowed;
}
public static function hasLimitedDingTalkAccess(User $user): bool

View File

@ -6,6 +6,7 @@ use App\Models\Auth\Permission;
use App\Models\Auth\Role;
use App\Utilities\BusinessNavigation;
use App\Utilities\SidebarMenu;
use App\Utilities\SidebarPermissions;
use Tests\Feature\FeatureTestCase;
class NavigationTest extends FeatureTestCase
@ -307,6 +308,34 @@ class NavigationTest extends FeatureTestCase
->assertSeeText('费比异常数据尚未接入');
}
public function testExistingRegularPermissionSetsInheritFeeRatioMonitoring(): void
{
$this->user->roles()->sync([Role::where('name', 'user')->firstOrFail()->id]);
$subject = 'role_user';
setting()->set('system.sidebar_permissions', [
'configured' => [$subject],
'subjects' => [$subject => [
'financial-risk-control/store-violation-alert',
'financial-risk-control/process-statistics',
]],
]);
setting()->save();
$this->assertContains(
'fee-ratio-monitoring/overview',
SidebarPermissions::allowedKeys($this->user),
);
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'financial-risk-control',
'page' => 'store-violation-alert',
]))
->assertOk()
->assertSee('/workspace/fee-ratio-monitoring/overview', false)
->assertSeeText('费比异常数据监控');
}
public function test_business_pages_render_menu_filter_and_open_page_tabs(): void
{
$this->loginAs()