-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop'
- Loading branch information
Showing
12 changed files
with
138 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,28 +4,27 @@ | |
|
||
use App\Helpers\StorageHelper; | ||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\AssetFileRequest; | ||
use App\Http\Requests\UploadFileRequest; | ||
use App\Models\Actionlog; | ||
use App\Models\Accessory; | ||
use Illuminate\Support\Facades\Response; | ||
use Illuminate\Support\Facades\Storage; | ||
use Symfony\Accessory\HttpFoundation\JsonResponse; | ||
use enshrined\svgSanitize\Sanitizer; | ||
|
||
class AccessoriesFilesController extends Controller | ||
{ | ||
/** | ||
* Validates and stores files associated with a accessory. | ||
* | ||
* @todo Switch to using the AssetFileRequest form request validator. | ||
* @author [A. Gianotto] [<[email protected]>] | ||
* @since [v1.0] | ||
* @param AssetFileRequest $request | ||
* @param UploadFileRequest $request | ||
* @param int $accessoryId | ||
* @return \Illuminate\Http\RedirectResponse | ||
* @throws \Illuminate\Auth\Access\AuthorizationException | ||
*@author [A. Gianotto] [<[email protected]>] | ||
* @since [v1.0] | ||
* @todo Switch to using the AssetFileRequest form request validator. | ||
*/ | ||
public function store(AssetFileRequest $request, $accessoryId = null) | ||
public function store(UploadFileRequest $request, $accessoryId = null) | ||
{ | ||
|
||
if (config('app.lock_passwords')) { | ||
|
@@ -45,30 +44,7 @@ public function store(AssetFileRequest $request, $accessoryId = null) | |
|
||
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)); | ||
} | ||
|
||
$file_name = $request->handleFile('private_uploads/accessories/', 'accessory-'.$accessory->id, $file); | ||
//Log the upload to the log | ||
$accessory->logUpload($file_name, e($request->input('notes'))); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,26 +3,25 @@ | |
namespace App\Http\Controllers; | ||
|
||
use App\Helpers\StorageHelper; | ||
use App\Http\Requests\AssetFileRequest; | ||
use App\Http\Requests\UploadFileRequest; | ||
use App\Models\Actionlog; | ||
use App\Models\AssetModel; | ||
use Illuminate\Support\Facades\Response; | ||
use Illuminate\Support\Facades\Storage; | ||
use enshrined\svgSanitize\Sanitizer; | ||
|
||
class AssetModelsFilesController extends Controller | ||
{ | ||
/** | ||
* Upload a file to the server. | ||
* | ||
* @author [A. Gianotto] [<[email protected]>] | ||
* @param AssetFileRequest $request | ||
* @param UploadFileRequest $request | ||
* @param int $modelId | ||
* @return Redirect | ||
* @since [v1.0] | ||
* @throws \Illuminate\Auth\Access\AuthorizationException | ||
*@since [v1.0] | ||
* @author [A. Gianotto] [<[email protected]>] | ||
*/ | ||
public function store(AssetFileRequest $request, $modelId = null) | ||
public function store(UploadFileRequest $request, $modelId = null) | ||
{ | ||
if (! $model = AssetModel::find($modelId)) { | ||
return redirect()->route('models.index')->with('error', trans('admin/hardware/message.does_not_exist')); | ||
|
@@ -37,27 +36,7 @@ public function store(AssetFileRequest $request, $modelId = null) | |
|
||
foreach ($request->file('file') as $file) { | ||
|
||
$extension = $file->getClientOriginalExtension(); | ||
$file_name = 'model-'.$model->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'); | ||
|
||
$sanitizer = new Sanitizer(); | ||
$dirtySVG = file_get_contents($file->getRealPath()); | ||
$cleanSVG = $sanitizer->sanitize($dirtySVG); | ||
|
||
try { | ||
Storage::put('private_uploads/assetmodels/'.$file_name, $cleanSVG); | ||
} catch (\Exception $e) { | ||
\Log::debug('Upload no workie :( '); | ||
\Log::debug($e); | ||
} | ||
} else { | ||
Storage::put('private_uploads/assetmodels/'.$file_name, file_get_contents($file)); | ||
} | ||
|
||
$file_name = $request->handleFile('private_uploads/assetmodels/','model-'.$model->id,$file); | ||
|
||
$model->logUpload($file_name, e($request->get('notes'))); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,26 +4,25 @@ | |
|
||
use App\Helpers\StorageHelper; | ||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\AssetFileRequest; | ||
use App\Http\Requests\UploadFileRequest; | ||
use App\Models\Actionlog; | ||
use App\Models\Asset; | ||
use Illuminate\Support\Facades\Response; | ||
use Illuminate\Support\Facades\Storage; | ||
use enshrined\svgSanitize\Sanitizer; | ||
|
||
class AssetFilesController extends Controller | ||
{ | ||
/** | ||
* Upload a file to the server. | ||
* | ||
* @author [A. Gianotto] [<[email protected]>] | ||
* @param AssetFileRequest $request | ||
* @param UploadFileRequest $request | ||
* @param int $assetId | ||
* @return Redirect | ||
* @since [v1.0] | ||
* @throws \Illuminate\Auth\Access\AuthorizationException | ||
*@since [v1.0] | ||
* @author [A. Gianotto] [<[email protected]>] | ||
*/ | ||
public function store(AssetFileRequest $request, $assetId = null) | ||
public function store(UploadFileRequest $request, $assetId = null) | ||
{ | ||
if (! $asset = Asset::find($assetId)) { | ||
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist')); | ||
|
@@ -37,28 +36,7 @@ public function store(AssetFileRequest $request, $assetId = null) | |
} | ||
|
||
foreach ($request->file('file') as $file) { | ||
|
||
$extension = $file->getClientOriginalExtension(); | ||
$file_name = 'hardware-'.$asset->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'); | ||
|
||
$sanitizer = new Sanitizer(); | ||
$dirtySVG = file_get_contents($file->getRealPath()); | ||
$cleanSVG = $sanitizer->sanitize($dirtySVG); | ||
|
||
try { | ||
Storage::put('private_uploads/assets/'.$file_name, $cleanSVG); | ||
} catch (\Exception $e) { | ||
\Log::debug('Upload no workie :( '); | ||
\Log::debug($e); | ||
} | ||
} else { | ||
Storage::put('private_uploads/assets/'.$file_name, file_get_contents($file)); | ||
} | ||
|
||
$file_name = $request->handleFile('private_uploads/assets/','hardware-'.$asset->id, $file); | ||
|
||
$asset->logUpload($file_name, e($request->get('notes'))); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,28 +4,27 @@ | |
|
||
use App\Helpers\StorageHelper; | ||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\AssetFileRequest; | ||
use App\Http\Requests\UploadFileRequest; | ||
use App\Models\Actionlog; | ||
use App\Models\Component; | ||
use Illuminate\Support\Facades\Response; | ||
use Illuminate\Support\Facades\Storage; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use enshrined\svgSanitize\Sanitizer; | ||
|
||
class ComponentsFilesController extends Controller | ||
{ | ||
/** | ||
* Validates and stores files associated with a component. | ||
* | ||
* @todo Switch to using the AssetFileRequest form request validator. | ||
* @author [A. Gianotto] [<[email protected]>] | ||
* @since [v1.0] | ||
* @param AssetFileRequest $request | ||
* @param UploadFileRequest $request | ||
* @param int $componentId | ||
* @return \Illuminate\Http\RedirectResponse | ||
* @throws \Illuminate\Auth\Access\AuthorizationException | ||
*@author [A. Gianotto] [<[email protected]>] | ||
* @since [v1.0] | ||
* @todo Switch to using the AssetFileRequest form request validator. | ||
*/ | ||
public function store(AssetFileRequest $request, $componentId = null) | ||
public function store(UploadFileRequest $request, $componentId = null) | ||
{ | ||
|
||
if (config('app.lock_passwords')) { | ||
|
@@ -43,30 +42,7 @@ public function store(AssetFileRequest $request, $componentId = null) | |
} | ||
|
||
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)); | ||
} | ||
$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'))); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,28 +4,27 @@ | |
|
||
use App\Helpers\StorageHelper; | ||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\AssetFileRequest; | ||
use App\Http\Requests\UploadFileRequest; | ||
use App\Models\Actionlog; | ||
use App\Models\Consumable; | ||
use Illuminate\Support\Facades\Response; | ||
use Illuminate\Support\Facades\Storage; | ||
use Symfony\Consumable\HttpFoundation\JsonResponse; | ||
use enshrined\svgSanitize\Sanitizer; | ||
|
||
class ConsumablesFilesController extends Controller | ||
{ | ||
/** | ||
* Validates and stores files associated with a consumable. | ||
* | ||
* @todo Switch to using the AssetFileRequest form request validator. | ||
* @author [A. Gianotto] [<[email protected]>] | ||
* @since [v1.0] | ||
* @param AssetFileRequest $request | ||
* @param UploadFileRequest $request | ||
* @param int $consumableId | ||
* @return \Illuminate\Http\RedirectResponse | ||
* @throws \Illuminate\Auth\Access\AuthorizationException | ||
*@author [A. Gianotto] [<[email protected]>] | ||
* @since [v1.0] | ||
* @todo Switch to using the AssetFileRequest form request validator. | ||
*/ | ||
public function store(AssetFileRequest $request, $consumableId = null) | ||
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')); | ||
|
@@ -42,30 +41,7 @@ public function store(AssetFileRequest $request, $consumableId = null) | |
} | ||
|
||
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)); | ||
} | ||
$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'))); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,28 +4,27 @@ | |
|
||
use App\Helpers\StorageHelper; | ||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\AssetFileRequest; | ||
use App\Http\Requests\UploadFileRequest; | ||
use App\Models\Actionlog; | ||
use App\Models\License; | ||
use Illuminate\Support\Facades\Response; | ||
use Illuminate\Support\Facades\Storage; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use enshrined\svgSanitize\Sanitizer; | ||
|
||
class LicenseFilesController extends Controller | ||
{ | ||
/** | ||
* Validates and stores files associated with a license. | ||
* | ||
* @todo Switch to using the AssetFileRequest form request validator. | ||
* @author [A. Gianotto] [<[email protected]>] | ||
* @since [v1.0] | ||
* @param AssetFileRequest $request | ||
* @param UploadFileRequest $request | ||
* @param int $licenseId | ||
* @return \Illuminate\Http\RedirectResponse | ||
* @throws \Illuminate\Auth\Access\AuthorizationException | ||
*@author [A. Gianotto] [<[email protected]>] | ||
* @since [v1.0] | ||
* @todo Switch to using the AssetFileRequest form request validator. | ||
*/ | ||
public function store(AssetFileRequest $request, $licenseId = null) | ||
public function store(UploadFileRequest $request, $licenseId = null) | ||
{ | ||
$license = License::find($licenseId); | ||
|
||
|
@@ -38,30 +37,7 @@ public function store(AssetFileRequest $request, $licenseId = null) | |
} | ||
|
||
foreach ($request->file('file') as $file) { | ||
|
||
$extension = $file->getClientOriginalExtension(); | ||
$file_name = 'license-'.$license->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/licenses/'.$file_name, $cleanSVG); | ||
} catch (\Exception $e) { | ||
\Log::debug('Upload no workie :( '); | ||
\Log::debug($e); | ||
} | ||
|
||
} else { | ||
Storage::put('private_uploads/licenses/'.$file_name, file_get_contents($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'))); | ||
|
Oops, something went wrong.