Have getIdForCurrentUser method return null if FMCS enabled, user is not super admin, and does not have company

This commit is contained in:
Marcus Moore 2024-10-17 15:14:39 -07:00
parent 99dd51a965
commit 979e4502ff
No known key found for this signature in database
2 changed files with 5 additions and 3 deletions

View file

@ -116,7 +116,7 @@ final class Company extends SnipeModel
if ($current_user->company_id != null) { if ($current_user->company_id != null) {
return $current_user->company_id; return $current_user->company_id;
} else { } else {
return static::getIdFromInput($unescaped_input); return null;
} }
} }
} }

View file

@ -4,8 +4,10 @@ namespace Tests\Unit\Models\Company;
use App\Models\Company; use App\Models\Company;
use App\Models\User; use App\Models\User;
use PHPUnit\Framework\Attributes\Group;
use Tests\TestCase; use Tests\TestCase;
#[Group('focus')]
class GetIdForCurrentUserTest extends TestCase class GetIdForCurrentUserTest extends TestCase
{ {
public function testReturnsProvidedValueWhenFullCompanySupportDisabled() public function testReturnsProvidedValueWhenFullCompanySupportDisabled()
@ -32,11 +34,11 @@ class GetIdForCurrentUserTest extends TestCase
$this->assertEquals(2000, Company::getIdForCurrentUser(1000)); $this->assertEquals(2000, Company::getIdForCurrentUser(1000));
} }
public function testReturnsProvidedValueForNonSuperUserWithoutCompanyIdWhenFullCompanySupportEnabled() public function testReturnsNullForNonSuperUserWithoutCompanyIdWhenFullCompanySupportEnabled()
{ {
$this->settings->enableMultipleFullCompanySupport(); $this->settings->enableMultipleFullCompanySupport();
$this->actingAs(User::factory()->create(['company_id' => null])); $this->actingAs(User::factory()->create(['company_id' => null]));
$this->assertEquals(1000, Company::getIdForCurrentUser(1000)); $this->assertNull(Company::getIdForCurrentUser(1000));
} }
} }