Merge branch 'dampfklon-9813-duplicate-accept-asset' into develop

This commit is contained in:
snipe 2022-06-29 04:58:26 -07:00
commit daaf8713d8
5 changed files with 74 additions and 343 deletions

View file

@ -180,123 +180,4 @@ class ViewAssetsController extends Controller
{
return view('account/requested');
}
// Get the acceptance screen
public function getAcceptAsset($logID = null)
{
$findlog = Actionlog::where('id', $logID)->first();
if (! $findlog) {
return redirect()->to('account/view-assets')->with('error', 'No matching record.');
}
if ($findlog->accepted_id != '') {
return redirect()->to('account/view-assets')->with('error', trans('admin/users/message.error.asset_already_accepted'));
}
$user = Auth::user();
// TODO - Fix this for non-assets
if (($findlog->item_type == Asset::class) && ($user->id != $findlog->item->assigned_to)) {
return redirect()->to('account/view-assets')->with('error', trans('admin/users/message.error.incorrect_user_accepted'));
}
$item = $findlog->item;
// Check if the asset exists
if (is_null($item)) {
// Redirect to the asset management page
return redirect()->to('account')->with('error', trans('admin/hardware/message.does_not_exist'));
} elseif (! Company::isCurrentUserHasAccess($item)) {
return redirect()->route('requestable-assets')->with('error', trans('general.insufficient_permissions'));
} else {
return view('account/accept-asset', compact('item'))->with('findlog', $findlog)->with('item', $item);
}
}
// Save the acceptance
public function postAcceptAsset(Request $request, $logID = null)
{
// Check if the asset exists
if (is_null($findlog = Actionlog::where('id', $logID)->first())) {
// Redirect to the asset management page
return redirect()->to('account/view-assets')->with('error', trans('admin/hardware/message.does_not_exist'));
}
if ($findlog->accepted_id != '') {
// Redirect to the asset management page
return redirect()->to('account/view-assets')->with('error', trans('admin/users/message.error.asset_already_accepted'));
}
if ($request->missing('asset_acceptance')) {
return redirect()->back()->with('error', trans('admin/users/message.error.accept_or_decline'));
}
$user = Auth::user();
if (($findlog->item_type == Asset::class) && ($user->id != $findlog->item->assigned_to)) {
return redirect()->to('account/view-assets')->with('error', trans('admin/users/message.error.incorrect_user_accepted'));
}
if ($request->filled('signature_output')) {
$path = config('app.private_uploads').'/signatures';
$sig_filename = 'siglog-'.$findlog->id.'-'.date('Y-m-d-his').'.png';
$data_uri = e($request->get('signature_output'));
$encoded_image = explode(',', $data_uri);
$decoded_image = base64_decode($encoded_image[1]);
Storage::putFileAs($path, $decoded_image, $sig_filename);
//file_put_contents($path.'/'.$sig_filename, $decoded_image);
}
$logaction = new Actionlog();
if ($request->input('asset_acceptance') == 'accepted') {
$logaction_msg = 'accepted';
$accepted = 'accepted';
$return_msg = trans('admin/users/message.accepted');
} else {
$logaction_msg = 'declined';
$accepted = 'rejected';
$return_msg = trans('admin/users/message.declined');
}
$logaction->item_id = $findlog->item_id;
$logaction->item_type = $findlog->item_type;
// Asset
if (($findlog->item_id != '') && ($findlog->item_type == Asset::class)) {
if ($request->input('asset_acceptance') != 'accepted') {
DB::table('assets')
->where('id', $findlog->item_id)
->update(['assigned_to' => null]);
}
}
$logaction->target_id = $findlog->target_id;
$logaction->target_type = User::class;
$logaction->note = e($request->input('note'));
$logaction->updated_at = date('Y-m-d H:i:s');
if (isset($sig_filename)) {
$logaction->accept_signature = $sig_filename;
}
$log = $logaction->logaction($logaction_msg);
$update_checkout = DB::table('action_logs')
->where('id', $findlog->id)
->update(['accepted_id' => $logaction->id]);
if (($findlog->item_id != '') && ($findlog->item_type == Asset::class)) {
$affected_asset = $logaction->item;
$affected_asset->accepted = $accepted;
$affected_asset->save();
}
if ($update_checkout) {
return redirect()->to('account/view-assets')->with('success', $return_msg);
} else {
return redirect()->to('account/view-assets')->with('error', 'Something went wrong ');
}
}
}

View file

@ -1,10 +1,10 @@
<?php
return array (
'app_version' => 'v6.0.5',
'full_app_version' => 'v6.0.5 - build 8229-g94e723a88',
'build_version' => '8229',
'full_app_version' => 'v6.0.5 - build 8230-g393c32558',
'build_version' => '8230',
'prerelease_version' => '',
'hash_version' => 'g94e723a88',
'full_hash' => 'v6.0.5-101-g94e723a88',
'branch' => 'develop',
'hash_version' => 'g393c32558',
'full_hash' => 'v6.0.5-102-g393c32558',
'branch' => 'master',
);

View file

