Compare commits

...

1 Commits

Author SHA1 Message Date
snipe
8450d1931d Fixed audit images not showing inline 2025-10-21 12:08:35 +01:00
9 changed files with 45 additions and 45 deletions

View File

@@ -51,14 +51,21 @@ class UploadedFilesController extends Controller
];
$uploads = self::$map_object_type[$object_type]::withTrashed()->find($id)->uploads()
->with('adminuser');
if (($request->filled('action_type') && ($request->input('action_type') == 'audit'))) {
$uploads = self::$map_object_type[$object_type]::withTrashed()->find($id)->audits()
->with('adminuser');
} else {
$uploads = self::$map_object_type[$object_type]::withTrashed()->find($id)->uploads()
->with('adminuser');
}
$offset = ($request->input('offset') > $uploads->count()) ? $uploads->count() : abs($request->input('offset'));
$limit = app('api_limit_value');
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
// Text search on action_logs fields
// We could use the normal Actionlogs text scope, but it's a very heavy query since it's searching across all relations
// and we generally won't need that here

View File

@@ -45,6 +45,7 @@ abstract class Controller extends BaseController
'accessories' => Accessory::class,
'maintenances' => Maintenance::class,
'assets' => Asset::class,
'audits' => Asset::class,
'components' => Component::class,
'consumables' => Consumable::class,
'hardware' => Asset::class,
@@ -58,6 +59,7 @@ abstract class Controller extends BaseController
'accessories' => 'private_uploads/accessories/',
'maintenances' => 'private_uploads/maintenances/',
'assets' => 'private_uploads/assets/',
'audits' => 'private_uploads/audits/',
'components' => 'private_uploads/components/',
'consumables' => 'private_uploads/consumables/',
'hardware' => 'private_uploads/assets/',
@@ -71,6 +73,7 @@ abstract class Controller extends BaseController
'accessories' => 'accessory',
'maintenances' => 'maintenance',
'assets' => 'asset',
'audits' => 'audit',
'components' => 'component',
'consumables' => 'consumable',
'hardware' => 'asset',

View File

@@ -149,6 +149,7 @@ class ActionlogsTransformer
'filename' => $actionlog->filename,
'inlineable' => StorageHelper::allowSafeInline($actionlog->uploads_file_path()),
'exists_on_disk' => Storage::exists($actionlog->uploads_file_path()) ? true : false,
'mediatype' => StorageHelper::getMediaType($actionlog->uploads_file_path()),
] : null,
'item' => ($actionlog->item) ? [

View File

@@ -466,8 +466,6 @@ class Actionlog extends SnipeModel
public function uploads_file_url()
{
if (($this->action_type == 'accepted') || ($this->action_type == 'declined')) {
return route('log.storedeula.download', ['filename' => $this->filename]);
}
@@ -478,6 +476,11 @@ class Actionlog extends SnipeModel
$object = 'models';
}
// @todo - remove audit special case when audits have their own file handling route
if ($this->action_type == 'audit') {
$object = 'audits';
}
return route('ui.files.show', [
'object_type' => $object,
'id' => $this->item_id,

View File

@@ -12,7 +12,7 @@ class UploadedFilesPresenter extends Presenter
*
* @return string
*/
public static function dataTableLayout()
public static function dataTableLayout($allow_deletes = true)
{
$layout = [
@@ -84,7 +84,11 @@ class UploadedFilesPresenter extends Presenter
'title' => trans('general.created_at'),
'visible' => true,
'formatter' => 'dateDisplayFormatter',
], [
],
];
if ($allow_deletes == 'true') {
$layout[] = [
'field' => 'available_actions',
'searchable' => false,
'sortable' => false,
@@ -92,8 +96,8 @@ class UploadedFilesPresenter extends Presenter
'title' => trans('table.actions'),
'visible' => true,
'formatter' => 'deleteUploadFormatter',
],
];
];
}
return json_encode($layout);
}

View File

@@ -2,12 +2,14 @@
@props([
'object',
'object_type' => '',
'action_type' => null,
'allow_deletes' => true,
])
<!-- begin non-ajaxed file listing table -->
<div class="table-responsive">
<table
data-columns="{{ \App\Presenters\UploadedFilesPresenter::dataTableLayout() }}"
data-columns="{{ \App\Presenters\UploadedFilesPresenter::dataTableLayout($allow_deletes) }}"
data-cookie-id-table="{{ $object_type }}-FileUploadsTable"
data-id-table="{{ $object_type }}-FileUploadsTable"
id="{{ $object_type }}-FileUploadsTable"
@@ -18,7 +20,11 @@
data-show-custom-view="true"
data-custom-view="customViewFormatter"
data-show-custom-view-button="true"
data-url="{{ route('api.files.index', ['object_type' => $object_type, 'id' => $object->id]) }}"
data-url="{{ route('api.files.index', [
'object_type' => $object_type,
'id' => $object->id,
'action_type' => $action_type]
) }}"
class="table table-striped snipe-table"
data-export-options='{
"fileName": "export-uploads-{{ str_slug($object->name) }}-{{ date('Y-m-d') }}",

