diff --git a/app/Http/Controllers/Accessories/AccessoriesFilesController.php b/app/Http/Controllers/Accessories/AccessoriesFilesController.php new file mode 100644 index 0000000000..cc6dcfb97f --- /dev/null +++ b/app/Http/Controllers/Accessories/AccessoriesFilesController.php @@ -0,0 +1,177 @@ +] + * @since [v1.0] + * @param AssetFileRequest $request + * @param int $accessoryId + * @return \Illuminate\Http\RedirectResponse + * @throws \Illuminate\Auth\Access\AuthorizationException + */ + public function store(AssetFileRequest $request, $accessoryId = null) + { + $accessory = Accessory::find($accessoryId); + + if (isset($accessory->id)) { + $this->authorize('update', $accessory); + + if ($request->hasFile('file')) { + if (! Storage::exists('private_uploads/accessories')) { + Storage::makeDirectory('private_uploads/accessories', 775); + } + + foreach ($request->file('file') as $file) { + + $extension = $file->getClientOriginalExtension(); + $file_name = 'accessory-'.$accessory->id.'-'.str_random(8).'-'.str_slug(basename($file->getClientOriginalName(), '.'.$extension)).'.'.$extension; + + + // Check for SVG and sanitize it + if ($extension == 'svg') { + \Log::debug('This is an SVG'); + \Log::debug($file_name); + + $sanitizer = new Sanitizer(); + $dirtySVG = file_get_contents($file->getRealPath()); + $cleanSVG = $sanitizer->sanitize($dirtySVG); + + try { + Storage::put('private_uploads/accessories/'.$file_name, $cleanSVG); + } catch (\Exception $e) { + \Log::debug('Upload no workie :( '); + \Log::debug($e); + } + + } else { + Storage::put('private_uploads/accessories/'.$file_name, file_get_contents($file)); + } + + //Log the upload to the log + $accessory->logUpload($file_name, e($request->input('notes'))); + } + + + return redirect()->route('accessories.show', $accessory->id)->with('success', trans('general.file_upload_success')); + + } + + return redirect()->route('accessories.show', $accessory->id)->with('error', trans('general.no_files_uploaded')); + } + // Prepare the error message + return redirect()->route('accessories.index') + ->with('error', trans('general.file_does_not_exist')); + } + + /** + * Deletes the selected accessory file. + * + * @author [A. Gianotto] [] + * @since [v1.0] + * @param int $accessoryId + * @param int $fileId + * @return \Illuminate\Http\RedirectResponse + * @throws \Illuminate\Auth\Access\AuthorizationException + */ + public function destroy($accessoryId = null, $fileId = null) + { + $accessory = Accessory::find($accessoryId); + + // the asset is valid + if (isset($accessory->id)) { + $this->authorize('update', $accessory); + $log = Actionlog::find($fileId); + + // Remove the file if one exists + if (Storage::exists('accessories/'.$log->filename)) { + try { + Storage::delete('accessories/'.$log->filename); + } catch (\Exception $e) { + \Log::debug($e); + } + } + + $log->delete(); + + return redirect()->back() + ->with('success', trans('admin/hardware/message.deletefile.success')); + } + + // Redirect to the licence management page + return redirect()->route('accessories.index')->with('error', trans('general.file_does_not_exist')); + } + + /** + * Allows the selected file to be viewed. + * + * @author [A. Gianotto] [] + * @since [v1.4] + * @param int $accessoryId + * @param int $fileId + * @return \Symfony\Accessory\HttpFoundation\Response + * @throws \Illuminate\Auth\Access\AuthorizationException + */ + public function show($accessoryId = null, $fileId = null, $download = true) + { + \Log::debug('Private filesystem is: '.config('filesystems.default')); + $accessory = Accessory::find($accessoryId); + + // the accessory is valid + if (isset($accessory->id)) { + $this->authorize('view', $accessory); + $this->authorize('accessories.files', $accessory); + + if (! $log = Actionlog::find($fileId)) { + return response('No matching record for that asset/file', 500) + ->header('Content-Type', 'text/plain'); + } + + $file = 'private_uploads/accessories/'.$log->filename; + + if (Storage::missing($file)) { + \Log::debug('FILE DOES NOT EXISTS for '.$file); + \Log::debug('URL should be '.Storage::url($file)); + + return response('File '.$file.' ('.Storage::url($file).') not found on server', 404) + ->header('Content-Type', 'text/plain'); + } else { + + // We have to override the URL stuff here, since local defaults in Laravel's Flysystem + // won't work, as they're not accessible via the web + if (config('filesystems.default') == 'local') { // TODO - is there any way to fix this at the StorageHelper layer? + return StorageHelper::downloader($file); + } else { + if ($download != 'true') { + \Log::debug('display the file'); + if ($contents = file_get_contents(Storage::url($file))) { // TODO - this will fail on private S3 files or large public ones + return Response::make(Storage::url($file)->header('Content-Type', mime_content_type($file))); + } + + return JsonResponse::create(['error' => 'Failed validation: '], 500); + } + + return StorageHelper::downloader($file); + + } + } + } + + return redirect()->route('accessories.index')->with('error', trans('general.file_does_not_exist', ['id' => $fileId])); + } +} diff --git a/app/Http/Controllers/Api/ConsumablesController.php b/app/Http/Controllers/Api/ConsumablesController.php index ebc27c608f..fc6620df48 100644 --- a/app/Http/Controllers/Api/ConsumablesController.php +++ b/app/Http/Controllers/Api/ConsumablesController.php @@ -228,6 +228,7 @@ class ConsumablesController extends Controller foreach ($consumable->consumableAssignments as $consumable_assignment) { $rows[] = [ + 'avatar' => ($consumable_assignment->user) ? e($consumable_assignment->user->present()->gravatar) : '', 'name' => ($consumable_assignment->user) ? $consumable_assignment->user->present()->nameUrl() : 'Deleted User', 'created_at' => Helper::getFormattedDateObject($consumable_assignment->created_at, 'datetime'), 'note' => ($consumable_assignment->note) ? e($consumable_assignment->note) : null, diff --git a/app/Http/Controllers/Components/ComponentsFilesController.php b/app/Http/Controllers/Components/ComponentsFilesController.php new file mode 100644 index 0000000000..d9f59f1d90 --- /dev/null +++ b/app/Http/Controllers/Components/ComponentsFilesController.php @@ -0,0 +1,175 @@ +] + * @since [v1.0] + * @param AssetFileRequest $request + * @param int $componentId + * @return \Illuminate\Http\RedirectResponse + * @throws \Illuminate\Auth\Access\AuthorizationException + */ + public function store(AssetFileRequest $request, $componentId = null) + { + $component = Component::find($componentId); + + if (isset($component->id)) { + $this->authorize('update', $component); + + if ($request->hasFile('file')) { + if (! Storage::exists('private_uploads/components')) { + Storage::makeDirectory('private_uploads/components', 775); + } + + foreach ($request->file('file') as $file) { + + $extension = $file->getClientOriginalExtension(); + $file_name = 'component-'.$component->id.'-'.str_random(8).'-'.str_slug(basename($file->getClientOriginalName(), '.'.$extension)).'.'.$extension; + + + // Check for SVG and sanitize it + if ($extension == 'svg') { + \Log::debug('This is an SVG'); + \Log::debug($file_name); + + $sanitizer = new Sanitizer(); + $dirtySVG = file_get_contents($file->getRealPath()); + $cleanSVG = $sanitizer->sanitize($dirtySVG); + + try { + Storage::put('private_uploads/components/'.$file_name, $cleanSVG); + } catch (\Exception $e) { + \Log::debug('Upload no workie :( '); + \Log::debug($e); + } + + } else { + Storage::put('private_uploads/components/'.$file_name, file_get_contents($file)); + } + + //Log the upload to the log + $component->logUpload($file_name, e($request->input('notes'))); + } + + + return redirect()->route('components.show', $component->id)->with('success', trans('general.file_upload_success')); + + } + + return redirect()->route('components.show', $component->id)->with('error', trans('general.no_files_uploaded')); + } + // Prepare the error message + return redirect()->route('components.index') + ->with('error', trans('general.file_does_not_exist')); + } + + /** + * Deletes the selected component file. + * + * @author [A. Gianotto] [] + * @since [v1.0] + * @param int $componentId + * @param int $fileId + * @return \Illuminate\Http\RedirectResponse + * @throws \Illuminate\Auth\Access\AuthorizationException + */ + public function destroy($componentId = null, $fileId = null) + { + $component = Component::find($componentId); + + // the asset is valid + if (isset($component->id)) { + $this->authorize('update', $component); + $log = Actionlog::find($fileId); + + // Remove the file if one exists + if (Storage::exists('components/'.$log->filename)) { + try { + Storage::delete('components/'.$log->filename); + } catch (\Exception $e) { + \Log::debug($e); + } + } + + $log->delete(); + + return redirect()->back() + ->with('success', trans('admin/hardware/message.deletefile.success')); + } + + // Redirect to the licence management page + return redirect()->route('components.index')->with('error', trans('general.file_does_not_exist')); + } + + /** + * Allows the selected file to be viewed. + * + * @author [A. Gianotto] [] + * @since [v1.4] + * @param int $componentId + * @param int $fileId + * @return \Symfony\Component\HttpFoundation\Response + * @throws \Illuminate\Auth\Access\AuthorizationException + */ + public function show($componentId = null, $fileId = null, $download = true) + { + \Log::debug('Private filesystem is: '.config('filesystems.default')); + $component = Component::find($componentId); + + // the component is valid + if (isset($component->id)) { + $this->authorize('view', $component); + $this->authorize('components.files', $component); + + if (! $log = Actionlog::find($fileId)) { + return response('No matching record for that asset/file', 500) + ->header('Content-Type', 'text/plain'); + } + + $file = 'private_uploads/components/'.$log->filename; + + if (Storage::missing($file)) { + \Log::debug('FILE DOES NOT EXISTS for '.$file); + \Log::debug('URL should be '.Storage::url($file)); + + return response('File '.$file.' ('.Storage::url($file).') not found on server', 404) + ->header('Content-Type', 'text/plain'); + } else { + + if (config('filesystems.default') == 'local') { // TODO - is there any way to fix this at the StorageHelper layer? + return StorageHelper::downloader($file); + } else { + if ($download != 'true') { + \Log::debug('display the file'); + if ($contents = file_get_contents(Storage::url($file))) { // TODO - this will fail on private S3 files or large public ones + return Response::make(Storage::url($file)->header('Content-Type', mime_content_type($file))); + } + + return JsonResponse::create(['error' => 'Failed validation: '], 500); + } + + return StorageHelper::downloader($file); + + } + } + } + + return redirect()->route('components.index')->with('error', trans('general.file_does_not_exist', ['id' => $fileId])); + } +} diff --git a/app/Http/Controllers/Consumables/ConsumablesFilesController.php b/app/Http/Controllers/Consumables/ConsumablesFilesController.php new file mode 100644 index 0000000000..51c0d3bf8c --- /dev/null +++ b/app/Http/Controllers/Consumables/ConsumablesFilesController.php @@ -0,0 +1,176 @@ +] + * @since [v1.0] + * @param AssetFileRequest $request + * @param int $consumableId + * @return \Illuminate\Http\RedirectResponse + * @throws \Illuminate\Auth\Access\AuthorizationException + */ + public function store(AssetFileRequest $request, $consumableId = null) + { + $consumable = Consumable::find($consumableId); + + if (isset($consumable->id)) { + $this->authorize('update', $consumable); + + if ($request->hasFile('file')) { + if (! Storage::exists('private_uploads/consumables')) { + Storage::makeDirectory('private_uploads/consumables', 775); + } + + foreach ($request->file('file') as $file) { + + $extension = $file->getClientOriginalExtension(); + $file_name = 'consumable-'.$consumable->id.'-'.str_random(8).'-'.str_slug(basename($file->getClientOriginalName(), '.'.$extension)).'.'.$extension; + + + // Check for SVG and sanitize it + if ($extension == 'svg') { + \Log::debug('This is an SVG'); + \Log::debug($file_name); + + $sanitizer = new Sanitizer(); + $dirtySVG = file_get_contents($file->getRealPath()); + $cleanSVG = $sanitizer->sanitize($dirtySVG); + + try { + Storage::put('private_uploads/consumables/'.$file_name, $cleanSVG); + } catch (\Exception $e) { + \Log::debug('Upload no workie :( '); + \Log::debug($e); + } + + } else { + Storage::put('private_uploads/consumables/'.$file_name, file_get_contents($file)); + } + + //Log the upload to the log + $consumable->logUpload($file_name, e($request->input('notes'))); + } + + + return redirect()->route('consumables.show', $consumable->id)->with('success', trans('general.file_upload_success')); + + } + + return redirect()->route('consumables.show', $consumable->id)->with('error', trans('general.no_files_uploaded')); + } + // Prepare the error message + return redirect()->route('consumables.index') + ->with('error', trans('general.file_does_not_exist')); + } + + /** + * Deletes the selected consumable file. + * + * @author [A. Gianotto] [] + * @since [v1.0] + * @param int $consumableId + * @param int $fileId + * @return \Illuminate\Http\RedirectResponse + * @throws \Illuminate\Auth\Access\AuthorizationException + */ + public function destroy($consumableId = null, $fileId = null) + { + $consumable = Consumable::find($consumableId); + + // the asset is valid + if (isset($consumable->id)) { + $this->authorize('update', $consumable); + $log = Actionlog::find($fileId); + + // Remove the file if one exists + if (Storage::exists('consumables/'.$log->filename)) { + try { + Storage::delete('consumables/'.$log->filename); + } catch (\Exception $e) { + \Log::debug($e); + } + } + + $log->delete(); + + return redirect()->back() + ->with('success', trans('admin/hardware/message.deletefile.success')); + } + + // Redirect to the licence management page + return redirect()->route('consumables.index')->with('error', trans('general.file_does_not_exist')); + } + + /** + * Allows the selected file to be viewed. + * + * @author [A. Gianotto] [] + * @since [v1.4] + * @param int $consumableId + * @param int $fileId + * @return \Symfony\Consumable\HttpFoundation\Response + * @throws \Illuminate\Auth\Access\AuthorizationException + */ + public function show($consumableId = null, $fileId = null, $download = true) + { + $consumable = Consumable::find($consumableId); + + // the consumable is valid + if (isset($consumable->id)) { + $this->authorize('view', $consumable); + $this->authorize('consumables.files', $consumable); + + if (! $log = Actionlog::find($fileId)) { + return response('No matching record for that asset/file', 500) + ->header('Content-Type', 'text/plain'); + } + + $file = 'private_uploads/consumables/'.$log->filename; + + if (Storage::missing($file)) { + \Log::debug('FILE DOES NOT EXISTS for '.$file); + \Log::debug('URL should be '.Storage::url($file)); + + return response('File '.$file.' ('.Storage::url($file).') not found on server', 404) + ->header('Content-Type', 'text/plain'); + } else { + + // We have to override the URL stuff here, since local defaults in Laravel's Flysystem + // won't work, as they're not accessible via the web + if (config('filesystems.default') == 'local') { // TODO - is there any way to fix this at the StorageHelper layer? + return StorageHelper::downloader($file); + } else { + if ($download != 'true') { + \Log::debug('display the file'); + if ($contents = file_get_contents(Storage::url($file))) { // TODO - this will fail on private S3 files or large public ones + return Response::make(Storage::url($file)->header('Content-Type', mime_content_type($file))); + } + + return JsonResponse::create(['error' => 'Failed validation: '], 500); + } + + return StorageHelper::downloader($file); + + } + } + } + + return redirect()->route('consumables.index')->with('error', trans('general.file_does_not_exist', ['id' => $fileId])); + } +} diff --git a/app/Models/Accessory.php b/app/Models/Accessory.php index 1f2f50463c..3f2004b047 100755 --- a/app/Models/Accessory.php +++ b/app/Models/Accessory.php @@ -101,6 +101,23 @@ class Accessory extends SnipeModel + /** + * Establishes the accessories -> action logs -> uploads relationship + * + * @author A. Gianotto + * @since [v6.1.13] + * @return \Illuminate\Database\Eloquent\Relations\Relation + */ + public function uploads() + { + return $this->hasMany(\App\Models\Actionlog::class, 'item_id') + ->where('item_type', '=', self::class) + ->where('action_type', '=', 'uploaded') + ->whereNotNull('filename') + ->orderBy('created_at', 'desc'); + } + + /** * Establishes the accessory -> supplier relationship * diff --git a/app/Models/Component.php b/app/Models/Component.php index 79d2fe55f2..dc353d288c 100644 --- a/app/Models/Component.php +++ b/app/Models/Component.php @@ -88,6 +88,24 @@ class Component extends SnipeModel 'location' => ['name'], ]; + + /** + * Establishes the components -> action logs -> uploads relationship + * + * @author A. Gianotto + * @since [v6.1.13] + * @return \Illuminate\Database\Eloquent\Relations\Relation + */ + public function uploads() + { + return $this->hasMany(\App\Models\Actionlog::class, 'item_id') + ->where('item_type', '=', self::class) + ->where('action_type', '=', 'uploaded') + ->whereNotNull('filename') + ->orderBy('created_at', 'desc'); + } + + /** * Establishes the component -> location relationship * diff --git a/app/Models/Consumable.php b/app/Models/Consumable.php index ac4b8fd9d4..c04c9b53d5 100644 --- a/app/Models/Consumable.php +++ b/app/Models/Consumable.php @@ -96,6 +96,24 @@ class Consumable extends SnipeModel 'manufacturer' => ['name'], ]; + + /** + * Establishes the components -> action logs -> uploads relationship + * + * @author A. Gianotto + * @since [v6.1.13] + * @return \Illuminate\Database\Eloquent\Relations\Relation + */ + public function uploads() + { + return $this->hasMany(\App\Models\Actionlog::class, 'item_id') + ->where('item_type', '=', self::class) + ->where('action_type', '=', 'uploaded') + ->whereNotNull('filename') + ->orderBy('created_at', 'desc'); + } + + /** * Sets the attribute of whether or not the consumable is requestable * diff --git a/app/Models/SnipeSCIMConfig.php b/app/Models/SnipeSCIMConfig.php index 221bf7d2e9..36a9ac855c 100644 --- a/app/Models/SnipeSCIMConfig.php +++ b/app/Models/SnipeSCIMConfig.php @@ -41,8 +41,10 @@ class SnipeSCIMConfig extends \ArieTimmerman\Laravel\SCIMServer\SCIMConfig } ); - $config['validations'][$core.'externalId'] = 'string'; // not required, but supported mostly just for Okta - $mappings['externalId'] = AttributeMapping::eloquent('scim_externalid'); + // externalId support + $config['validations'][$core.'externalId'] = 'string|nullable'; // not required, but supported mostly just for Okta + // note that the mapping is *not* namespaced like the other $mappings + $config['mapping']['externalId'] = AttributeMapping::eloquent('scim_externalid'); $config['validations'][$core.'emails'] = 'nullable|array'; // emails are not required in Snipe-IT... $config['validations'][$core.'emails.*.value'] = 'email'; // ...(had to remove the recommended 'required' here) diff --git a/app/Models/User.php b/app/Models/User.php index 09e3509124..8211fabd63 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -61,6 +61,7 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo 'remote', 'start_date', 'end_date', + 'scim_externalid' ]; protected $casts = [ diff --git a/config/permissions.php b/config/permissions.php index 2af54d615a..adb216b960 100644 --- a/config/permissions.php +++ b/config/permissions.php @@ -145,6 +145,13 @@ return [ 'note' => '', 'display' => true, ], + [ + 'permission' => 'accessories.files', + 'label' => 'View and Modify Accessory Files', + 'note' => '', + 'display' => true, + ], + ], 'Consumables' => [ @@ -178,6 +185,12 @@ return [ 'note' => '', 'display' => true, ], + [ + 'permission' => 'consumables.files', + 'label' => 'View and Modify Consumable Files', + 'note' => '', + 'display' => true, + ], ], @@ -264,6 +277,12 @@ return [ 'note' => '', 'display' => true, ], + [ + 'permission' => 'components.files', + 'label' => 'View and Modify Component Files', + 'note' => '', + 'display' => true, + ], ], diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index be18b9c0ef..bcc08dafd4 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -280,6 +280,9 @@ return [ 'yes' => 'Yes', 'zip' => 'Zip', 'noimage' => 'No image uploaded or image not found.', + 'file_does_not_exist' => 'The requested file does not exist on the server.', + 'file_upload_success' => 'File upload success!', + 'no_files_uploaded' => 'File upload success!', 'token_expired' => 'Your form session has expired. Please try again.', 'login_enabled' => 'Login Enabled', 'audit_due' => 'Due for Audit', diff --git a/resources/views/accessories/view.blade.php b/resources/views/accessories/view.blade.php index c85acefe35..82ff8efc44 100644 --- a/resources/views/accessories/view.blade.php +++ b/resources/views/accessories/view.blade.php @@ -46,65 +46,234 @@ {{-- Page content --}} @section('content') + {{-- Page content --}} +
+
- - + + + +@can('update', Accessory::class) + @include ('modals.upload-file', ['item_type' => 'accessory', 'item_id' => $accessory->id]) +@endcan @stop - - - - - - @section('moar_scripts') @include ('partials.bootstrap-table') @stop diff --git a/resources/views/components/view.blade.php b/resources/views/components/view.blade.php index 3b08cf236a..d7b494566b 100644 --- a/resources/views/components/view.blade.php +++ b/resources/views/components/view.blade.php @@ -48,61 +48,188 @@ @endcan @stop - {{-- Page content --}} @section('content') - +{{-- Page content --}}
-
-
-
-
-
- + + + + + @can('components.files', $component) +
  • + + + + +
  • + @endcan + + @can('update', Component::class) + +
  • + + {{ trans('button.upload') }} + +
  • + @endcan + + +
    + +
    +
    + +
    + + + + + + + + + +
    + {{ trans('general.asset') }} + + {{ trans('general.qty') }} + + {{ trans('general.notes') }} + + {{ trans('general.date') }} + + {{ trans('general.checkin') }}/{{ trans('general.checkout') }} +
    + +
    +
    + + + @can('components.files', $component) +
    + +
    + - - - - - + + + + + + + + -
    - {{ trans('general.asset') }} - - {{ trans('general.qty') }} - - {{ trans('general.notes') }} - - {{ trans('general.date') }} - - {{ trans('general.checkin') }}/{{ trans('general.checkout') }} - {{trans('general.file_type')}}{{ trans('general.image') }}{{ trans('general.file_name') }}{{ trans('general.filesize') }}{{ trans('general.notes') }}{{ trans('general.download') }}{{ trans('general.created_at') }}{{ trans('table.actions') }}
    + + @if ($component->uploads->count() > 0) + @foreach ($component->uploads as $file) + + + + {{ Helper::filetype_icon($file->filename) }} + + + @if ($file->filename) + @if ( Helper::checkUploadIsImage($file->get_src('components'))) + + @endif + @endif + + + {{ $file->filename }} + + + {{ @Helper::formatFilesizeUnits(Storage::exists('private_uploads/components/'.$file->filename) ? Storage::size('private_uploads/components/'.$file->filename) : '') }} + + + + @if ($file->note) + {{ $file->note }} + @endif + + + @if ($file->filename) + + + {{ trans('general.download') }} + + @endif + + {{ $file->created_at }} + + + + {{ trans('general.delete') }} + + + + @endforeach + @else + + {{ trans('general.no_results') }} + + @endif + +
    -
    -
    +
    + @endcan +
    @@ -156,6 +283,9 @@
    +@can('update', Component::class) + @include ('modals.upload-file', ['item_type' => 'component', 'item_id' => $component->id]) +@endcan @stop @section('moar_scripts') diff --git a/resources/views/consumables/view.blade.php b/resources/views/consumables/view.blade.php index c406264a77..406d3b4bd1 100644 --- a/resources/views/consumables/view.blade.php +++ b/resources/views/consumables/view.blade.php @@ -18,57 +18,182 @@
    -
    - @if ($consumable->id) -
    -
    -

    {{ $consumable->name }}

    -
    -
    - @endif -
    -
    -
    -
    + + +
    + + + @can('consumables.files', $consumable) +
    + +
    + + + + + + + + + + + + + + @if ($consumable->uploads->count() > 0) + @foreach ($consumable->uploads as $file) + + + + + + + + + + + + @endforeach + @else + + + + @endif +
    {{trans('general.file_type')}}{{ trans('general.image') }}{{ trans('general.file_name') }}{{ trans('general.filesize') }}{{ trans('general.notes') }}{{ trans('general.download') }}{{ trans('general.created_at') }}{{ trans('table.actions') }}
    + + {{ Helper::filetype_icon($file->filename) }} + + + @if ($file->filename) + @if ( Helper::checkUploadIsImage($file->get_src('consumables'))) + + @endif + @endif + + {{ $file->filename }} + + {{ @Helper::formatFilesizeUnits(Storage::exists('private_uploads/consumables/'.$file->filename) ? Storage::size('private_uploads/consumables/'.$file->filename) : '') }} + + @if ($file->note) + {{ $file->note }} + @endif + + @if ($file->filename) + + + {{ trans('general.download') }} + + @endif + {{ $file->created_at }} + + + {{ trans('general.delete') }} + +
    {{ trans('general.no_results') }}
    -
    +
    + @endcan -
    -
    -
    -
    +
    +
    + + +
    @@ -161,6 +286,11 @@
    + + +@can('update', \App\Models\Consumable::class) + @include ('modals.upload-file', ['item_type' => 'consumable', 'item_id' => $consumable->id]) +@endcan @stop @section('moar_scripts') diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php index 57ac6a4d7e..ef29f8370d 100644 --- a/resources/views/partials/bootstrap-table.blade.php +++ b/resources/views/partials/bootstrap-table.blade.php @@ -632,10 +632,14 @@ if (value) { - if (row.name) { + // This is a clunky override to handle unusual API responses where we're presenting a link instead of an array + if (row.avatar) { + var altName = ''; + } + else if (row.name) { var altName = row.name; } - else if ((row) && (row.model)) { + else if ((row) && (row.model)) { var altName = row.model.name; } return '' + altName + ''; diff --git a/routes/web/accessories.php b/routes/web/accessories.php index c250c122d2..3166b36cd9 100644 --- a/routes/web/accessories.php +++ b/routes/web/accessories.php @@ -27,6 +27,21 @@ Route::group(['prefix' => 'accessories', 'middleware' => ['auth']], function () [Accessories\AccessoryCheckinController::class, 'store'] )->name('accessories.checkin.store'); + Route::post( + '{accessoryId}/upload', + [Accessories\AccessoriesFilesController::class, 'store'] + )->name('upload/accessory'); + + Route::delete( + '{accessoryId}/deletefile/{fileId}', + [Accessories\AccessoriesFilesController::class, 'destroy'] + )->name('delete/accessoryfile'); + + Route::get( + '{accessoryId}/showfile/{fileId}/{download?}', + [Accessories\AccessoriesFilesController::class, 'show'] + )->name('show.accessoryfile'); + }); Route::resource('accessories', Accessories\AccessoriesController::class, [ diff --git a/routes/web/components.php b/routes/web/components.php index 81302df159..429573b8fb 100644 --- a/routes/web/components.php +++ b/routes/web/components.php @@ -25,6 +25,21 @@ Route::group(['prefix' => 'components', 'middleware' => ['auth']], function () { [Components\ComponentCheckinController::class, 'store'] )->name('components.checkin.store'); + Route::post( + '{componentId}/upload', + [Components\ComponentsFilesController::class, 'store'] + )->name('upload/component'); + + Route::delete( + '{componentId}/deletefile/{fileId}', + [Components\ComponentsFilesController::class, 'destroy'] + )->name('delete/componentfile'); + + Route::get( + '{componentId}/showfile/{fileId}/{download?}', + [Components\ComponentsFilesController::class, 'show'] + )->name('show.componentfile'); + }); Route::resource('components', Components\ComponentsController::class, [ diff --git a/routes/web/consumables.php b/routes/web/consumables.php index 9f930a968c..4e2472d30c 100644 --- a/routes/web/consumables.php +++ b/routes/web/consumables.php @@ -16,6 +16,21 @@ Route::group(['prefix' => 'consumables', 'middleware' => ['auth']], function () [Consumables\ConsumableCheckoutController::class, 'store'] )->name('consumables.checkout.store'); + Route::post( + '{consumableId}/upload', + [Consumables\ConsumablesFilesController::class, 'store'] + )->name('upload/consumable'); + + Route::delete( + '{consumableId}/deletefile/{fileId}', + [Consumables\ConsumablesFilesController::class, 'destroy'] + )->name('delete/consumablefile'); + + Route::get( + '{consumableId}/showfile/{fileId}/{download?}', + [Consumables\ConsumablesFilesController::class, 'show'] + )->name('show.consumablefile'); + });