Skip to content

Commit

Permalink
Fixes snipe#5859 - add file name/size to file upload UI (snipe#5861)
Browse files Browse the repository at this point in the history
* Fixes snipe#5859 - add file name/size to file upload UI

* Reverting assetcontroller

Not sure exactly what happened here…

* Production assets
  • Loading branch information
snipe authored Jul 17, 2018
1 parent b5de5ac commit a4799a4
Show file tree
Hide file tree
Showing 14 changed files with 475 additions and 489 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/AssetFilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public function store(AssetFileRequest $request, $assetId = null)

$destinationPath = config('app.private_uploads').'/assets';

if ($request->hasFile('assetfile')) {
foreach ($request->file('assetfile') as $file) {
if ($request->hasFile('file')) {
foreach ($request->file('file') as $file) {
$extension = $file->getClientOriginalExtension();
$filename = 'hardware-'.$asset->id.'-'.str_random(8);
$filename .= '-'.str_slug(basename($file->getClientOriginalName(), '.'.$extension)).'.'.$extension;
Expand Down
184 changes: 92 additions & 92 deletions app/Http/Controllers/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ public function __construct()
}

/**
* Returns a view that invokes the ajax tables which actually contains
* the content for the assets listing, which is generated in getDatatable.
*
* @author [A. Gianotto] [<[email protected]>]
* @see AssetController::getDatatable() method that generates the JSON response
* @since [v1.0]
* @return View
*/
* Returns a view that invokes the ajax tables which actually contains
* the content for the assets listing, which is generated in getDatatable.
*
* @author [A. Gianotto] [<[email protected]>]
* @see AssetController::getDatatable() method that generates the JSON response
* @since [v1.0]
* @return View
*/
public function index(Request $request)
{
$this->authorize('index', Asset::class);
Expand Down Expand Up @@ -104,12 +104,12 @@ public function create(Request $request)
}

/**
* Validate and process new asset form data.
*
* @author [A. Gianotto] [<[email protected]>]
* @since [v1.0]
* @return Redirect
*/
* Validate and process new asset form data.
*
* @author [A. Gianotto] [<[email protected]>]
* @since [v1.0]
* @return Redirect
*/
public function store(AssetRequest $request)
{
$this->authorize(Asset::class);
Expand Down Expand Up @@ -195,7 +195,7 @@ public function store(AssetRequest $request)
}
}

// Was the asset created?
// Was the asset created?
if ($asset->save()) {


Expand Down Expand Up @@ -223,13 +223,13 @@ public function store(AssetRequest $request)
}

/**
* Returns a view that presents a form to edit an existing asset.
*
* @author [A. Gianotto] [<[email protected]>]
* @param int $assetId
* @since [v1.0]
* @return View
*/
* Returns a view that presents a form to edit an existing asset.
*
* @author [A. Gianotto] [<[email protected]>]
* @param int $assetId
* @since [v1.0]
* @return View
*/
public function edit($assetId = null)
{
if (!$item = Asset::find($assetId)) {
Expand All @@ -246,13 +246,13 @@ public function edit($assetId = null)


/**
* Returns a view that presents information about an asset for detail view.
*
* @author [A. Gianotto] [<[email protected]>]
* @param int $assetId
* @since [v1.0]
* @return View
*/
* Returns a view that presents information about an asset for detail view.
*
* @author [A. Gianotto] [<[email protected]>]
* @param int $assetId
* @since [v1.0]
* @return View
*/
public function show($assetId = null)
{
$asset = Asset::withTrashed()->find($assetId);
Expand Down Expand Up @@ -289,13 +289,13 @@ public function show($assetId = null)


/**
* Validate and process asset edit form.
*
* @author [A. Gianotto] [<[email protected]>]
* @param int $assetId
* @since [v1.0]
* @return Redirect
*/
* Validate and process asset edit form.
*
* @author [A. Gianotto] [<[email protected]>]
* @param int $assetId
* @since [v1.0]
* @return Redirect
*/

public function update(AssetRequest $request, $assetId = null)
{
Expand Down Expand Up @@ -404,13 +404,13 @@ public function update(AssetRequest $request, $assetId = null)
}

/**
* Delete a given asset (mark as deleted).
*
* @author [A. Gianotto] [<[email protected]>]
* @param int $assetId
* @since [v1.0]
* @return Redirect
*/
* Delete a given asset (mark as deleted).
*
* @author [A. Gianotto] [<[email protected]>]
* @param int $assetId
* @since [v1.0]
* @return Redirect
*/
public function destroy($assetId)
{
// Check if the asset exists
Expand Down Expand Up @@ -450,13 +450,13 @@ public function getAssetByTag()
return redirect()->route('hardware.show', $asset->id)->with('topsearch', $topsearch);
}
/**
* Return a QR code for the asset
*
* @author [A. Gianotto] [<[email protected]>]
* @param int $assetId
* @since [v1.0]
* @return Response
*/
* Return a QR code for the asset
*
* @author [A. Gianotto] [<[email protected]>]
* @param int $assetId
* @since [v1.0]
* @return Response
*/
public function getQrCode($assetId = null)
{
$settings = Setting::getSettings();
Expand Down Expand Up @@ -516,13 +516,13 @@ public function getBarCode($assetId = null)
}

/**
* Returns a view that presents a form to clone an asset.
*
* @author [A. Gianotto] [<[email protected]>]
* @param int $assetId
* @since [v1.0]
* @return View
*/
* Returns a view that presents a form to clone an asset.
*
* @author [A. Gianotto] [<[email protected]>]
* @param int $assetId
* @since [v1.0]
* @return View
*/
public function getClone($assetId = null)
{
// Check if the asset exists
Expand All @@ -540,9 +540,9 @@ public function getClone($assetId = null)
$asset->assigned_to = '';

return view('hardware/edit')
->with('statuslabel_list', Helper::statusLabelList())
->with('statuslabel_types', Helper::statusTypeList())
->with('item', $asset);
->with('statuslabel_list', Helper::statusLabelList())
->with('statuslabel_types', Helper::statusTypeList())
->with('item', $asset);
}

/**
Expand Down Expand Up @@ -641,15 +641,15 @@ public function postImportHistory(Request $request)
$item[$asset_tag][$batch_counter]['user_id'] = $user->id;

Actionlog::firstOrCreate(array(
'item_id' => $asset->id,
'item_type' => Asset::class,
'user_id' => Auth::user()->id,
'note' => 'Checkout imported by '.Auth::user()->present()->fullName().' from history importer',
'target_id' => $item[$asset_tag][$batch_counter]['user_id'],
'target_type' => User::class,
'created_at' => $item[$asset_tag][$batch_counter]['checkout_date'],
'action_type' => 'checkout',
));
'item_id' => $asset->id,
'item_type' => Asset::class,
'user_id' => Auth::user()->id,
'note' => 'Checkout imported by '.Auth::user()->present()->fullName().' from history importer',
'target_id' => $item[$asset_tag][$batch_counter]['user_id'],
'target_type' => User::class,
'created_at' => $item[$asset_tag][$batch_counter]['checkout_date'],
'action_type' => 'checkout',
));

$asset->assigned_to = $user->id;

Expand Down Expand Up @@ -682,14 +682,14 @@ public function postImportHistory(Request $request)
$asset_batch[$x]['real_checkin'] = $checkin_date;

Actionlog::firstOrCreate(array(
'item_id' => $asset_batch[$x]['asset_id'],
'item_type' => Asset::class,
'user_id' => Auth::user()->id,
'note' => 'Checkin imported by ' . Auth::user()->present()->fullName() . ' from history importer',
'target_id' => null,
'created_at' => $checkin_date,
'action_type' => 'checkin'
));
'item_id' => $asset_batch[$x]['asset_id'],
'item_type' => Asset::class,
'user_id' => Auth::user()->id,
'note' => 'Checkin imported by ' . Auth::user()->present()->fullName() . ' from history importer',
'target_id' => null,
'created_at' => $checkin_date,
'action_type' => 'checkin'
));
}
}
}
Expand All @@ -698,13 +698,13 @@ public function postImportHistory(Request $request)
}

/**
* Retore a deleted asset.
*
* @author [A. Gianotto] [<[email protected]>]
* @param int $assetId
* @since [v1.0]
* @return View
*/
* Retore a deleted asset.
*
* @author [A. Gianotto] [<[email protected]>]
* @param int $assetId
* @since [v1.0]
* @return View
*/
public function getRestore($assetId = null)
{
// Get asset information
Expand Down Expand Up @@ -775,14 +775,14 @@ public function auditStore(AssetFileRequest $request, $id)

if ($request->hasFile('image')) {
$file = $request->file('image');
try {
$destinationPath = config('app.private_uploads').'/audits';
$extension = $file->getClientOriginalExtension();
$filename = 'audit-'.$asset->id.'-'.str_slug(basename($file->getClientOriginalName(), '.'.$extension)).'.'.$extension;
$file->move($destinationPath, $filename);
} catch (\Exception $e) {
\Log::error($e);
}
try {
$destinationPath = config('app.private_uploads').'/audits';
$extension = $file->getClientOriginalExtension();
$filename = 'audit-'.$asset->id.'-'.str_slug(basename($file->getClientOriginalName(), '.'.$extension)).'.'.$extension;
$file->move($destinationPath, $filename);
} catch (\Exception $e) {
\Log::error($e);
}
}

$asset->logAudit($request->input('note'), $request->input('location_id'), $filename);
Expand Down
16 changes: 4 additions & 12 deletions app/Http/Controllers/LicensesController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace App\Http\Controllers;

use App\Http\Requests\AssetFileRequest;
use Assets;
use Illuminate\Support\Facades\Session;
use Input;
Expand Down Expand Up @@ -495,7 +496,7 @@ public function getClone($licenseId = null)
* @param int $licenseId
* @return \Illuminate\Http\RedirectResponse
*/
public function postUpload(Request $request, $licenseId = null)
public function postUpload(AssetFileRequest $request, $licenseId = null)
{
$license = License::find($licenseId);
// the license is valid
Expand All @@ -504,18 +505,9 @@ public function postUpload(Request $request, $licenseId = null)
if (isset($license->id)) {
$this->authorize('update', $license);

if (Input::hasFile('licensefile')) {
if (Input::hasFile('file')) {

foreach (Input::file('licensefile') as $file) {

$rules = array(
'licensefile' => 'required|mimes:png,gif,jpg,jpeg,doc,docx,pdf,txt,zip,rar,rtf,xml,lic'
);
$validator = Validator::make(array('licensefile'=> $file), $rules);

if ($validator->fails()) {
return redirect()->back()->with('error', trans('admin/licenses/message.upload.invalidfiles'));
}
foreach (Input::file('file') as $file) {
$extension = $file->getClientOriginalExtension();
$filename = 'license-'.$license->id.'-'.str_random(8).'-'.str_slug(basename($file->getClientOriginalName(), '.'.$extension)).'.'.$extension;
$upload_success = $file->move($destinationPath, $filename);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/AssetFileRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function rules()
{
$max_file_size = \App\Helpers\Helper::file_upload_max_size();
return [
'file.*' => 'required|mimes:png,gif,jpg,jpeg,doc,docx,pdf,txt,zip,rar|max:'.$max_file_size,
'file.*' => 'required|mimes:png,gif,jpg,svg,jpeg,doc,docx,pdf,txt,zip,rar,xls,lic|max:'.$max_file_size,
];
}

Expand Down
Loading

0 comments on commit a4799a4

Please sign in to comment.