mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-24 21:24:13 -08:00
Fixed #4301 - added image upload to audit
This commit is contained in:
parent
4785db4471
commit
1ef4cc9fc2
|
@ -302,8 +302,13 @@ class AssetsController extends Controller
|
|||
|
||||
|
||||
if ($request->has('image_delete')) {
|
||||
try {
|
||||
unlink(public_path().'/uploads/assets/'.$asset->image);
|
||||
$asset->image = '';
|
||||
} catch (\Exception $e) {
|
||||
\Log::error($e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1008,7 +1013,13 @@ class AssetsController extends Controller
|
|||
$this->authorize('view', $asset);
|
||||
|
||||
$log = Actionlog::find($fileId);
|
||||
|
||||
$file = $log->get_src('assets');
|
||||
|
||||
if ($log->action_type =='audit') {
|
||||
$file = $log->get_src('assets/audits');
|
||||
}
|
||||
|
||||
$filetype = Helper::checkUploadIsImage($file);
|
||||
|
||||
if ($filetype) {
|
||||
|
@ -1278,7 +1289,7 @@ class AssetsController extends Controller
|
|||
}
|
||||
|
||||
|
||||
public function auditStore(Request $request, $id)
|
||||
public function auditStore(AssetFileRequest $request, $id)
|
||||
{
|
||||
$this->authorize('audit', Asset::class);
|
||||
|
||||
|
@ -1288,11 +1299,13 @@ class AssetsController extends Controller
|
|||
);
|
||||
|
||||
$validator = \Validator::make($request->all(), $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, $validator->errors()->all()));
|
||||
}
|
||||
|
||||
$asset = Asset::findOrFail($id);
|
||||
|
||||
// We don't want to log this as a normal update, so let's bypass that
|
||||
$asset->unsetEventDispatcher();
|
||||
|
||||
|
@ -1300,7 +1313,23 @@ class AssetsController extends Controller
|
|||
$asset->last_audit_date = date('Y-m-d h:i:s');
|
||||
|
||||
if ($asset->save()) {
|
||||
$asset->logAudit(request('note'), request('location_id'));
|
||||
|
||||
|
||||
$filename = '';
|
||||
|
||||
if ($request->hasFile('image')) {
|
||||
$file = $request->file('image');
|
||||
try {
|
||||
$destinationPath = config('app.private_uploads').'/assets/audits';
|
||||
$extension = $file->getClientOriginalExtension();
|
||||
$filename = 'audit-'.$asset->id.'-'.str_slug($file->getClientOriginalName()).'.'.$extension;
|
||||
$file->move($destinationPath, $filename);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error($e);
|
||||
}
|
||||
}
|
||||
|
||||
$asset->logAudit($request->input('note'), $request->input('location_id'), $filename);
|
||||
return redirect()->to("hardware")->with('success', trans('admin/hardware/message.audit.success'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ class ActionlogsTransformer
|
|||
'id' => (int) $actionlog->id,
|
||||
'icon' => $actionlog->present()->icon(),
|
||||
'image' => (method_exists($actionlog->item, 'getImageUrl')) ? $actionlog->item->getImageUrl() : null,
|
||||
'file' => ($actionlog->filename!='') ? route('show/assetfile', ['assetId' => $actionlog->item->id, 'fileId' => $actionlog->id]) : null,
|
||||
'item' => ($actionlog->item) ? [
|
||||
'id' => (int) $actionlog->item->id,
|
||||
'name' => e($actionlog->item->getDisplayNameAttribute()),
|
||||
|
|
|
@ -163,7 +163,7 @@ trait Loggable
|
|||
* @since [v4.0]
|
||||
* @return \App\Models\Actionlog
|
||||
*/
|
||||
public function logAudit($note, $location_id)
|
||||
public function logAudit($note, $location_id, $filename = null)
|
||||
{
|
||||
$log = new Actionlog;
|
||||
$location = Location::find($location_id);
|
||||
|
@ -177,10 +177,12 @@ trait Loggable
|
|||
$log->location_id = ($location_id) ? $location_id : null;
|
||||
$log->note = $note;
|
||||
$log->user_id = Auth::user()->id;
|
||||
$log->filename = $filename;
|
||||
$log->logaction('audit');
|
||||
|
||||
$params = [
|
||||
'item' => $log->item,
|
||||
'filename' => $log->filename,
|
||||
'admin' => $log->user,
|
||||
'location' => ($location) ? $location->name : '',
|
||||
'note' => $note
|
||||
|
|
|
@ -12,4 +12,5 @@ return array(
|
|||
'submit' => 'Submit',
|
||||
'upload' => 'Upload',
|
||||
'select_file' => 'Select File...',
|
||||
'select_files' => 'Select Files...',
|
||||
);
|
||||
|
|
|
@ -20,7 +20,13 @@
|
|||
<!-- left column -->
|
||||
<div class="col-md-7">
|
||||
<div class="box box-default">
|
||||
<form class="form-horizontal" method="post" action="" autocomplete="off">
|
||||
|
||||
{{ Form::open([
|
||||
'method' => 'POST',
|
||||
'route' => ['asset.audit.store', $asset->id],
|
||||
'files' => true,
|
||||
'class' => 'form-horizontal' ]) }}
|
||||
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title"> {{ trans('admin/hardware/form.tag') }} {{ $asset->asset_tag }}</h3>
|
||||
</div>
|
||||
|
@ -71,6 +77,13 @@
|
|||
</div>
|
||||
|
||||
|
||||
<!-- Images -->
|
||||
@include ('partials.forms.edit.image-upload')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div> <!--/.box-body-->
|
||||
<div class="box-footer">
|
||||
|
|
|
@ -729,6 +729,8 @@
|
|||
data-side-pagination="server"
|
||||
data-show-columns="true"
|
||||
data-show-refresh="true"
|
||||
data-sort-order="desc"
|
||||
data-sort-name="created_at"
|
||||
data-show-export="true"
|
||||
data-export-options='{
|
||||
"fileName": "export{{ (Input::has('status')) ? '-'.str_slug(Input::get('status')) : '' }}-assets",
|
||||
|
@ -751,6 +753,7 @@
|
|||
@if ($snipeSettings->require_accept_signature=='1')
|
||||
<th class="col-md-3" data-field="signature_file" data-visible="false" data-formatter="imageFormatter">{{ trans('general.signature') }}</th>
|
||||
@endif
|
||||
<th class="col-md-3" data-visible="false" data-field="file" data-visible="false" data-formatter="imageFormatter">{{ trans('general.image') }}</th>
|
||||
<th class="col-sm-2" data-field="log_meta" data-visible="true" data-formatter="changeLogFormatter">Changed</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
|
@ -501,7 +501,7 @@
|
|||
}
|
||||
|
||||
|
||||
function imageFormatter(value, row) {
|
||||
function imageFormatter(value) {
|
||||
if (value) {
|
||||
return '<a href="' + value + '" data-toggle="lightbox" data-type="image"><img src="' + value + '" style="max-height: {{ $snipeSettings->thumbnail_max_h }}px; width: auto;" class="img-responsive"></a>';
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue