Skip to content

Logging Audit on Checkin/out #16679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
7 changes: 6 additions & 1 deletion app/Http/Controllers/Assets/AssetCheckinController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Illuminate\Support\Facades\Log;
use \Illuminate\Contracts\View\View;
use \Illuminate\Http\RedirectResponse;
use Gate;

class AssetCheckinController extends Controller
{
Expand Down Expand Up @@ -133,7 +134,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 redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets'))->with('success', trans('admin/hardware/message.checkin.success'));
}
Expand Down
6 changes: 6 additions & 0 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;

class AssetCheckoutController extends Controller
{
Expand Down Expand Up @@ -114,6 +115,11 @@ 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'))) {
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'));
}
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 @@ -283,6 +283,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
22 changes: 16 additions & 6 deletions resources/views/hardware/checkin.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,6 @@
'show_display_checkin_fields' => 'true'
])







<!-- Note -->
<div class="form-group {{ $errors->has('note') ? 'error' : '' }}">
<label for="note" class="col-md-3 control-label">
Expand All @@ -161,6 +155,22 @@
{!! $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
65 changes: 65 additions & 0 deletions resources/views/hardware/checkout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,23 @@
</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" id="auditcheckbox" onclick="auditCheckbox()">
{{ trans('admin/settings/general.log_audit') }}
<p id="audittext" style="display:none">Checkbox is CHECKED!</p>
</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 @@ -223,6 +240,54 @@
@section('moar_scripts')
@include('partials/assets-assigned')

<script> //testing script
function auditCheckbox() {
// Get the checkbox
var checkBox = document.getElementById("auditcheckbox");
// Get the output text
var text = document.getElementById("audittext");

// If the checkbox is checked, display the fields
if (checkBox.checked == true){
text.style.display = "block";
} else {
text.style.display = "none";
}
</script>

<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>
$(document).ready(function() {
$("#optional_info").on("click", function () {
$('#optional_details').fadeToggle(100);
$('#optional_info_icon').toggleClass('checkbox);
var optional_info_open = $('#optional_info_icon').hasClass('checkbox');
document.cookie = "optional_info_open=" + optional_info_open + '; path=/';
});
var all_cookies = document.cookie.split(';')
for (var i in all_cookies) {
var trimmed_cookie = all_cookies[i].trim(' ')
if (trimmed_cookie.startsWith('optional_info_open=')) {
elems = all_cookies[i].split('=', 2)
if (elems[1] == 'true') {
$('#optional_info').trigger('click');
}
}
}
});

<script>
// $('#checkout_at').datepicker({
// clearBtn: true,
Expand Down
Loading