diff --git a/app/Http/Controllers/Assets/AssetCheckinController.php b/app/Http/Controllers/Assets/AssetCheckinController.php index d05822a55f..73f4838a6a 100644 --- a/app/Http/Controllers/Assets/AssetCheckinController.php +++ b/app/Http/Controllers/Assets/AssetCheckinController.php @@ -12,7 +12,6 @@ use App\Models\CheckoutAcceptance; use App\Models\LicenseSeat; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Facades\Auth; -use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\Log; @@ -47,6 +46,10 @@ class AssetCheckinController extends Controller return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkin.already_checked_in')); } + if (!$asset->model) { + return redirect()->route('hardware.show', $asset->id)->with('error', trans('admin/hardware/general.model_invalid_fix')); + } + return view('hardware/checkin', compact('asset'))->with('statusLabel_list', Helper::statusLabelList())->with('backto', $backto)->with('table_name', 'Assets'); } @@ -72,6 +75,11 @@ class AssetCheckinController extends Controller if (is_null($target = $asset->assignedTo)) { return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkin.already_checked_in')); } + + if (!$asset->model) { + return redirect()->route('hardware.show', $asset->id)->with('error', trans('admin/hardware/general.model_invalid_fix')); + } + $this->authorize('checkin', $asset); if ($asset->assignedType() == Asset::USER) { diff --git a/app/Http/Controllers/Assets/AssetCheckoutController.php b/app/Http/Controllers/Assets/AssetCheckoutController.php index 0cbbb79b6c..36f00f0fc6 100644 --- a/app/Http/Controllers/Assets/AssetCheckoutController.php +++ b/app/Http/Controllers/Assets/AssetCheckoutController.php @@ -34,12 +34,17 @@ class AssetCheckoutController extends Controller $this->authorize('checkout', $asset); + if (!$asset->model) { + return redirect()->route('hardware.show', $asset->id)->with('error', trans('admin/hardware/general.model_invalid_fix')); + } + if ($asset->availableForCheckout()) { return view('hardware/checkout', compact('asset')) ->with('statusLabel_list', Helper::deployableStatusLabelList()) ->with('table_name', 'Assets'); } + return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkout.not_available')); } @@ -62,6 +67,11 @@ class AssetCheckoutController extends Controller return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkout.not_available')); } $this->authorize('checkout', $asset); + + if (!$asset->model) { + return redirect()->route('hardware.show', $asset->id)->with('error', trans('admin/hardware/general.model_invalid_fix')); + } + $admin = Auth::user(); $target = $this->determineCheckoutTarget(); diff --git a/resources/lang/en-US/admin/hardware/general.php b/resources/lang/en-US/admin/hardware/general.php index f7f8ad4d06..e1472e709c 100644 --- a/resources/lang/en-US/admin/hardware/general.php +++ b/resources/lang/en-US/admin/hardware/general.php @@ -15,8 +15,8 @@ return [ 'delete_confirm' => 'Are you sure you want to delete this asset?', 'edit' => 'Edit Asset', 'model_deleted' => 'This Assets model has been deleted. You must restore the model before you can restore the Asset.', - 'model_invalid' => 'The Model of this Asset is invalid.', - 'model_invalid_fix' => 'The Asset should be edited to correct this before attempting to check it in or out.', + 'model_invalid' => 'This model for this asset is invalid.', + 'model_invalid_fix' => 'The asset must be updated use a valid asset model this before attempting to check it in or out, or to audit it.', 'requestable' => 'Requestable', 'requested' => 'Requested', 'not_requestable' => 'Not Requestable', diff --git a/resources/views/hardware/audit.blade.php b/resources/views/hardware/audit.blade.php index 9713b6fc1e..1192d3cc9f 100644 --- a/resources/views/hardware/audit.blade.php +++ b/resources/views/hardware/audit.blade.php @@ -18,7 +18,7 @@
-
+
{{ Form::open([ @@ -32,15 +32,28 @@
{{csrf_field()}} - @if ($asset->model->name) - + +
{{ Form::label('name', trans('admin/hardware/form.model'), array('class' => 'col-md-3 control-label')) }}
-

{{ $asset->model->name }}

+

+ @if (($asset->model) && ($asset->model->name)) + {{ $asset->model->name }} + @else + + + {{ trans('admin/hardware/general.model_invalid')}} + + {{ trans('admin/hardware/general.model_invalid_fix')}} + + {{ trans('admin/hardware/general.edit') }} + + @endif +

- @endif +
@@ -114,7 +127,10 @@
diff --git a/resources/views/hardware/checkin.blade.php b/resources/views/hardware/checkin.blade.php index debfdef91c..9bd88f3f4f 100755 --- a/resources/views/hardware/checkin.blade.php +++ b/resources/views/hardware/checkin.blade.php @@ -16,50 +16,56 @@ -
+
-
-
-
-

{{ trans('admin/hardware/form.tag') }} {{ $asset->asset_tag }}

+
+
+
+

+ {{ trans('admin/hardware/form.tag') }} + {{ $asset->asset_tag }} +

-
-
- @if ($backto=='user') +
+
+ + @if ($backto == 'user') +
+ @else - @else - - @endif + action="{{ route('hardware.checkin.store', array('assetId'=> $asset->id)) }}" autocomplete="off"> + @endif {{csrf_field()}}
{{ Form::label('model', trans('admin/hardware/form.model'), array('class' => 'col-md-3 control-label')) }}
+

@if (($asset->model) && ($asset->model->name)) {{ $asset->model->name }} - @else - {{ trans('admin/hardware/general.model_invalid')}} - {{ trans('admin/hardware/general.model_invalid_fix')}} + + {{ trans('admin/hardware/general.model_invalid')}} + + {{ trans('admin/hardware/general.model_invalid_fix')}} + + {{ trans('admin/hardware/general.edit') }} + @endif

+
-
{{ Form::label('name', trans('admin/hardware/form.name'), array('class' => 'col-md-3 control-label')) }}
- + {!! $errors->first('name', '') !!}
@@ -67,7 +73,7 @@
{{ Form::label('status_id', trans('admin/hardware/form.status'), array('class' => 'col-md-3 control-label')) }} -
+
{{ Form::select('status_id', $statusLabel_list, '', array('class'=>'select2', 'style'=>'width:100%','id' =>'modal-statuslabel_types', 'aria-label'=>'status_id')) }} {!! $errors->first('status_id', '') !!}
@@ -77,7 +83,9 @@
+ {{ Form::label('checkin_at', trans('admin/hardware/form.checkin_date'), array('class' => 'col-md-3 control-label')) }} +
@@ -89,25 +97,29 @@
-
- {{ Form::label('note', trans('admin/hardware/form.notes'), array('class' => 'col-md-3 control-label')) }} -
- + {!! $errors->first('note', '') !!}
- @include ('partials.forms.redirect_submit_options', ['route' => 'hardware.index', 'table_name' => $table_name, 'type'=> $asset->model->name, 'checkin' => true]) - -
-
+
+
-
+ @include ('partials.forms.redirect_submit_options', + [ + 'route' => 'hardware.index', + 'table_name' => $table_name, + 'type'=> ($asset->model ? $asset->model->name : trans('general.asset_model')), + 'checkin' => true + ]) + + +
+ @stop \ No newline at end of file diff --git a/resources/views/hardware/checkout.blade.php b/resources/views/hardware/checkout.blade.php index bb02992819..30e6e670a4 100755 --- a/resources/views/hardware/checkout.blade.php +++ b/resources/views/hardware/checkout.blade.php @@ -36,7 +36,8 @@
@endif - + +
{{ Form::label('model', trans('admin/hardware/form.model'), array('class' => 'col-md-3 control-label')) }}
@@ -45,8 +46,14 @@ {{ $asset->model->name }} @else - {{ trans('admin/hardware/general.model_invalid')}} - {{ trans('admin/hardware/general.model_invalid_fix')}} + + {{ trans('admin/hardware/general.model_invalid')}} + + + {{ trans('admin/hardware/general.model_invalid_fix')}} + + {{ trans('admin/hardware/general.edit') }} + @endif

@@ -141,7 +148,13 @@ @endif
- @include ('partials.forms.redirect_submit_options', ['route' => 'hardware.index', 'table_name' => $table_name, 'type'=> $asset->model->name, 'checkin' => false]) + @include ('partials.forms.redirect_submit_options', + [ + 'route' => 'hardware.index', + 'table_name' => $table_name, + 'type'=> ($asset->model ? $asset->model->name : trans('general.asset_model')), + 'checkin' => false + ])
diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 4eeea43137..a9159c4fa3 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -867,7 +867,7 @@ 'id' => 'bulkForm']) }} - + {{ Form::close() }} @@ -895,17 +895,21 @@ @if (($asset->assigned_to != '') && ($asset->deleted_at=='')) @can('checkin', \App\Models\Asset::class) @endcan @elseif (($asset->assigned_to == '') && ($asset->deleted_at=='')) @can('checkout', \App\Models\Asset::class) @endcan @endif @@ -915,7 +919,7 @@ @can('update', $asset) @if ($asset->deleted_at=='') @@ -924,7 +928,7 @@ @can('create', $asset) @@ -932,21 +936,24 @@ @can('audit', \App\Models\Asset::class) @endcan @can('delete', $asset)
@if ($asset->deleted_at=='') - + {{ trans('general.delete') }} @else
@csrf - +
@endif
diff --git a/resources/views/notifications.blade.php b/resources/views/notifications.blade.php index 0205e3e10f..a64436f68d 100755 --- a/resources/views/notifications.blade.php +++ b/resources/views/notifications.blade.php @@ -11,7 +11,7 @@ @endif -@if ($message = Session::get('status')) +@if ($message = session()->get('status'))
@@ -23,7 +23,7 @@ @endif -@if ($message = Session::get('success')) +@if ($message = session()->get('success'))
@@ -35,7 +35,7 @@ @endif -@if ($message = Session::get('success-unescaped')) +@if ($message = session()->get('success-unescaped'))
@@ -47,7 +47,7 @@ @endif -@if ($assets = Session::get('assets')) +@if ($assets = session()->get('assets')) @foreach ($assets as $asset)
@@ -62,9 +62,9 @@
  • {{ trans('general.asset_name') }} {{ $asset->model->name }}
  • @endisset
  • {{ trans('general.asset_tag') }} {{ $asset->asset_tag }}
  • - @isset ($asset->notes) -
  • {{ trans('general.notes') }} {{ $asset->notes }}
  • - @endisset + @isset ($asset->notes) +
  • {{ trans('general.notes') }} {{ $asset->notes }}
  • + @endisset
    @@ -73,7 +73,7 @@ @endif -@if ($consumables = Session::get('consumables')) +@if ($consumables = session()->get('consumables')) @foreach ($consumables as $consumable)
    @@ -87,7 +87,7 @@ @endif -@if ($accessories = Session::get('accessories')) +@if ($accessories = session()->get('accessories')) @foreach ($accessories as $accessory)
    @@ -101,7 +101,7 @@ @endif -@if ($message = Session::get('error')) +@if ($message = session()->get('error'))
    @@ -113,7 +113,7 @@ @endif -@if ($messages = Session::get('error_messages')) +@if ($messages = session()->get('error_messages')) @foreach ($messages as $message)
    @@ -127,7 +127,7 @@ @endif -@if ($messages = Session::get('bulk_asset_errors')) +@if ($messages = session()->get('bulk_asset_errors'))
    @@ -146,7 +146,7 @@ @endif -@if ($message = Session::get('warning')) +@if ($message = session()->get('warning'))
    @@ -158,7 +158,7 @@ @endif -@if ($message = Session::get('info')) +@if ($message = session()->get('info'))
    diff --git a/resources/views/partials/forms/redirect_submit_options.blade.php b/resources/views/partials/forms/redirect_submit_options.blade.php index 979bc5403c..0c89f587bd 100644 --- a/resources/views/partials/forms/redirect_submit_options.blade.php +++ b/resources/views/partials/forms/redirect_submit_options.blade.php @@ -1,11 +1,36 @@ + + + \ No newline at end of file diff --git a/tests/Feature/Checkins/AssetCheckinTest.php b/tests/Feature/Checkins/AssetCheckinTest.php index 7734d4831d..1ccbbfaa01 100644 --- a/tests/Feature/Checkins/AssetCheckinTest.php +++ b/tests/Feature/Checkins/AssetCheckinTest.php @@ -28,6 +28,16 @@ class AssetCheckinTest extends TestCase { $this->actingAs(User::factory()->checkinAssets()->create()) ->post(route('hardware.checkin.store', ['assetId' => Asset::factory()->create()->id])) + ->assertStatus(302) + ->assertSessionHas('error') + ->assertRedirect(route('hardware.index')); + } + + public function testCannotStoreAssetCheckinThatIsNotCheckedOut() + { + $this->actingAs(User::factory()->checkinAssets()->create()) + ->get(route('hardware.checkin.store', ['assetId' => Asset::factory()->create()->id])) + ->assertStatus(302) ->assertSessionHas('error') ->assertRedirect(route('hardware.index')); } @@ -159,4 +169,31 @@ class AssetCheckinTest extends TestCase return $event->action_date === '2023-01-02' && $event->note === 'hello'; }, 1); } + + public function testAssetCheckinPageIsRedirectedIfModelIsInvalid() + { + + $asset = Asset::factory()->assignedToUser()->create(); + $asset->model_id = 0; + $asset->forceSave(); + + $this->actingAs(User::factory()->admin()->create()) + ->get(route('hardware.checkin.create', ['assetId' => $asset->id])) + ->assertStatus(302) + ->assertSessionHas('error') + ->assertRedirect(route('hardware.show',['hardware' => $asset->id])); + } + + public function testAssetCheckinPagePostIsRedirectedIfModelIsInvalid() + { + $asset = Asset::factory()->assignedToUser()->create(); + $asset->model_id = 0; + $asset->forceSave(); + + $this->actingAs(User::factory()->admin()->create()) + ->post(route('hardware.checkin.store', ['assetId' => $asset->id])) + ->assertStatus(302) + ->assertSessionHas('error') + ->assertRedirect(route('hardware.show', ['hardware' => $asset->id])); + } } diff --git a/tests/Feature/Checkouts/AssetCheckoutTest.php b/tests/Feature/Checkouts/AssetCheckoutTest.php index fd0408b452..6dcff789f0 100644 --- a/tests/Feature/Checkouts/AssetCheckoutTest.php +++ b/tests/Feature/Checkouts/AssetCheckoutTest.php @@ -236,4 +236,35 @@ class AssetCheckoutTest extends TestCase $this->assertTrue(Carbon::parse($asset->last_checkout)->diffInSeconds(now()) < 2); } + + public function testAssetCheckoutPageIsRedirectedIfModelIsInvalid() + { + + $asset = Asset::factory()->create(); + $asset->model_id = 0; + $asset->forceSave(); + + $this->actingAs(User::factory()->admin()->create()) + ->get(route('hardware.checkout.create', ['assetId' => $asset->id])) + ->assertStatus(302) + ->assertSessionHas('error') + ->assertRedirect(route('hardware.show',['hardware' => $asset->id])); + } + + public function testAssetCheckoutPagePostIsRedirectedIfModelIsInvalid() + { + $asset = Asset::factory()->create(); + $asset->model_id = 0; + $asset->forceSave(); + $user = User::factory()->create(); + + $this->actingAs(User::factory()->admin()->create()) + ->post(route('hardware.checkout.store', $asset), [ + 'checkout_to_type' => 'user', + 'assigned_user' => $user->id, + ]) + ->assertStatus(302) + ->assertSessionHas('error') + ->assertRedirect(route('hardware.show', ['hardware' => $asset->id])); + } }