View File

@@ -1372,35 +1372,11 @@
<!-- checked out assets table -->
<div class="row">
<div class="col-md-12">
<table
class="table table-striped snipe-table"
id="assetAuditHistory"
data-id-table="assetAuditHistory"
data-side-pagination="server"
data-sort-order="desc"
data-sort-name="created_at"
data-export-options='{
"fileName": "export-asset-{{ $asset->id }}-audits",
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
}'
data-url="{{ route('api.activity.index', ['item_id' => $asset->id, 'item_type' => 'asset', 'action_type' => 'audit']) }}"
data-cookie-id-table="assetHistory"
data-cookie="true">
<thead>
<tr>
<th data-visible="true" data-field="icon" style="width: 40px;" class="hidden-xs" data-formatter="iconFormatter">{{ trans('admin/hardware/table.icon') }}</th>
<th data-visible="true" data-field="created_at" data-sortable="true" data-formatter="dateDisplayFormatter">{{ trans('general.date') }}</th>
<th data-visible="true" data-field="admin" data-formatter="usersLinkObjFormatter">{{ trans('general.created_by') }}</th>
<th class="col-sm-2" data-field="file" data-sortable="true" data-visible="false" data-formatter="fileNameFormatter">{{ trans('general.file_name') }}</th>
<th data-field="note">{{ trans('general.notes') }}</th>
<th data-visible="false" data-field="file" data-visible="false" data-formatter="fileDownloadButtonsFormatter">{{ trans('general.download') }}</th>
<th data-field="log_meta" data-visible="true" data-formatter="changeLogFormatter">{{ trans('admin/hardware/table.changed')}}</th>
<th data-field="remote_ip" data-visible="false" data-sortable="true">{{ trans('admin/settings/general.login_ip') }}</th>
<th data-field="user_agent" data-visible="false" data-sortable="true">{{ trans('admin/settings/general.login_user_agent') }}</th>
<th data-field="action_source" data-visible="false" data-sortable="true">{{ trans('general.action_source') }}</th>
</tr>
</thead>
</table>
<x-filestable
object_type="assets"
action_type="audit"
allow_deletes="false"
:object="$asset" />
</div>
</div> <!-- /.row -->
</div> <!-- /.tab-pane history -->

View File

@@ -1348,7 +1348,7 @@ Route::group(['prefix' => 'v1', 'middleware' => ['api', 'api-throttle:api']], fu
'index'
]
)->name('api.files.index')
->where(['object_type' => 'accessories|assets|components|consumables|hardware|licenses|locations|maintenances|models|users']);
->where(['object_type' => 'accessories|audits|assets|components|consumables|hardware|licenses|locations|maintenances|models|users']);
// Get a file
Route::get('{object_type}/{id}/files/{file_id}',
@@ -1357,7 +1357,7 @@ Route::group(['prefix' => 'v1', 'middleware' => ['api', 'api-throttle:api']], fu
'show'
]
)->name('api.files.show')
->where(['object_type' => 'accessories|assets|components|consumables|hardware|licenses|locations|maintenances|models|users']);
->where(['object_type' => 'accessories|audits|assets|components|consumables|hardware|licenses|locations|maintenances|models|users']);
// Upload files(s)
Route::post('{object_type}/{id}/files',
@@ -1366,7 +1366,7 @@ Route::group(['prefix' => 'v1', 'middleware' => ['api', 'api-throttle:api']], fu
'store'
]
)->name('api.files.store')
->where(['object_type' => 'accessories|assets|components|consumables|hardware|licenses|locations|maintenances|models|users']);
->where(['object_type' => 'accessories|audits|assets|components|consumables|hardware|licenses|locations|maintenances|models|users']);
// Delete files(s)
Route::delete('{object_type}/{id}/files/{file_id}/delete',

View File

@@ -716,7 +716,7 @@ Route::group(['middleware' => 'web'], function () {
'show'
]
)->name('ui.files.show')
->where(['object_type' => 'assets|maintenances|hardware|models|users|locations|accessories|consumables|licenses|components']);
->where(['object_type' => 'accessories|audits|assets|components|consumables|hardware|licenses|locations|maintenances|models|users']);
// Upload files(s)
Route::post('{object_type}/{id}/files',
@@ -725,7 +725,7 @@ Route::group(['middleware' => 'web'], function () {
'store'
]
)->name('ui.files.store')
->where(['object_type' => 'assets|maintenances|hardware|models|users|locations|accessories|consumables|licenses|components']);
->where(['object_type' => 'accessories|audits|assets|components|consumables|hardware|licenses|locations|maintenances|models|users']);
// Delete files(s)
Route::delete('{object_type}/{id}/files/{file_id}/delete',
@@ -734,7 +734,7 @@ Route::group(['middleware' => 'web'], function () {
'destroy'
]
)->name('ui.files.destroy')
->where(['object_type' => 'assets|maintenances|hardware|models|users|locations|accessories|consumables|licenses|components']);
->where(['object_type' => 'accessories|assets|components|consumables|hardware|licenses|locations|maintenances|models|users']);
});