mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-11 08:04:09 -08:00
Merge remote-tracking branch 'origin/develop'
This commit is contained in:
commit
309c0ff66f
|
@ -286,9 +286,11 @@ class UsersController extends Controller
|
||||||
$users = Company::scopeCompanyables($users);
|
$users = Company::scopeCompanyables($users);
|
||||||
|
|
||||||
if ($request->filled('search')) {
|
if ($request->filled('search')) {
|
||||||
$users = $users->SimpleNameSearch($request->get('search'))
|
$users = $users->where(function ($query) use ($request) {
|
||||||
|
$query->SimpleNameSearch($request->get('search'))
|
||||||
->orWhere('username', 'LIKE', '%'.$request->get('search').'%')
|
->orWhere('username', 'LIKE', '%'.$request->get('search').'%')
|
||||||
->orWhere('employee_num', 'LIKE', '%'.$request->get('search').'%');
|
->orWhere('employee_num', 'LIKE', '%'.$request->get('search').'%');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$users = $users->orderBy('last_name', 'asc')->orderBy('first_name', 'asc');
|
$users = $users->orderBy('last_name', 'asc')->orderBy('first_name', 'asc');
|
||||||
|
|
|
@ -27,7 +27,7 @@ class AssetCheckoutController extends Controller
|
||||||
public function create($assetId)
|
public function create($assetId)
|
||||||
{
|
{
|
||||||
// Check if the asset exists
|
// Check if the asset exists
|
||||||
if (is_null($asset = Asset::find(e($assetId)))) {
|
if (is_null($asset = Asset::with('company')->find(e($assetId)))) {
|
||||||
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
|
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,4 +52,13 @@ class SettingFactory extends Factory
|
||||||
'email_domain' => 'test.com',
|
'email_domain' => 'test.com',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withMultipleFullCompanySupport()
|
||||||
|
{
|
||||||
|
return $this->state(function () {
|
||||||
|
return [
|
||||||
|
'full_multiple_companies_support' => 1,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,16 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
{{csrf_field()}}
|
{{csrf_field()}}
|
||||||
|
@if ($asset->company && $asset->company->name)
|
||||||
|
<div class="form-group">
|
||||||
|
{{ Form::label('model', trans('general.company'), array('class' => 'col-md-3 control-label')) }}
|
||||||
|
<div class="col-md-8">
|
||||||
|
<p class="form-control-static">
|
||||||
|
{{ $asset->company->name }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
<!-- AssetModel name -->
|
<!-- AssetModel name -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
{{ Form::label('model', trans('admin/hardware/form.model'), array('class' => 'col-md-3 control-label')) }}
|
{{ Form::label('model', trans('admin/hardware/form.model'), array('class' => 'col-md-3 control-label')) }}
|
||||||
|
@ -33,7 +43,6 @@
|
||||||
<p class="form-control-static">
|
<p class="form-control-static">
|
||||||
@if (($asset->model) && ($asset->model->name))
|
@if (($asset->model) && ($asset->model->name))
|
||||||
{{ $asset->model->name }}
|
{{ $asset->model->name }}
|
||||||
|
|
||||||
@else
|
@else
|
||||||
<span class="text-danger text-bold">
|
<span class="text-danger text-bold">
|
||||||
<i class="fas fa-exclamation-triangle"></i>{{ trans('admin/hardware/general.model_invalid')}}
|
<i class="fas fa-exclamation-triangle"></i>{{ trans('admin/hardware/general.model_invalid')}}
|
||||||
|
|
90
tests/Feature/Api/Users/UsersForSelectListTest.php
Normal file
90
tests/Feature/Api/Users/UsersForSelectListTest.php
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Api\Users;
|
||||||
|
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Models\Setting;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Testing\Fluent\AssertableJson;
|
||||||
|
use Laravel\Passport\Passport;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class UsersForSelectListTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function testUsersAreReturned()
|
||||||
|
{
|
||||||
|
Setting::factory()->create();
|
||||||
|
|
||||||
|
User::factory()->count(3)->create();
|
||||||
|
|
||||||
|
Passport::actingAs(User::factory()->firstAdmin()->create());
|
||||||
|
$this->getJson(route('api.users.selectlist'))
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonStructure([
|
||||||
|
'results',
|
||||||
|
'pagination',
|
||||||
|
'total_count',
|
||||||
|
'page',
|
||||||
|
'page_count',
|
||||||
|
])
|
||||||
|
->assertJson(fn(AssertableJson $json) => $json->has('results', 4)->etc());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUsersScopedToCompanyWhenMultipleFullCompanySupportEnabled()
|
||||||
|
{
|
||||||
|
Setting::factory()->withMultipleFullCompanySupport()->create();
|
||||||
|
|
||||||
|
$jedi = Company::factory()->has(User::factory()->count(3)->sequence(
|
||||||
|
['first_name' => 'Luke', 'last_name' => 'Skywalker', 'username' => 'lskywalker'],
|
||||||
|
['first_name' => 'Obi-Wan', 'last_name' => 'Kenobi', 'username' => 'okenobi'],
|
||||||
|
['first_name' => 'Anakin', 'last_name' => 'Skywalker', 'username' => 'askywalker'],
|
||||||
|
))->create();
|
||||||
|
|
||||||
|
$sith = Company::factory()
|
||||||
|
->has(User::factory()->state(['first_name' => 'Darth', 'last_name' => 'Vader', 'username' => 'dvader']))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
Passport::actingAs($jedi->users->first());
|
||||||
|
$response = $this->getJson(route('api.users.selectlist'))->assertOk();
|
||||||
|
|
||||||
|
$results = collect($response->json('results'));
|
||||||
|
|
||||||
|
$this->assertEquals(3, $results->count());
|
||||||
|
$this->assertTrue(
|
||||||
|
$results->pluck('text')->contains(fn($text) => str_contains($text, 'Luke'))
|
||||||
|
);
|
||||||
|
$this->assertFalse(
|
||||||
|
$results->pluck('text')->contains(fn($text) => str_contains($text, 'Darth'))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUsersScopedToCompanyDuringSearchWhenMultipleFullCompanySupportEnabled()
|
||||||
|
{
|
||||||
|
Setting::factory()->withMultipleFullCompanySupport()->create();
|
||||||
|
|
||||||
|
$jedi = Company::factory()->has(User::factory()->count(3)->sequence(
|
||||||
|
['first_name' => 'Luke', 'last_name' => 'Skywalker', 'username' => 'lskywalker'],
|
||||||
|
['first_name' => 'Obi-Wan', 'last_name' => 'Kenobi', 'username' => 'okenobi'],
|
||||||
|
['first_name' => 'Anakin', 'last_name' => 'Skywalker', 'username' => 'askywalker'],
|
||||||
|
))->create();
|
||||||
|
|
||||||
|
Company::factory()
|
||||||
|
->has(User::factory()->state(['first_name' => 'Darth', 'last_name' => 'Vader', 'username' => 'dvader']))
|
||||||
|
->create();
|
||||||
|
|
||||||
|
Passport::actingAs($jedi->users->first());
|
||||||
|
$response = $this->getJson(route('api.users.selectlist', ['search' => 'a']))->assertOk();
|
||||||
|
|
||||||
|
$results = collect($response->json('results'));
|
||||||
|
|
||||||
|
$this->assertEquals(3, $results->count());
|
||||||
|
$this->assertTrue($results->pluck('text')->contains(fn($text) => str_contains($text, 'Luke')));
|
||||||
|
$this->assertTrue($results->pluck('text')->contains(fn($text) => str_contains($text, 'Anakin')));
|
||||||
|
|
||||||
|
$response = $this->getJson(route('api.users.selectlist', ['search' => 'v']))->assertOk();
|
||||||
|
$this->assertEquals(0, collect($response->json('results'))->count());
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,9 +2,17 @@
|
||||||
|
|
||||||
namespace Tests;
|
namespace Tests;
|
||||||
|
|
||||||
|
use App\Models\Setting;
|
||||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||||
|
|
||||||
abstract class TestCase extends BaseTestCase
|
abstract class TestCase extends BaseTestCase
|
||||||
{
|
{
|
||||||
use CreatesApplication;
|
use CreatesApplication;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->beforeApplicationDestroyed(fn() => Setting::$_cache = null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue