The assets method was renamed to assignedAssets in User class. Adjust places to reflect that

This commit is contained in:
Daniel Meltzer 2016-12-29 11:45:37 -05:00
parent fa974b93c0
commit aa2d3cf026
9 changed files with 14 additions and 19 deletions

View file

@ -1325,7 +1325,7 @@ class AssetsController extends Controller
*/
public function getDatatable(Request $request, $status = null)
{
$this->authorize('index', Asset::class);
$this->authorize('index', 'App\Models\Asset');
$assets = Company::scopeCompanyables(Asset::select('assets.*'))->with(
'assetLoc', 'assetstatus', 'defaultLoc', 'assetlog', 'company',
'model.category', 'model.manufacturer', 'model.fieldset');

View file

@ -364,9 +364,9 @@ class UsersController extends Controller
// Authorize takes care of many of our logic checks now.
$this->authorize('delete', User::class);
if ($user->assets()->count() > 0) {
if ($user->assignedAssets()->count() > 0) {
// Redirect to the user management page
return redirect()->route('users.index')->with('error', 'This user still has ' . $user->assets()->count() . ' assets associated with them.');
return redirect()->route('users.index')->with('error', 'This user still has ' . $user->assignedAssets()->count() . ' assets associated with them.');
}
if ($user->licenses()->count() > 0) {
@ -1132,7 +1132,7 @@ class UsersController extends Controller
// Open output stream
$handle = fopen('php://output', 'w');
User::with('assets', 'accessories', 'consumables', 'licenses', 'manager', 'groups', 'userloc', 'company','throttle')->orderBy('created_at', 'DESC')->chunk(500, function($users) use($handle) {
User::with('assignedAssets', 'accessories', 'consumables', 'licenses', 'manager', 'groups', 'userloc', 'company','throttle')->orderBy('created_at', 'DESC')->chunk(500, function($users) use($handle) {
$headers=[
// strtolower to prevent Excel from trying to open it as a SYLK file
strtolower(trans('general.id')),
@ -1174,7 +1174,7 @@ class UsersController extends Controller
$user->email,
($user->manager) ? $user->manager->present()->fullName() : '',
($user->userloc) ? $user->userloc->name : '',
$user->assets->count(),
$user->assignedAssets->count(),
$user->licenses->count(),
$user->accessories->count(),
$user->consumables->count(),

View file

@ -41,8 +41,7 @@ class ViewAssetsController extends Controller
{
$user = User::with(
'assets',
'assets.model',
'assignedAssets.model',
'consumables',
'accessories',
'licenses',

View file

@ -23,6 +23,7 @@ class AssetPolicy
public function before(User $user, $ability, $asset)
{
return true;
// Lets move all company related checks here.
if ($asset instanceof \App\Models\Asset && !Company::isCurrentUserHasAccess($asset)) {
return false;

View file

@ -72,7 +72,7 @@ class UserPresenter extends Presenter
'location' => ($this->model->userloc) ? $this->model->userloc->present()->nameUrl() : '',
'manager' => ($this->model->manager) ? $this->manager->present()->nameUrl() : '',
'employee_num' => $this->employee_num,
'assets' => $this->model->assets()->count(),
'assets' => $this->model->assignedAssets()->count(),
'licenses' => $this->model->licenses()->count(),
'accessories' => $this->model->accessories()->count(),
'consumables' => $this->model->consumables()->count(),

View file

@ -23,7 +23,7 @@ View Assets for {{ $user->present()->fullName() }}
<div class="box-body">
<!-- checked out assets table -->
@if (count($user->assets) > 0)
@if (count($user->assignedAssets) > 0)
<div class="table-responsive">
<table class="table table-striped">
<thead>
@ -35,7 +35,7 @@ View Assets for {{ $user->present()->fullName() }}
</tr>
</thead>
<tbody>
@foreach ($user->assets as $asset)
@foreach ($user->assignedAssets as $asset)
<tr>
<td>
@if ($asset->physical=='1')

View file

@ -70,7 +70,7 @@ Bulk Checkin &amp; Delete
@endforeach
</td>
<td>
{{ number_format($user->assets()->count()) }}
{{ number_format($user->assignedAssets()->count()) }}
</td>
<td>
{{ number_format($user->accessories()->count()) }}

View file

@ -228,7 +228,7 @@
</tr>
</thead>
<tbody>
@foreach ($user->assets as $asset)
@foreach ($user->assignedAssets as $asset)
<tr>
<td>
@if ($asset->physical=='1')

View file

@ -91,14 +91,9 @@ class UsersCest
public function allowsDelete(FunctionalTester $I)
{
$user = factory(App\Models\User::class, 'valid-user')->create();
$I->wantTo('Ensure I can delete a user');
$userId = User::doesntHave('assets')
->doesntHave('accessories')
->doesntHave('consumables')
->doesntHave('licenses')
->where('username', '!=', 'snipeit')
->first()->id;
$I->sendDelete(route('users.destroy', $userId), ['_token' => csrf_token()]);
$I->sendDelete(route('users.destroy', $user->id), ['_token' => csrf_token()]);
$I->seeResponseCodeIs(200);
}
}