@ -1,135 +0,0 @@
@extends('layouts/default')
{{-- Page title --}}
@section('title')
{{ trans('general.accept', ['asset' => $item->present()->name()]) }}
@parent
@stop
{{-- Page content --}}
@section('content')
<link rel="stylesheet" href="{{ url(mix('css/dist/signature-pad.min.css')) }}">
<style>
.form-horizontal .control-label, .form-horizontal .radio, .form-horizontal .checkbox, .form-horizontal .radio-inline, .form-horizontal .checkbox-inline {
padding-top: 17px;
padding-right: 10px;
}
#eula_div {
width: 100%;
height: auto;
overflow: scroll;
}
</style>
<form class="form-horizontal" method="post" action="" autocomplete="off">
<!-- CSRF Token -->
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
<input type="hidden" name="logId" value="{{ $findlog->id }}" />
<div class="row">
<div class="col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2">
<div class="panel box box-default">
<div class="box-body">
<div class="col-md-12">
<div class="radio">
<label>
<input type="radio" name="asset_acceptance" id="accepted" value="accepted">
{{trans('general.i_accept')}}
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="asset_acceptance" id="declined" value="declined">
{{trans('general.i_decline')}}
</label>
</div>
@if ($item->getEula())
<div class="col-md-12" style="padding-top: 20px">
<div id="eula_div">
{!! $item->getEula() !!}
</div>
</div>
@endif
@if ($snipeSettings->require_accept_signature=='1')
<div class="col-md-12 col-sm-12 text-center" style="padding-top: 20px">
<h2>{{trans('general.sign_tos')}}</h2>
<div id="signature-pad" class="m-signature-pad">
<div class="m-signature-pad--body col-md-12 col-sm-12 col-lg-12 col-xs-12">
<canvas></canvas>
<input type="hidden" name="signature_output" id="signature_output">
</div>
<div class="col-md-12 col-sm-12 col-lg-12 col-xs-12 text-center">
<button type="button" class="btn btn-sm btn-primary clear" data-action="clear" id="clear_button">{{trans('general.clear_signature')}}</button>
</div>
</div>
</div> <!-- .col-md-12.text-center-->
@endif
</div><!-- / col-md-12 -->
</div> <!-- / box-body -->
<div class="box-footer text-right">
<button type="submit" class="btn btn-success" id="submit-button"><i class="fas fa-check icon-white" aria-hidden="true"></i> {{ trans('general.submit') }}</button>
</div><!-- /.box-footer -->
</div> <!-- / box-default -->
</div> <!-- / col -->
</div> <!-- / row -->
</form>
@stop
@section('moar_scripts')
<script nonce="{{ csrf_token() }}">
var wrapper = document.getElementById("signature-pad"),
clearButton = wrapper.querySelector("[data-action=clear]"),
saveButton = wrapper.querySelector("[data-action=save]"),
canvas = wrapper.querySelector("canvas"),
signaturePad;
// Adjust canvas coordinate space taking into account pixel ratio,
// to make it look crisp on mobile devices.
// This also causes canvas to be cleared.
function resizeCanvas() {
// When zoomed out to less than 100%, for some very strange reason,
// some browsers report devicePixelRatio as less than 1
// and only part of the canvas is cleared then.
var ratio = Math.max(window.devicePixelRatio || 1, 1);
canvas.width = canvas.offsetWidth * ratio;
canvas.height = canvas.offsetHeight * ratio;
canvas.getContext("2d").scale(ratio, ratio);
}
window.onresize = resizeCanvas;
resizeCanvas();
signaturePad = new SignaturePad(canvas);
$('#clear_button').on("click", function (event) {
signaturePad.clear();
});
$('#submit-button').on("click", function (event) {
if (signaturePad.isEmpty()) {
alert("Please provide signature first.");
return false;
} else {
$('#signature_output').val(signaturePad.toDataURL());
}
});
</script>
@stop

View file

