Merge remote-tracking branch 'origin/develop'
This commit is contained in:
commit
b25612bbac
4 changed files with 55 additions and 2 deletions
|
@ -640,7 +640,7 @@ class SettingsController extends Controller
|
||||||
$audit_diff_months = ((int)$request->input('audit_interval') - (int)($setting->audit_interval));
|
$audit_diff_months = ((int)$request->input('audit_interval') - (int)($setting->audit_interval));
|
||||||
|
|
||||||
// Grab all assets that have an existing next_audit_date, chunking to handle very large datasets
|
// Grab all assets that have an existing next_audit_date, chunking to handle very large datasets
|
||||||
Asset::whereNotNull('next_audit_date')->chunk(20, function ($assets) use ($audit_diff_months) {
|
Asset::whereNotNull('next_audit_date')->chunk(200, function ($assets) use ($audit_diff_months) {
|
||||||
|
|
||||||
// Update assets' next_audit_date values
|
// Update assets' next_audit_date values
|
||||||
foreach ($assets as $asset) {
|
foreach ($assets as $asset) {
|
||||||
|
|
|
@ -113,6 +113,14 @@ final class Company extends SnipeModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the company id for the current user taking into
|
||||||
|
* account the full multiple company support setting
|
||||||
|
* and if the current user is a super user.
|
||||||
|
*
|
||||||
|
* @param $unescaped_input
|
||||||
|
* @return int|mixed|string|null
|
||||||
|
*/
|
||||||
public static function getIdForCurrentUser($unescaped_input)
|
public static function getIdForCurrentUser($unescaped_input)
|
||||||
{
|
{
|
||||||
if (! static::isFullMultipleCompanySupportEnabled()) {
|
if (! static::isFullMultipleCompanySupportEnabled()) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Tests\Unit;
|
namespace Tests\Unit\Models\Company;
|
||||||
|
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
45
tests/Unit/Models/Company/GetIdForCurrentUserTest.php
Normal file
45
tests/Unit/Models/Company/GetIdForCurrentUserTest.php
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit\Models\Company;
|
||||||
|
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Models\User;
|
||||||
|
use Tests\Support\InteractsWithSettings;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class GetIdForCurrentUserTest extends TestCase
|
||||||
|
{
|
||||||
|
use InteractsWithSettings;
|
||||||
|
|
||||||
|
public function testReturnsProvidedValueWhenFullCompanySupportDisabled()
|
||||||
|
{
|
||||||
|
$this->settings->disableMultipleFullCompanySupport();
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->create());
|
||||||
|
$this->assertEquals(1000, Company::getIdForCurrentUser(1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReturnsProvidedValueForSuperUsersWhenFullCompanySupportEnabled()
|
||||||
|
{
|
||||||
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->superuser()->create());
|
||||||
|
$this->assertEquals(2000, Company::getIdForCurrentUser(2000));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReturnsNonSuperUsersCompanyIdWhenFullCompanySupportEnabled()
|
||||||
|
{
|
||||||
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->forCompany(['id' => 2000])->create());
|
||||||
|
$this->assertEquals(2000, Company::getIdForCurrentUser(1000));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testReturnsProvidedValueForNonSuperUserWithoutCompanyIdWhenFullCompanySupportEnabled()
|
||||||
|
{
|
||||||
|
$this->settings->enableMultipleFullCompanySupport();
|
||||||
|
|
||||||
|
$this->actingAs(User::factory()->create(['company_id' => null]));
|
||||||
|
$this->assertEquals(1000, Company::getIdForCurrentUser(1000));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue