diff --git a/app/Utilities/SidebarPermissions.php b/app/Utilities/SidebarPermissions.php index 2841973f..411a3065 100644 --- a/app/Utilities/SidebarPermissions.php +++ b/app/Utilities/SidebarPermissions.php @@ -338,14 +338,7 @@ class SidebarPermissions return true; } - if (in_array(trim((string) $user->name), $allowedViewers, true)) { - return true; - } - - $dingTalkUserId = trim((string) ($user->dingtalkIdentity?->dingtalk_user_id ?? '')); - - return $dingTalkUserId !== '' - && in_array('dingtalk:' . $dingTalkUserId, $allowedViewers, true); + return in_array(trim((string) $user->name), $allowedViewers, true); } private static function applyPageViewerAllowlists(array $navigation, User $user): array diff --git a/config/business_page_access.php b/config/business_page_access.php index 05073dcf..45d6a5cf 100644 --- a/config/business_page_access.php +++ b/config/business_page_access.php @@ -11,10 +11,6 @@ return [ | */ 'page_viewers' => [ - 'other/log-statistics' => [ - // 人参 / 张宏:按钉钉用户 ID 锁定,避免同名或显示名称变更导致误锁。 - 'dingtalk:1004216768778351', - ], 'financial-operations/labor-expenses' => [ '晨曦', 'Chenxi', diff --git a/tests/Feature/Business/LogStatisticsPageAccessTest.php b/tests/Feature/Business/LogStatisticsPageAccessTest.php index 02b72b65..1088aaff 100644 --- a/tests/Feature/Business/LogStatisticsPageAccessTest.php +++ b/tests/Feature/Business/LogStatisticsPageAccessTest.php @@ -2,7 +2,6 @@ namespace Tests\Feature\Business; -use App\Models\Auth\DingTalkIdentity; use App\Models\Auth\Permission; use App\Models\Auth\Role; use App\Models\Auth\User; @@ -11,42 +10,41 @@ use Tests\Feature\FeatureTestCase; class LogStatisticsPageAccessTest extends FeatureTestCase { - public function test_log_statistics_is_locked_to_renshen_even_for_explicit_grants_and_admins(): void + public function test_log_statistics_is_visible_to_any_user_with_normal_page_permission(): void { - $renshen = $this->account('人参', '1004216768778351'); - $sameName = $this->account('人参'); - $other = $this->account('其他财务'); - $subject = 'user_' . $other->id; + $viewer = $this->account('普通财务'); + $denied = $this->account('未授权账号'); + $subject = 'user_' . $viewer->id; + $deniedSubject = 'user_' . $denied->id; setting()->set('system.sidebar_permissions', [ - 'configured' => [$subject], - 'subjects' => [$subject => ['other/log-statistics']], + 'configured' => [$subject, $deniedSubject], + 'subjects' => [ + $subject => ['other/log-statistics'], + $deniedSubject => [], + ], ]); - $this->assertTrue(SidebarPermissions::canViewPage($renshen, 'other', 'log-statistics')); - $this->assertFalse(SidebarPermissions::canViewPage($sameName, 'other', 'log-statistics')); - $this->assertFalse(SidebarPermissions::canViewPage($other, 'other', 'log-statistics')); - $this->assertFalse(SidebarPermissions::canViewPage($this->user, 'other', 'log-statistics')); + $this->assertTrue(SidebarPermissions::canViewPage($viewer, 'other', 'log-statistics')); + $otherSection = collect(SidebarPermissions::navigationFor($viewer)) + ->firstWhere('slug', 'other'); + $this->assertTrue(collect($otherSection['pages'] ?? [])->contains('slug', 'log-statistics')); - $this->loginAs($renshen) + $this->loginAs($viewer) ->get(route('business.pages.show', [ 'section' => 'other', 'page' => 'log-statistics', ])) ->assertOk(); - $this->withExceptionHandling()->loginAs($other) + $this->withExceptionHandling()->loginAs($denied) ->get(route('business.pages.show', [ 'section' => 'other', 'page' => 'log-statistics', ])) ->assertForbidden(); - $this->post(route('business.pages.store', [ - 'section' => 'other', - 'page' => 'log-statistics', - ]), [])->assertForbidden(); } - private function account(string $name, ?string $dingTalkUserId = null): User + private function account(string $name): User { $suffix = User::count(); $user = User::create([ @@ -60,15 +58,6 @@ class LogStatisticsPageAccessTest extends FeatureTestCase $user->roles()->attach(Role::where('name', 'user')->firstOrFail()->id); $user->permissions()->attach(Permission::where('name', 'read-admin-panel')->firstOrFail()->id); $user->companies()->attach($this->company->id); - if ($dingTalkUserId !== null) { - DingTalkIdentity::create([ - 'user_id' => $user->id, - 'union_id' => 'union-log-statistics-' . $user->id, - 'dingtalk_user_id' => $dingTalkUserId, - 'nickname' => $name, - 'bound_at' => now(), - ]); - } return $user; } diff --git a/tests/Feature/Business/PagesTest.php b/tests/Feature/Business/PagesTest.php index 64f3e663..9d6b2821 100644 --- a/tests/Feature/Business/PagesTest.php +++ b/tests/Feature/Business/PagesTest.php @@ -2,7 +2,6 @@ namespace Tests\Feature\Business; -use App\Models\Auth\DingTalkIdentity; use App\Models\Auth\Permission; use App\Models\Auth\Role; use App\Models\Auth\User; @@ -91,7 +90,7 @@ class PagesTest extends FeatureTestCase public function testLogStatisticsPageIsAvailableUnderOther(): void { Carbon::setTestNow(Carbon::parse('2026-11-04 10:26:00', 'Asia/Shanghai')); - $renshen = $this->account('人参', '1004216768778351'); + $renshen = $this->account('人参'); $repository = Mockery::mock(DingWorklogMirrorRepository::class); $repository->shouldReceive('available')->andReturnTrue(); @@ -199,7 +198,7 @@ class PagesTest extends FeatureTestCase public function testLogStatisticsPageHidesTheEmptyPenaltyPanel(): void { Carbon::setTestNow(Carbon::parse('2026-11-05 15:00:00', 'Asia/Shanghai')); - $renshen = $this->account('人参', '1004216768778351'); + $renshen = $this->account('人参'); $repository = Mockery::mock(DingWorklogMirrorRepository::class); $repository->shouldReceive('available')->andReturnTrue(); @@ -1775,7 +1774,7 @@ class PagesTest extends FeatureTestCase ->assertSee('data-directory-fixed="end"', false); } - private function account(string $name, ?string $dingTalkUserId = null): User + private function account(string $name): User { $suffix = User::count(); $user = User::create([ @@ -1789,15 +1788,6 @@ class PagesTest extends FeatureTestCase $user->roles()->attach(Role::where('name', 'user')->firstOrFail()->id); $user->permissions()->attach(Permission::where('name', 'read-admin-panel')->firstOrFail()->id); $user->companies()->attach($this->company->id); - if ($dingTalkUserId !== null) { - DingTalkIdentity::create([ - 'user_id' => $user->id, - 'union_id' => 'union-pages-' . $user->id, - 'dingtalk_user_id' => $dingTalkUserId, - 'nickname' => $name, - 'bound_at' => now(), - ]); - } return $user; }