@ -2,7 +2,7 @@
{{-- Page title --}}
@section('title')
{{ trans('general.accept', array('asset' => $acceptance->checkoutable->present()->name())) }}
{{trans('general.accept', ['asset' => $acceptance->checkoutable->present()->name()])}}
@parent
@stop
@ -10,89 +10,80 @@
{{-- Page content --}}
@section('content')
<link rel="stylesheet" href="{{ url('css/signature-pad.min.css') }}">
<style>
.form-horizontal .control-label, .form-horizontal .radio, .form-horizontal .checkbox, .form-horizontal .radio-inline, .form-horizontal .checkbox-inline {
padding-top: 17px;
padding-right: 10px;
}
<link rel="stylesheet" href="{{ url('css/signature-pad.min.css') }}">
#eula_div {
width: 100%;
height: auto;
overflow: scroll;
}
<style>
.form-horizontal .control-label, .form-horizontal .radio, .form-horizontal .checkbox, .form-horizontal .radio-inline, .form-horizontal .checkbox-inline {
padding-top: 17px;
padding-right: 10px;
}
.m-signature-pad--body {
border-style: solid;
border-color: grey;
border-width: thin;
}
#eula_div {
width: 100%;
height: auto;
overflow: auto;
}
</style>
.m-signature-pad--body {
border-style: solid;
border-color: grey;
border-width: thin;
}
</style>
<form class="form-horizontal" method="post" action="" autocomplete="off">
<!-- CSRF Token -->
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
<form class="form-horizontal" method="post" action="" autocomplete="off">
<!-- CSRF Token -->
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
<div class="row">
<div class="col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2">
<div class="panel box box-default">
<div class="box-body">
<div class="col-md-12">
<div class="radio">
<label>
<input type="radio" name="asset_acceptance" id="accepted" value="accepted" class="minimal">
{{ trans('general.i_accept') }}
</label>
</div>
<div class="row">
<div class="col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2">
<div class="panel box box-default">
<div class="box-body">
@if ($acceptance->checkoutable->getEula())
<div id="eula_div" style="padding-bottom: 20px">
{!! $acceptance->checkoutable->getEula() !!}
</div>
@endif
<div class="radio">
<label>
<input type="radio" name="asset_acceptance" id="declined" value="declined" class="minimal">
{{ trans('general.i_decline') }}
</label>
</div>
<h3>{{$acceptance->checkoutable->present()->name()}}</h3>
<div class="radio">
<label>
<input type="radio" class="minimal" name="asset_acceptance" id="accepted" value="accepted">
{{trans('general.i_accept')}}
</label>
</div>
<div class="radio">
<label>
<input type="radio" class="minimal" name="asset_acceptance" id="declined" value="declined">
{{trans('general.i_decline')}}
</label>
</div>
@if ($acceptance->checkoutable->getEula())
<div class="col-md-12" style="padding-top: 20px">
<div id="eula_div">
{!! $acceptance->checkoutable->getEula() !!}
</div>
</div>
@endif
@if ($snipeSettings->require_accept_signature=='1')
<h3 style="padding-top: 20px">{{trans('general.sign_tos')}}</h3>
<div id="signature-pad" class="m-signature-pad">
<div class="m-signature-pad--body col-md-12 col-sm-12 col-lg-12 col-xs-12">
<canvas></canvas>
<input type="hidden" name="signature_output" id="signature_output">
</div>
<div class="col-md-12 col-sm-12 col-lg-12 col-xs-12 text-center">
<button type="button" class="btn btn-sm btn-default clear" data-action="clear" id="clear_button">{{trans('general.clear_signature')}}</button>
</div>
</div>
@endif
@if ($snipeSettings->require_accept_signature=='1')
<div class="col-md-12 col-sm-12 text-center" style="padding-top: 20px">
<h3>{{ trans('general.sign_tos') }}</h3>
<div id="signature-pad" class="m-signature-pad">
<div class="m-signature-pad--body col-md-12 col-sm-12 col-lg-12 col-xs-12">
<canvas></canvas>
<input type="hidden" name="signature_output" id="signature_output">
</div>
<div class="col-md-12 col-sm-12 col-lg-12 col-xs-12 text-center">
<button type="button" class="btn btn-sm btn-primary clear" data-action="clear" id="clear_button">{{ trans('general.clear_signature') }}</button>
</div>
</div>
</div> <!-- .col-md-12.text-center-->
@endif
</div><!-- / col-md-12 -->
</div> <!-- / box-body -->
<div class="box-footer text-right">
<button type="submit" class="btn btn-success" id="submit-button"><i class="fas fa-check icon-white"></i> {{ trans('general.submit') }}</button>
</div><!-- /.box-footer -->
</div> <!-- / box-default -->
</div> <!-- / col -->
</div> <!-- / row -->
</form>
</div> <!-- / box-body -->
<div class="box-footer text-right">
<button type="submit" class="btn btn-success" id="submit-button"><i class="fa fa-check icon-white" aria-hidden="true"></i> {{ trans('general.submit') }}</button>
</div><!-- /.box-footer -->
</div> <!-- / box-default -->
</div> <!-- / col -->
</div> <!-- / row -->
</form>
@stop
@ -100,10 +91,10 @@
<script nonce="{{ csrf_token() }}">
var wrapper = document.getElementById("signature-pad"),
clearButton = wrapper.querySelector("[data-action=clear]"),
saveButton = wrapper.querySelector("[data-action=save]"),
canvas = wrapper.querySelector("canvas"),
signaturePad;
clearButton = wrapper.querySelector("[data-action=clear]"),
saveButton = wrapper.querySelector("[data-action=save]"),
canvas = wrapper.querySelector("canvas"),
signaturePad;
// Adjust canvas coordinate space taking into account pixel ratio,
// to make it look crisp on mobile devices.
@ -137,4 +128,4 @@
});
</script>
@stop
@stop

View file

@ -254,12 +254,6 @@ Route::group(['prefix' => 'account', 'middleware' => ['auth']], function () {
Route::get('requested', [ViewAssetsController::class, 'getRequestedAssets'])->name('account.requested');
// Accept Asset
Route::get(
'accept-asset/{logID}',
[ViewAssetsController::class, 'getAcceptAsset']
)->name('account/accept-assets');
// Profile
Route::get(
'requestable-assets',