Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion app/Http/Controllers/Assets/AssetCheckinController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Events\CheckoutableCheckedIn;
use App\Helpers\Helper;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Assets\AssetsController;
use App\Http\Requests\AssetCheckinRequest;
use App\Http\Traits\MigratesLegacyAssetLocations;
use App\Models\Asset;
Expand All @@ -14,6 +15,7 @@
use Illuminate\Support\Facades\Log;
use \Illuminate\Contracts\View\View;
use \Illuminate\Http\RedirectResponse;
use Gate;
use Illuminate\Support\Facades\Validator;

class AssetCheckinController extends Controller
Expand Down Expand Up @@ -88,6 +90,13 @@ public function store(AssetCheckinRequest $request, $assetId = null, $backto = n

$this->authorize('checkin', $asset);

if ($request->filled('log_audit') == "1") {
$this->authorize('audit', Asset::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause a forbidden error. We don't need the entire block in this section.

}

if ($asset->assignedType() == Asset::USER) {
$user = $asset->assignedTo;
}
session()->put('checkedInFrom', $asset->assignedTo->id);
session()->put('checkout_to_type', match ($asset->assigned_type) {
'App\Models\User' => 'user',
Expand Down Expand Up @@ -151,7 +160,11 @@ function (Builder $query) use ($asset) {
$asset->customFieldsForCheckinCheckout('display_checkin');

if ($asset->save()) {

if(Gate::allows('audit',$asset)) {
if ($request->filled('log_audit') == "1") {
$asset->logAudit($request->input('note'), $request->input('location_id'));
}
}
event(new CheckoutableCheckedIn($asset, $target, auth()->user(), $request->input('note'), $checkin_at, $originalValues));
return Helper::getRedirectOption($request, $asset->id, 'Assets')
->with('success', trans('admin/hardware/message.checkin.success'));
Expand Down
18 changes: 16 additions & 2 deletions app/Http/Controllers/Assets/AssetCheckoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Illuminate\Support\Facades\Session;
use \Illuminate\Contracts\View\View;
use \Illuminate\Http\RedirectResponse;
use Gate;
use Illuminate\Support\Facades\Validator;

class AssetCheckoutController extends Controller
Expand Down Expand Up @@ -44,7 +45,7 @@ public function create(Asset $asset) : View | RedirectResponse
return redirect()->route('hardware.edit', $asset)->withErrors($asset->getErrors());
}


if ($asset->availableForCheckout()) {
return view('hardware/checkout', compact('asset'))
->with('statusLabel_list', Helper::deployableStatusLabelList())
Expand Down Expand Up @@ -80,6 +81,12 @@ public function store(AssetCheckoutRequest $request, $assetId) : RedirectRespons

$admin = auth()->user();

if(Gate::allows('audit',$asset)) {
if ($request->filled('log_audit') == "1") {
$this->authorize('audit', Asset::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here

}
}

$target = $this->determineCheckoutTarget();

$asset = $this->updateAssetLocation($asset, $target);
Expand Down Expand Up @@ -123,7 +130,14 @@ public function store(AssetCheckoutRequest $request, $assetId) : RedirectRespons
session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]);

if ($asset->checkOut($target, $admin, $checkout_at, $expected_checkin, $request->get('note'), $request->get('name'))) {
return Helper::getRedirectOption($request, $asset->id, 'Assets')

if(Gate::allows('audit',$asset)) {
if ($request->filled('log_audit') == "1") {
$asset->logAudit($request->input('note'), $request->input('location_id'));
}
}
return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets'))

->with('success', trans('admin/hardware/message.checkout.success'));
}
// Redirect to the asset management page with error
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en-US/admin/settings/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@
'require_accept_signature_help_text' => 'Enabling this feature will require users to physically sign off on accepting an asset.',
'require_checkinout_notes' => 'Require Notes on Checkin/Checkout',
'require_checkinout_notes_help_text' => 'Enabling this feature will require the note fields to be populated when checking in or checking out an asset.',
'log_audit' => 'Mark as audited',
'log_audit_help_text' => 'Check this box to also log an audit in addition to this',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This phrasing seems a little clunky to me.

Copy link
Member Author

@akemidx akemidx Apr 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, but words are not my strong suit.
However, this seems clunky since at the END after 'this' it will say checkin or checkout

example:
{{ trans('admin/settings/general.log_audit_help_text') . " " . trans('general.checkin') . "." }}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my example in the PR review comment. I suggested different phrasing altogether :)

'left' => 'left',
'right' => 'right',
'top' => 'top',
Expand Down
114 changes: 106 additions & 8 deletions resources/views/hardware/checkin.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,39 +106,109 @@
<div class="form-group">
<div class="col-md-9 col-md-offset-3">
<label class="form-control">
<input name="update_default_location" type="radio" value="1" checked="checked" aria-label="update_default_location" />
{{ Form::radio('update_default_location', '1', old('update_default_location'), ['checked'=> 'checked', 'aria-label'=>'update_default_location']) }}
{{ trans('admin/hardware/form.asset_location') }}
</label>
<label class="form-control">
<input name="update_default_location" type="radio" value="0" aria-label="update_default_location" />
{{ Form::radio('update_default_location', '0', old('update_default_location'), ['aria-label'=>'update_default_location']) }}
{{ trans('admin/hardware/form.asset_location_update_default_current') }}
</label>
</div>
</div> <!--/form-group-->

<!-- Checkout/Checkin Date -->
<div class="form-group{{ $errors->has('checkin_at') ? ' has-error' : '' }}">
<label for="checkin_at" class="col-sm-3 col-xs-12 col-sm-12 control-label">
<label for="checkin_at" class="col-sm-3 control-label">
{{ trans('admin/hardware/form.checkin_date') }}
</label>

<div class="col-md-8 col-xs-12 col-sm-12">
<div class="input-group col-xl-5 col-lg-5 col-md-7 col-sm-9 col-xs-12 required">
<div class="col-md-8">
<div class="input-group col-md-5 required">
<div class="input-group date" data-provide="datepicker"
data-date-format="yyyy-mm-dd" data-autoclose="true">
<input type="text" class="form-control"
placeholder="{{ trans('general.select_date') }}"
name="checkin_at" id="checkin_at"
value="{{ old('checkin_at', date('Y-m-d')) }}">
<span class="input-group-addon">
<x-icon type="calendar" />
</span>
<span class="input-group-addon"><i class="fas fa-calendar"
aria-hidden="true"></i></span>
</div>
{!! $errors->first('checkin_at', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
</div>
</div>

<!-- Custom fields -->
@include("models/custom_fields_form", [
'model' => $asset->model,
'show_display_checkin_fields' => 'true'
])

@if($snipeSettings->audit_on_checkinout){
<!-- Show last audit date -->
<div class="form-group">
<label class="control-label col-md-3">
{{ trans('general.last_audit') }}
</label>
<div class="col-md-8">

<p class="form-control-static">
@if ($asset->last_audit_date)
{{ Helper::getFormattedDateObject($asset->last_audit_date, 'datetime', false) }}
@else
{{ trans('admin/settings/general.none') }}
@endif
</p>
</div>
</div>


<!-- Next Audit -->
<div class="form-group{{ $errors->has('next_audit_date') ? ' has-error' : '' }}">
<label for="next_audit_date" class="col-sm-3 control-label">
{{ trans('general.next_audit_date') }}
</label>
<div class="col-md-8">
<div class="input-group date col-md-5" data-provide="datepicker" data-date-format="yyyy-mm-dd" data-date-clear-btn="true">
<input type="text" class="form-control" placeholder="{{ trans('general.next_audit_date') }}" name="next_audit_date" id="next_audit_date" value="{{ old('next_audit_date', $next_audit_date) }}">
<span class="input-group-addon"><x-icon type="calendar" /></span>
</div>
{!! $errors->first('next_audit_date', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
<p class="help-block">{!! trans('general.next_audit_date_help') !!}</p>
</div>
</div>


} @endif


<!-- Note -->
<div class="form-group {{ $errors->has('note') ? 'error' : '' }}">
<label for="note" class="col-md-3 control-label">
{{ trans('general.notes') }}
</label>
<div class="col-md-8">
<textarea class="col-md-6 form-control" id="note" @required($snipeSettings->require_checkinout_notes)
name="note">{{ old('note', $asset->note) }}</textarea>
{!! $errors->first('note', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
</div>

@can('audit', \App\Models\Asset::class)
<!-- Log an audit checkbox -->
<div class="form-group">
<div class="col-sm-3 control-label" ></div>
<div class="col-md-8">
<label class="form-control">
<input type="checkbox" value="1" name="log_audit" {{ (old('log_audit')) == '1' ? ' checked="checked"' : '' }} aria-label="log_audit">
{{ trans('admin/settings/general.log_audit') }}
</label>
<p class="help-block">{{ trans('admin/settings/general.log_audit_help_text') . " " . trans('general.checkin') . "." }}</p>
</div>
</div>
<!-- /.form-group -->
@endcan

<!-- Note -->
<div class="form-group {{ $errors->has('note') ? 'error' : '' }}">
<label for="note" class="col-md-3 control-label">
Expand All @@ -159,6 +229,34 @@
])


<!-- Note -->
<div class="form-group {{ $errors->has('note') ? 'error' : '' }}">
<label for="note" class="col-md-3 control-label">
{{ trans('general.notes') }}
</label>
<div class="col-md-8">
<textarea class="col-md-6 form-control" id="note" @required($snipeSettings->require_checkinout_notes)
name="note">{{ old('note', $asset->note) }}</textarea>
{!! $errors->first('note', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
</div>

@can('audit', \App\Models\Asset::class)
<!-- Log an audit checkbox -->
<div class="form-group">
<div class="col-sm-3 control-label" ></div>
<div class="col-md-8">
<label class="form-control">
<input type="checkbox" value="1" name="log_audit" {{ (old('log_audit')) == '1' ? ' checked="checked"' : '' }} aria-label="log_audit">
{{ trans('admin/settings/general.log_audit') }}
</label>
<p class="help-block">{{ trans('admin/settings/general.log_audit_help_text') . " " . trans('general.checkin') . "." }}</p>
</div>
</div>
<!-- /.form-group -->
@endcan


</div> <!--/.box-body-->
</div> <!--/.box-body-->

Expand Down
41 changes: 40 additions & 1 deletion resources/views/hardware/checkout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
{!! $errors->first('note', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
</div>

<!-- Custom fields -->
@include("models/custom_fields_form", [
'model' => $asset->model,
Expand All @@ -161,6 +161,22 @@




@can('audit', \App\Models\Asset::class)
<!-- Log an audit checkbox -->
<div class="form-group">
<div class="col-sm-3 control-label" ></div>
<div class="col-md-8">
<label class="form-control">
<input type="checkbox" value="1" name="log_audit" {{ (old('log_audit')) == '1' ? ' checked="checked"' : '' }} aria-label="log_audit">
{{ trans('admin/settings/general.log_audit') }}
</label>
<p class="help-block">{{ trans('admin/settings/general.log_audit_help_text') . " " . trans('general.checkout') . "." }}</p>
</div>
</div>
<!-- /.form-group -->
@endcan

@if ($asset->requireAcceptance() || $asset->getEula() || ($snipeSettings->webhook_endpoint!=''))
<div class="form-group notification-callout">
<div class="col-md-8 col-md-offset-3">
Expand Down Expand Up @@ -222,4 +238,27 @@

@section('moar_scripts')
@include('partials/assets-assigned')
<script>
// Only display the audit fields if the checkbox is selected
$(".format").change(function(){
$(this).find("option:selected").each(function(){
if ($('.format').prop("selectedIndex") == 1) {
$("#custom_regex").show();
} else{
$("#custom_regex").hide();
}
});
}).change();
</script>

<script>
// $('#checkout_at').datepicker({
// clearBtn: true,
// todayHighlight: true,
// endDate: '0d',
// format: 'yyyy-mm-dd'
// });


</script>
@stop
23 changes: 23 additions & 0 deletions resources/views/settings/general.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
{{-- Page content --}}
@section('content')





<form method="POST" autocomplete="off" class="form-horizontal" role="form" id="create-form">
<!-- CSRF Token -->
{{csrf_field()}}
Expand Down Expand Up @@ -227,6 +231,25 @@
</div>
</div>


<!-- login text -->
<div class="form-group {{ $errors->has('login_note') ? 'error' : '' }}">
<div class="col-md-3">
<label for="login_note">{{ trans('admin/settings/general.login_note') }}</label>
</div>
<div class="col-md-9">
@if (config('app.lock_passwords'))

<textarea class="form-control disabled" name="login_note" placeholder="{{trans('admin/settings/general.login_note_placeholder')}}" rows="2" aria-label="login_note" readonly>{{ old('login_note', $setting->login_note) }}</textarea>
{!! $errors->first('login_note', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
<p class="text-warning"><i class="fas fa-lock"></i> {{ trans('general.feature_disabled') }}</p>
@else
<textarea class="form-control" name="login_note" aria-label="login_note" placeholder="{{trans('admin/settings/general.login_note_placeholder')}}" rows="2">{{ old('login_note', $setting->login_note) }}</textarea>
{!! $errors->first('login_note', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
@endif
<p class="help-block">{!! trans('admin/settings/general.login_note_help') !!}</p>
</div>
</div>
<!-- Show assets assigned to user's assets -->
<div class="form-group {{ $errors->has('show_assigned_assets') ? 'error' : '' }}">
<div class="col-md-8 col-md-offset-3">
Expand Down
Loading