diff --git a/app/Http/Controllers/AssetModelsFilesController.php b/app/Http/Controllers/AssetModelsFilesController.php deleted file mode 100644 index 14b2c1fc0b..0000000000 --- a/app/Http/Controllers/AssetModelsFilesController.php +++ /dev/null @@ -1,115 +0,0 @@ -] - */ - public function store(UploadFileRequest $request, $modelId = null) : RedirectResponse - { - if (! $model = AssetModel::find($modelId)) { - return redirect()->route('models.index')->with('error', trans('admin/hardware/message.does_not_exist')); - } - - $this->authorize('update', $model); - - if ($request->hasFile('file')) { - if (! Storage::exists('private_uploads/assetmodels')) { - Storage::makeDirectory('private_uploads/assetmodels', 775); - } - - foreach ($request->file('file') as $file) { - - $file_name = $request->handleFile('private_uploads/assetmodels/','model-'.$model->id,$file); - - $model->logUpload($file_name, $request->get('notes')); - } - - return redirect()->back()->withFragment('files')->with('success', trans('general.file_upload_success')); - } - - return redirect()->back()->withFragment('files')->with('error', trans('admin/hardware/message.upload.nofiles')); - } - - /** - * Check for permissions and display the file. - * - * @author [A. Gianotto] [] - * @param int $modelId - * @param int $fileId - * @since [v1.0] - */ - public function show(AssetModel $model, $fileId = null) : StreamedResponse | Response | RedirectResponse | BinaryFileResponse - { - - $this->authorize('view', $model); - - if (! $log = Actionlog::find($fileId)) { - return response('No matching record for that model/file', 500) - ->header('Content-Type', 'text/plain'); - } - - $file = 'private_uploads/assetmodels/'.$log->filename; - - if (! Storage::exists($file)) { - return response('File '.$file.' not found on server', 404) - ->header('Content-Type', 'text/plain'); - } - - if (request('inline') == 'true') { - - $headers = [ - 'Content-Disposition' => 'inline', - ]; - - return Storage::download($file, $log->filename, $headers); - } - - return StorageHelper::downloader($file); - } - - /** - * Delete the associated file - * - * @author [A. Gianotto] [] - * @param int $modelId - * @param int $fileId - * @since [v1.0] - */ - public function destroy(AssetModel $model, $fileId = null) : RedirectResponse - { - $rel_path = 'private_uploads/assetmodels'; - $this->authorize('update', $model); - $log = Actionlog::find($fileId); - if ($log) { - if (Storage::exists($rel_path.'/'.$log->filename)) { - Storage::delete($rel_path.'/'.$log->filename); - } - $log->delete(); - - return redirect()->back()->withFragment('files')->with('success', trans('admin/hardware/message.deletefile.success')); - } - - return redirect()->back()->withFragment('files')->with('success', trans('admin/hardware/message.deletefile.success')); - - } -} diff --git a/app/Http/Controllers/Assets/AssetFilesController.php b/app/Http/Controllers/Assets/AssetFilesController.php deleted file mode 100644 index cf119edddc..0000000000 --- a/app/Http/Controllers/Assets/AssetFilesController.php +++ /dev/null @@ -1,108 +0,0 @@ -] - */ - public function store(UploadFileRequest $request, Asset $asset) : RedirectResponse - { - - $this->authorize('update', $asset); - - if ($request->hasFile('file')) { - if (! Storage::exists('private_uploads/assets')) { - Storage::makeDirectory('private_uploads/assets', 775); - } - - foreach ($request->file('file') as $file) { - $file_name = $request->handleFile('private_uploads/assets/','hardware-'.$asset->id, $file); - - $asset->logUpload($file_name, $request->get('notes')); - } - - return redirect()->back()->withFragment('files')->with('success', trans('admin/hardware/message.upload.success')); - } - - return redirect()->back()->with('error', trans('admin/hardware/message.upload.nofiles')); - } - - /** - * Check for permissions and display the file. - * - * @author [A. Gianotto] [] - * @param int $assetId - * @param int $fileId - * @since [v1.0] - */ - public function show(Asset $asset, $fileId = null) : View | RedirectResponse | Response | StreamedResponse | BinaryFileResponse - { - - $this->authorize('view', $asset); - - if ($log = Actionlog::whereNotNull('filename')->where('item_id', $asset->id)->find($fileId)) { - $file = 'private_uploads/assets/'.$log->filename; - - if ($log->action_type == 'audit') { - $file = 'private_uploads/audits/'.$log->filename; - } - - try { - return StorageHelper::showOrDownloadFile($file, $log->filename); - } catch (\Exception $e) { - return redirect()->route('hardware.show', $asset)->with('error', trans('general.file_not_found')); - } - - } - - return redirect()->route('hardware.show', $asset)->with('error', trans('general.log_record_not_found')); - - - } - - /** - * Delete the associated file - * - * @author [A. Gianotto] [] - * @param int $assetId - * @param int $fileId - * @since [v1.0] - */ - public function destroy(Asset $asset, $fileId = null) : RedirectResponse - { - $this->authorize('update', $asset); - $rel_path = 'private_uploads/assets'; - - if ($log = Actionlog::find($fileId)) { - if (Storage::exists($rel_path.'/'.$log->filename)) { - Storage::delete($rel_path.'/'.$log->filename); - } - $log->delete(); - return redirect()->back()->withFragment('files')->with('success', trans('admin/hardware/message.deletefile.success')); - } - - return redirect()->route('hardware.show', $asset)->with('error', trans('general.log_record_not_found')); - } - -} diff --git a/app/Http/Controllers/Components/ComponentsFilesController.php b/app/Http/Controllers/Components/ComponentsFilesController.php deleted file mode 100644 index b5e30aa694..0000000000 --- a/app/Http/Controllers/Components/ComponentsFilesController.php +++ /dev/null @@ -1,138 +0,0 @@ -] - * @since [v1.0] - * @todo Switch to using the AssetFileRequest form request validator. - */ - public function store(UploadFileRequest $request, $componentId = null) - { - - if (config('app.lock_passwords')) { - return redirect()->route('components.show', ['component'=>$componentId])->with('error', trans('general.feature_disabled')); - } - - $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) { - $file_name = $request->handleFile('private_uploads/components/','component-'.$component->id, $file); - - //Log the upload to the log - $component->logUpload($file_name, e($request->input('notes'))); - } - - - return redirect()->route('components.show', $component->id)->withFragment('files')->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()->withFragment('files') - ->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) - { - Log::debug('Private filesystem is: '.config('filesystems.default')); - - - // the component is valid - if ($component = Component::find($componentId)) { - $this->authorize('view', $component); - $this->authorize('components.files', $component); - - if ($log = Actionlog::whereNotNull('filename')->where('item_id', $component->id)->find($fileId)) { - - $file = 'private_uploads/components/'.$log->filename; - - try { - return StorageHelper::showOrDownloadFile($file, $log->filename); - } catch (\Exception $e) { - return redirect()->route('components.show', ['component' => $component])->with('error', trans('general.file_not_found')); - } - } - return redirect()->route('components.show', ['component' => $component])->with('error', trans('general.log_record_not_found')); - - } - - 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 deleted file mode 100644 index 545b008dc0..0000000000 --- a/app/Http/Controllers/Consumables/ConsumablesFilesController.php +++ /dev/null @@ -1,134 +0,0 @@ -] - * @since [v1.0] - * @todo Switch to using the AssetFileRequest form request validator. - */ - public function store(UploadFileRequest $request, $consumableId = null) - { - if (config('app.lock_passwords')) { - return redirect()->route('consumables.show', ['consumable'=>$consumableId])->with('error', trans('general.feature_disabled')); - } - - $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) { - $file_name = $request->handleFile('private_uploads/consumables/','consumable-'.$consumable->id, $file); - - //Log the upload to the log - $consumable->logUpload($file_name, e($request->input('notes'))); - } - - - return redirect()->route('consumables.show', $consumable->id)->withFragment('files')->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()->withFragment('files') - ->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 - * @throws \Illuminate\Auth\Access\AuthorizationException - */ - public function show($consumableId = null, $fileId = null) - { - $consumable = Consumable::find($consumableId); - - // the consumable is valid - if (isset($consumable->id)) { - $this->authorize('view', $consumable); - $this->authorize('consumables.files', $consumable); - - if ($log = Actionlog::whereNotNull('filename')->where('item_id', $consumable->id)->find($fileId)) { - $file = 'private_uploads/consumables/'.$log->filename; - - try { - return StorageHelper::showOrDownloadFile($file, $log->filename); - } catch (\Exception $e) { - return redirect()->route('consumables.show', ['consumable' => $consumable])->with('error', trans('general.file_not_found')); - } - } - // The log record doesn't exist somehow - return redirect()->route('consumables.show', ['consumable' => $consumable])->with('error', trans('general.log_record_not_found')); - - } - - return redirect()->route('consumables.index')->with('error', trans('general.file_does_not_exist', ['id' => $fileId])); - } -} diff --git a/app/Http/Controllers/Licenses/LicenseFilesController.php b/app/Http/Controllers/Licenses/LicenseFilesController.php deleted file mode 100644 index 6ab3cb7703..0000000000 --- a/app/Http/Controllers/Licenses/LicenseFilesController.php +++ /dev/null @@ -1,132 +0,0 @@ -] - * @since [v1.0] - * @todo Switch to using the AssetFileRequest form request validator. - */ - public function store(UploadFileRequest $request, $licenseId = null) - { - $license = License::find($licenseId); - - if (isset($license->id)) { - $this->authorize('update', $license); - - if ($request->hasFile('file')) { - if (! Storage::exists('private_uploads/licenses')) { - Storage::makeDirectory('private_uploads/licenses', 775); - } - - foreach ($request->file('file') as $file) { - $file_name = $request->handleFile('private_uploads/licenses/','license-'.$license->id, $file); - - //Log the upload to the log - $license->logUpload($file_name, e($request->input('notes'))); - } - - - return redirect()->route('licenses.show', $license->id)->with('success', trans('admin/licenses/message.upload.success')); - - } - - return redirect()->route('licenses.show', $license->id)->with('error', trans('admin/licenses/message.upload.nofiles')); - } - // Prepare the error message - return redirect()->route('licenses.index') - ->with('error', trans('admin/licenses/message.does_not_exist')); - } - - /** - * Deletes the selected license file. - * - * @author [A. Gianotto] [] - * @since [v1.0] - * @param int $licenseId - * @param int $fileId - * @return \Illuminate\Http\RedirectResponse - * @throws \Illuminate\Auth\Access\AuthorizationException - */ - public function destroy($licenseId = null, $fileId = null) - { - if ($license = License::find($licenseId)) { - - $this->authorize('update', $license); - - if ($log = Actionlog::find($fileId)) { - - // Remove the file if one exists - if (Storage::exists('licenses/'.$log->filename)) { - try { - Storage::delete('licenses/'.$log->filename); - } catch (\Exception $e) { - Log::debug($e); - } - } - - $log->delete(); - - return redirect()->back() - ->with('success', trans('admin/hardware/message.deletefile.success')); - } - - return redirect()->route('licenses.index')->with('error', trans('general.log_does_not_exist')); - } - - return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.does_not_exist')); - } - - /** - * Allows the selected file to be viewed. - * - * @author [A. Gianotto] [] - * @since [v1.4] - * @param int $licenseId - * @param int $fileId - * @return \Symfony\Component\HttpFoundation\Response - * @throws \Illuminate\Auth\Access\AuthorizationException - */ - public function show($licenseId = null, $fileId = null, $download = true) - { - $license = License::find($licenseId); - - // the license is valid - if (isset($license->id)) { - $this->authorize('view', $license); - $this->authorize('licenses.files', $license); - - if ($log = Actionlog::whereNotNull('filename')->where('item_id', $license->id)->find($fileId)) { - $file = 'private_uploads/licenses/'.$log->filename; - - try { - return StorageHelper::showOrDownloadFile($file, $log->filename); - } catch (\Exception $e) { - return redirect()->route('licenses.show', ['licenses' => $license])->with('error', trans('general.file_not_found')); - } - } - - // The log record doesn't exist somehow - return redirect()->route('licenses.show', ['licenses' => $license])->with('error', trans('general.log_record_not_found')); - - } - - return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.does_not_exist', ['id' => $fileId])); - } -} diff --git a/app/Http/Controllers/LocationsFilesController.php b/app/Http/Controllers/LocationsFilesController.php deleted file mode 100644 index 3aaec0e089..0000000000 --- a/app/Http/Controllers/LocationsFilesController.php +++ /dev/null @@ -1,111 +0,0 @@ -] - */ - public function store(UploadFileRequest $request, Location $location) : RedirectResponse - { - $this->authorize('update', $location); - - if ($request->hasFile('file')) { - - if (! Storage::exists('private_uploads/locations')) { - Storage::makeDirectory('private_uploads/locations', 775); - } - - foreach ($request->file('file') as $file) { - $file_name = $request->handleFile('private_uploads/locations/','location-'.$location->id, $file); - $location->logUpload($file_name, $request->get('notes')); - } - - return redirect()->back()->withFragment('files')->with('success', trans('general.file_upload_success')); - } - - return redirect()->back()->withFragment('files')->with('error', trans('admin/hardware/message.upload.nofiles')); - } - - /** - * Check for permissions and display the file. - * - * @author [A. Gianotto] [] - * @param int $modelId - * @param int $fileId - * @since [v1.0] - */ - public function show(Location $location, $fileId = null) : StreamedResponse | Response | RedirectResponse | BinaryFileResponse - { - - $this->authorize('view', $location); - - if (! $log = Actionlog::find($fileId)) { - return redirect()->back()->withFragment('files')->with('error', 'No matching file record'); - } - - $file = 'private_uploads/locations/'.$log->filename; - - if (! Storage::exists($file)) { - return redirect()->back()->withFragment('files')->with('error', 'No matching file on server'); - } - - if (request('inline') == 'true') { - - $headers = [ - 'Content-Disposition' => 'inline', - ]; - - return Storage::download($file, $log->filename, $headers); - } - - return StorageHelper::downloader($file); - } - - /** - * Delete the associated file - * - * @author [A. Gianotto] [] - * @param int $modelId - * @param int $fileId - * @since [v1.0] - */ - public function destroy(Location $location, $fileId = null) : RedirectResponse - { - $rel_path = 'private_uploads/locations'; - $this->authorize('update', $location); - $log = Actionlog::find($fileId); - - if ($log) { - - // This should be moved to purge -// if (Storage::exists($rel_path.'/'.$log->filename)) { -// Storage::delete($rel_path.'/'.$log->filename); -// } - $log->delete(); - - return redirect()->back()->withFragment('files')->with('success', trans('admin/hardware/message.deletefile.success')); - } - - return redirect()->back()->withFragment('files')->with('success', trans('admin/hardware/message.deletefile.success')); - - } -} diff --git a/app/Http/Controllers/Users/UserFilesController.php b/app/Http/Controllers/Users/UserFilesController.php deleted file mode 100644 index 3e1f6cd9a6..0000000000 --- a/app/Http/Controllers/Users/UserFilesController.php +++ /dev/null @@ -1,119 +0,0 @@ -] - * @since [v1.6] - */ - public function store(UploadFileRequest $request, User $user) - { - $this->authorize('update', $user); - - if ($request->hasFile('file')) { - if (! Storage::exists('private_uploads/users')) { - Storage::makeDirectory('private_uploads/users', 775); - } - - foreach ($request->file('file') as $file) { - $file_name = $request->handleFile('private_uploads/users/','user-'.$user->id, $file); - $user->logUpload($file_name, $request->get('notes')); - } - - return redirect()->back()->withFragment('files')->with('success', trans('admin/users/message.upload.success')); - } - - return redirect()->back()->with('error', trans('admin/users/message.upload.nofiles')); - - - } - - /** - * Delete file - * - * @author [A. Gianotto] [] - * @since [v1.6] - * @param int $userId - * @param int $fileId - * @return \Illuminate\Http\RedirectResponse - * @throws \Illuminate\Auth\Access\AuthorizationException - */ - public function destroy($userId = null, $fileId = null) - { - if ($user = User::find($userId)) { - - $this->authorize('delete', $user); - $rel_path = 'private_uploads/users'; - - - if ($log = Actionlog::find($fileId)) { - $filename = $log->filename; - $log->delete(); - - if (Storage::exists($rel_path.'/'.$filename)) { - Storage::delete($rel_path.'/'.$filename); - return redirect()->back()->withFragment('files')->with('success', trans('admin/users/message.deletefile.success')); - } - - } - - // The log record doesn't exist somehow - return redirect()->back()->with('success', trans('admin/users/message.deletefile.success')); - } - - return redirect()->route('users.index')->with('error', trans('admin/users/message.user_not_found', ['id' => $userId])); - - } - - /** - * Display/download the uploaded file - * - * @author [A. Gianotto] [] - * @since [v1.6] - * @param int $userId - * @param int $fileId - * @return mixed - * @throws \Illuminate\Auth\Access\AuthorizationException - */ - public function show(User $user, $fileId = null) - { - - - if (empty($fileId)) { - return redirect()->route('users.show')->with('error', 'Invalid file request'); - } - - $this->authorize('view', $user); - - if ($log = Actionlog::whereNotNull('filename')->where('item_id', $user->id)->find($fileId)) { - $file = 'private_uploads/users/'.$log->filename; - - try { - return StorageHelper::showOrDownloadFile($file, $log->filename); - } catch (\Exception $e) { - return redirect()->route('users.show', ['user' => $user])->with('error', trans('general.file_not_found')); - } - } - - // The log record doesn't exist somehow - return redirect()->route('users.show', ['user' => $user])->with('error', trans('general.log_record_not_found')); - - } - -}