From 979e4502ffbadab5978d38633fe06aa96eed698a Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 17 Oct 2024 15:14:39 -0700 Subject: [PATCH] Have getIdForCurrentUser method return null if FMCS enabled, user is not super admin, and does not have company --- app/Models/Company.php | 2 +- tests/Unit/Models/Company/GetIdForCurrentUserTest.php | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Models/Company.php b/app/Models/Company.php index 171d559542..8886da77f6 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -116,7 +116,7 @@ final class Company extends SnipeModel if ($current_user->company_id != null) { return $current_user->company_id; } else { - return static::getIdFromInput($unescaped_input); + return null; } } } diff --git a/tests/Unit/Models/Company/GetIdForCurrentUserTest.php b/tests/Unit/Models/Company/GetIdForCurrentUserTest.php index 6d77c88731..f69230fad1 100644 --- a/tests/Unit/Models/Company/GetIdForCurrentUserTest.php +++ b/tests/Unit/Models/Company/GetIdForCurrentUserTest.php @@ -4,8 +4,10 @@ namespace Tests\Unit\Models\Company; use App\Models\Company; use App\Models\User; +use PHPUnit\Framework\Attributes\Group; use Tests\TestCase; +#[Group('focus')] class GetIdForCurrentUserTest extends TestCase { public function testReturnsProvidedValueWhenFullCompanySupportDisabled() @@ -32,11 +34,11 @@ class GetIdForCurrentUserTest extends TestCase $this->assertEquals(2000, Company::getIdForCurrentUser(1000)); } - public function testReturnsProvidedValueForNonSuperUserWithoutCompanyIdWhenFullCompanySupportEnabled() + public function testReturnsNullForNonSuperUserWithoutCompanyIdWhenFullCompanySupportEnabled() { $this->settings->enableMultipleFullCompanySupport(); $this->actingAs(User::factory()->create(['company_id' => null])); - $this->assertEquals(1000, Company::getIdForCurrentUser(1000)); + $this->assertNull(Company::getIdForCurrentUser(1000)); } }