mirror of
https://github.com/grokability/snipe-it.git
synced 2026-03-12 17:52:00 +08:00
Commiting this so I don’t lose the history, but will open a smaller PR
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
@@ -119,7 +119,6 @@ class UploadedFilesController extends Controller
|
||||
*/
|
||||
public function store(UploadFileRequest $request, $object_type, $id) : JsonResponse
|
||||
{
|
||||
\Log::debug('store fired');
|
||||
|
||||
$object = self::$map_object_type[$object_type]::find($id);
|
||||
$this->authorize('view', $object);
|
||||
@@ -209,9 +208,10 @@ class UploadedFilesController extends Controller
|
||||
*/
|
||||
public function destroy($object_type, $id, $file_id) : JsonResponse
|
||||
{
|
||||
\Log::error('destroy called for '.$object_type.' with id '.$id.' and file_id '.$file_id);
|
||||
|
||||
$object = self::$map_object_type[$object_type]::find($id);
|
||||
$this->authorize('update', $file_id);
|
||||
$this->authorize('update', self::$map_object_type[$object_type]);
|
||||
|
||||
if (!$object) {
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.file_upload_status.invalid_object')));
|
||||
@@ -219,7 +219,7 @@ class UploadedFilesController extends Controller
|
||||
|
||||
|
||||
// Check for the file
|
||||
$log = Actionlog::find($file_id)->where('item_type', AssetModel::class)
|
||||
$log = Actionlog::find($file_id)->where('item_type', self::$map_object_type[$object_type])
|
||||
->where('item_id', $object->id)->first();
|
||||
|
||||
if ($log) {
|
||||
|
||||
@@ -29,14 +29,19 @@ class UploadedFilesTransformer
|
||||
$array = [
|
||||
'id' => (int) $file->id,
|
||||
'icon' => Helper::filetype_icon($file->filename),
|
||||
'name' => e($file->filename),
|
||||
'item' => ($file->item_type) ? [
|
||||
'id' => (int) $file->item_id,
|
||||
'type' => strtolower(class_basename($file->item_type)),
|
||||
] : null,
|
||||
'filename' => e($file->filename),
|
||||
'filetype' => StorageHelper::getFiletype($file->uploads_file_path()),
|
||||
'url' => $file->uploads_file_url(),
|
||||
'note' => ($file->note) ? e($file->note) : null,
|
||||
'created_by' => ($file->adminuser) ? [
|
||||
'id' => (int) $file->adminuser->id,
|
||||
'name'=> e($file->adminuser->present()->fullName),
|
||||
] : null,
|
||||
'note' => ($file->note) ? e($file->note) : null,
|
||||
'created_at' => Helper::getFormattedDateObject($file->created_at, 'datetime'),
|
||||
'deleted_at' => Helper::getFormattedDateObject($file->deleted_at, 'datetime'),
|
||||
'inline' => StorageHelper::allowSafeInline($file->uploads_file_path()),
|
||||
|
||||
@@ -91,7 +91,7 @@ class UploadsPresenter extends Presenter
|
||||
'sortable' => false,
|
||||
'switchable' => false,
|
||||
'title' => trans('table.actions'),
|
||||
'formatter' => $object.'ActionsFormatter',
|
||||
'formatter' => 'deleteUploadFormatter',
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
32
resources/views/blade/confirm-modal.blade.php
Normal file
32
resources/views/blade/confirm-modal.blade.php
Normal file
@@ -0,0 +1,32 @@
|
||||
{{-- IMPORTANT!!! Make sure there is no newline at the end of this file, or it will break the loaders for the tables --}}
|
||||
|
||||
@props([
|
||||
'route',
|
||||
'id',
|
||||
'method',
|
||||
])
|
||||
<div {{ $attributes->merge() }} id="dataConfirmModal" tabindex="-1" role="dialog"
|
||||
aria-labelledby="myModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h2 class="modal-title" id="myModalLabel"> </h2>
|
||||
</div>
|
||||
<div class="modal-body"></div>
|
||||
<div class="modal-footer">
|
||||
<form method="post" id="{{ isset($id) ?? $id }}" role="form"{!! isset($route) ?? ' action="'.route($route).'"' !!}>
|
||||
{{ csrf_field() }}
|
||||
{{ method_field('DELETE') }}
|
||||
|
||||
<button type="button" class="btn btn-default pull-left" data-dismiss="modal">
|
||||
{{ trans('general.cancel') }}
|
||||
</button>
|
||||
<button type="submit" class="btn btn-outline" id="dataConfirmOK">
|
||||
{{ trans('general.yes') }}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -14,7 +14,6 @@
|
||||
data-cookie-id-table="{{ str_slug($object->name ?? $object->id) }}UploadsTable"
|
||||
data-id-table="{{ str_slug($object->name ?? $object->id) }}UploadsTable"
|
||||
id="{{ str_slug($object->name ?? $object->id) }}UploadsTable"
|
||||
data-search="true"
|
||||
data-show-custom-view="true"
|
||||
data-custom-view="fileGalleryFormatter"
|
||||
data-show-custom-view-button="true"
|
||||
@@ -38,6 +37,7 @@
|
||||
}'>
|
||||
</table>
|
||||
|
||||
<!-- this is used by the bootstrap-table partial to format the file gallery -->
|
||||
<template id="fileGalleryTemplate">
|
||||
<div class="col-md-4">
|
||||
<div class="panel panel-%PANEL_CLASS%">
|
||||
|
||||
@@ -962,55 +962,8 @@ dir="{{ Helper::determineLanguageDirection() }}">
|
||||
|
||||
<!-- end main container -->
|
||||
|
||||
<div class="modal modal-danger fade" id="dataConfirmModal" tabindex="-1" role="dialog"
|
||||
aria-labelledby="myModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h2 class="modal-title" id="myModalLabel"> </h2>
|
||||
</div>
|
||||
<div class="modal-body"></div>
|
||||
<div class="modal-footer">
|
||||
<form method="post" id="deleteForm" role="form">
|
||||
{{ csrf_field() }}
|
||||
{{ method_field('DELETE') }}
|
||||
|
||||
<button type="button" class="btn btn-default pull-left"
|
||||
data-dismiss="modal">{{ trans('general.cancel') }}</button>
|
||||
<button type="submit" class="btn btn-outline"
|
||||
id="dataConfirmOK">{{ trans('general.yes') }}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="modal modal-warning fade" id="restoreConfirmModal" tabindex="-1" role="dialog"
|
||||
aria-labelledby="confirmModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title" id="confirmModalLabel"> </h4>
|
||||
</div>
|
||||
<div class="modal-body"></div>
|
||||
<div class="modal-footer">
|
||||
<form method="post" id="restoreForm" role="form">
|
||||
{{ csrf_field() }}
|
||||
{{ method_field('POST') }}
|
||||
|
||||
<button type="button" class="btn btn-default pull-left"
|
||||
data-dismiss="modal">{{ trans('general.cancel') }}</button>
|
||||
<button type="submit" class="btn btn-outline"
|
||||
id="dataConfirmOK">{{ trans('general.yes') }}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<x-confirm-modal class="modal modal-danger fade" id="deleteModal" method="DELETE"/>
|
||||
<x-confirm-modal class="modal modal-warning fade" id="restoreModal" method="POST"/>
|
||||
|
||||
|
||||
{{-- Javascript files --}}
|
||||
|
||||
@@ -345,11 +345,16 @@
|
||||
}
|
||||
|
||||
function deleteUploadFormatter(value, row) {
|
||||
|
||||
var item_type = row.item.type;
|
||||
if (item_type == 'assetmodel') {
|
||||
item_type = 'models'
|
||||
}
|
||||
if ((row.available_actions) && (row.available_actions.delete === true)) {
|
||||
return '<a href="{{ config('app.url') }}/' + dest + '/' + row.id + '" '
|
||||
return '<a href="{{ config('app.url') }}/' + item_type + '/' + row.item.id + '/showfile/' + row.id + '/delete" '
|
||||
+ ' class="actions btn btn-danger btn-sm delete-asset" data-tooltip="true" '
|
||||
+ ' data-toggle="modal" '
|
||||
+ ' data-content="{{ trans('general.file_upload_status.confirm_delete') }} ' + name_for_box + '?" '
|
||||
+ ' data-content="{{ trans('general.file_upload_status.confirm_delete') }} ' + row.filename + '?" '
|
||||
+ ' data-title="{{ trans('general.delete') }}" onClick="return false;">'
|
||||
+ '<x-icon type="delete" /><span class="sr-only">{{ trans('general.delete') }}</span></a> ';
|
||||
}
|
||||
@@ -952,6 +957,18 @@
|
||||
}
|
||||
}
|
||||
|
||||
function fileUploadDeleteFormatter(row, value) {
|
||||
|
||||
if ((value) && (value.filename) && (value.url)) {
|
||||
if (value.exists_on_disk) {
|
||||
return '<a href="' + value.url + '?inline=true" target="_blank">' + value.filename + '</a>';
|
||||
} else {
|
||||
return '<span data-tooltip="true" title="{{ trans('general.file_does_not_exist') }}"><x-icon type="x" class="text-danger" /> <del>' + value.filename + '</del></span>';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function linkToUserSectionBasedOnCount (count, id, section) {
|
||||
if (count) {
|
||||
return '<a href="{{ config('app.url') }}/users/' + id + '#' + section +'">' + count + '</a>';
|
||||
|
||||
@@ -1076,12 +1076,6 @@ Route::group(['prefix' => 'v1', 'middleware' => ['api', 'throttle:api']], functi
|
||||
]
|
||||
)->name('api.users.licenselist');
|
||||
|
||||
Route::post('{user}/upload',
|
||||
[
|
||||
Api\UsersController::class,
|
||||
'postUpload'
|
||||
]
|
||||
)->name('api.users.uploads');
|
||||
|
||||
Route::post('{user}/restore',
|
||||
[
|
||||
|
||||
@@ -5,7 +5,6 @@ use App\Http\Controllers\Assets\AssetsController;
|
||||
use App\Http\Controllers\Assets\BulkAssetsController;
|
||||
use App\Http\Controllers\Assets\AssetCheckoutController;
|
||||
use App\Http\Controllers\Assets\AssetCheckinController;
|
||||
use App\Http\Controllers\Assets\AssetFilesController;
|
||||
use App\Models\Setting;
|
||||
use Tabuna\Breadcrumbs\Trail;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
@@ -141,17 +140,6 @@ Route::group(
|
||||
[AssetsController::class, 'getRestore']
|
||||
)->name('restore/hardware')->withTrashed();
|
||||
|
||||
Route::post('{asset}/upload',
|
||||
[AssetFilesController::class, 'store']
|
||||
)->name('upload/asset')->withTrashed();
|
||||
|
||||
Route::get('{asset}/showfile/{fileId}/{download?}',
|
||||
[AssetFilesController::class, 'show']
|
||||
)->name('show/assetfile')->withTrashed();
|
||||
|
||||
Route::delete('{asset}/showfile/{fileId}/delete',
|
||||
[AssetFilesController::class, 'destroy']
|
||||
)->name('delete/assetfile')->withTrashed();
|
||||
|
||||
Route::post(
|
||||
'bulkedit',
|
||||
|
||||
@@ -11,6 +11,10 @@ use Tabuna\Breadcrumbs\Trail;
|
||||
|
||||
Route::group(['prefix' => 'models', 'middleware' => ['auth']], function () {
|
||||
|
||||
Route::delete('{model}/showfile/{fileId}/delete',
|
||||
[AssetModelsFilesController::class, 'destroy']
|
||||
)->name('delete/modelfile')->withTrashed();
|
||||
|
||||
Route::post('{model}/upload',
|
||||
[AssetModelsFilesController::class, 'store']
|
||||
)->name('upload/models')->withTrashed();
|
||||
@@ -19,9 +23,7 @@ Route::group(['prefix' => 'models', 'middleware' => ['auth']], function () {
|
||||
[AssetModelsFilesController::class, 'show']
|
||||
)->name('show/modelfile')->withTrashed();
|
||||
|
||||
Route::delete('{model}/showfile/{fileId}/delete',
|
||||
[AssetModelsFilesController::class, 'destroy']
|
||||
)->name('delete/modelfile')->withTrashed();
|
||||
|
||||
|
||||
Route::get(
|
||||
'{model}/clone',
|
||||
|
||||
Reference in New Issue
Block a user