From 0fa8b59a550f963c66301908a35cf22ac36a714f Mon Sep 17 00:00:00 2001 From: renshen <1005457301@qq.com> Date: Wed, 16 Sep 2026 13:13:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BB=88=E7=89=88=E5=BA=94?= =?UTF-8?q?=E4=BB=98=E6=AC=BE=E9=A1=B9=E6=9D=83=E9=99=90=E8=81=94=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Utilities/SidebarPermissions.php | 14 +++++- .../SystemSettings/UserPermissionsTest.php | 46 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/app/Utilities/SidebarPermissions.php b/app/Utilities/SidebarPermissions.php index 6c1e2c40..9c9a0eb2 100644 --- a/app/Utilities/SidebarPermissions.php +++ b/app/Utilities/SidebarPermissions.php @@ -11,6 +11,11 @@ class SidebarPermissions 'refunds/small-payment-work-orders' => 'financial-operations/small-payment-work-orders', ]; + private const FINAL_SECTION_KEYS = [ + 'supplier-payables' => 'supplier-payables-final', + 'courier-payables' => 'courier-payables-final', + ]; + public static function settings(): array { $value = setting('system.sidebar_permissions', []); @@ -140,7 +145,14 @@ class SidebarPermissions foreach ($keys as $key) { $key = (string) $key; - $normalized[] = self::LEGACY_PAGE_KEYS[$key] ?? $key; + $normalizedKey = self::LEGACY_PAGE_KEYS[$key] ?? $key; + $normalized[] = $normalizedKey; + + foreach (self::FINAL_SECTION_KEYS as $sectionKey => $finalSectionKey) { + if ($normalizedKey === $sectionKey || str_starts_with($normalizedKey, $sectionKey . '/')) { + $normalized[] = $finalSectionKey; + } + } if ($key === 'refunds') { $normalized[] = self::LEGACY_PAGE_KEYS['refunds/small-payment-work-orders']; diff --git a/tests/Feature/SystemSettings/UserPermissionsTest.php b/tests/Feature/SystemSettings/UserPermissionsTest.php index 0873e4ab..af9e7287 100644 --- a/tests/Feature/SystemSettings/UserPermissionsTest.php +++ b/tests/Feature/SystemSettings/UserPermissionsTest.php @@ -175,6 +175,52 @@ class UserPermissionsTest extends FeatureTestCase ); } + public function test_payables_final_entries_follow_their_base_section_permissions(): void + { + $regular = $this->account('user'); + $subject = 'user_' . $regular->id; + setting()->set('system.sidebar_permissions', [ + 'configured' => [$subject], + 'subjects' => [$subject => ['supplier-payables', 'courier-payables']], + ]); + + $this->assertEqualsCanonicalizing( + ['supplier-payables', 'supplier-payables-final', 'courier-payables', 'courier-payables-final'], + SidebarPermissions::allowedKeys($regular) + ); + + $navigation = SidebarPermissions::navigationFor($regular); + $this->assertSame( + ['supplier-payables-final', 'courier-payables-final', 'supplier-payables', 'courier-payables'], + array_column($navigation, 'slug') + ); + } + + public function test_payables_final_entry_follows_a_selected_child_permission(): void + { + $regular = $this->account('user'); + $subject = 'user_' . $regular->id; + setting()->set('system.sidebar_permissions', [ + 'configured' => [$subject], + 'subjects' => [$subject => ['supplier-payables/product-prices']], + ]); + + $this->assertSame( + ['supplier-payables/product-prices', 'supplier-payables-final'], + SidebarPermissions::allowedKeys($regular) + ); + + $navigation = SidebarPermissions::navigationFor($regular); + $this->assertSame( + ['supplier-payables-final', 'supplier-payables'], + array_column($navigation, 'slug') + ); + $this->assertSame( + ['product-prices'], + array_column($navigation[1]['pages'], 'slug') + ); + } + public function test_dingtalk_bound_user_cannot_be_deleted_into_an_orphaned_identity(): void { $target = $this->account('user'); -- 2.47.2