Skip to content

Commit

Permalink
Merge pull request #16105 from snipe/use_url_fragment_for_file_uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe authored Jan 21, 2025
2 parents 2668960 + d5309c7 commit 8db8d4b
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function store(UploadFileRequest $request, $accessoryId = null) : Redirec
}


return redirect()->route('accessories.show', $accessory->id)->with('success', trans('general.file_upload_success'));
return redirect()->route('accessories.show', $accessory->id)->withFragment('files')->with('success', trans('general.file_upload_success'));

}

Expand Down Expand Up @@ -90,8 +90,7 @@ public function destroy($accessoryId = null, $fileId = null) : RedirectResponse

$log->delete();

return redirect()->back()
->with('success', trans('admin/hardware/message.deletefile.success'));
return redirect()->back()->withFragment('files')->with('success', trans('admin/hardware/message.deletefile.success'));
}

// Redirect to the licence management page
Expand Down
9 changes: 4 additions & 5 deletions app/Http/Controllers/AssetModelsFilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public function store(UploadFileRequest $request, $modelId = null) : RedirectRes
$model->logUpload($file_name, $request->get('notes'));
}

return redirect()->back()->with('success', trans('general.file_upload_success'));
return redirect()->back()->withFragment('files')->with('success', trans('general.file_upload_success'));
}

return redirect()->back()->with('error', trans('admin/hardware/message.upload.nofiles'));
return redirect()->back()->withFragment('files')->with('error', trans('admin/hardware/message.upload.nofiles'));
}

/**
Expand Down Expand Up @@ -119,11 +119,10 @@ public function destroy($modelId = null, $fileId = null) : RedirectResponse
}
$log->delete();

return redirect()->back()->with('success', trans('admin/hardware/message.deletefile.success'));
return redirect()->back()->withFragment('files')->with('success', trans('admin/hardware/message.deletefile.success'));
}

return redirect()->back()
->with('success', trans('admin/hardware/message.deletefile.success'));
return redirect()->back()->withFragment('files')->with('success', trans('admin/hardware/message.deletefile.success'));
}

// Redirect to the hardware management page
Expand Down
20 changes: 7 additions & 13 deletions app/Http/Controllers/Assets/AssetFilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function store(UploadFileRequest $request, $assetId = null) : RedirectRes
$asset->logUpload($file_name, $request->get('notes'));
}

return redirect()->back()->with('success', trans('admin/hardware/message.upload.success'));
return redirect()->back()->withFragment('files')->with('success', trans('admin/hardware/message.upload.success'));
}

return redirect()->back()->with('error', trans('admin/hardware/message.upload.nofiles'));
Expand Down Expand Up @@ -97,25 +97,19 @@ public function show($assetId = null, $fileId = null) : View | RedirectResponse
*/
public function destroy($assetId = null, $fileId = null) : RedirectResponse
{
$asset = Asset::find($assetId);
$this->authorize('update', $asset);
$rel_path = 'private_uploads/assets';

// the asset is valid
if (isset($asset->id)) {
if ($asset = Asset::find($assetId)) {
$this->authorize('update', $asset);
$log = Actionlog::find($fileId);
if ($log) {
$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()->with('success', trans('admin/hardware/message.deletefile.success'));
return redirect()->back()->withFragment('files')->with('success', trans('admin/hardware/message.deletefile.success'));
}

return redirect()->back()
->with('success', trans('admin/hardware/message.deletefile.success'));
return redirect()->route('hardware.show', ['hardware' => $asset])->with('error', trans('general.log_record_not_found'));
}

return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Components/ComponentsFilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function store(UploadFileRequest $request, $componentId = null)
}


return redirect()->route('components.show', $component->id)->with('success', trans('general.file_upload_success'));
return redirect()->route('components.show', $component->id)->withFragment('files')->with('success', trans('general.file_upload_success'));

}

Expand Down Expand Up @@ -91,7 +91,7 @@ public function destroy($componentId = null, $fileId = null)

$log->delete();

return redirect()->back()
return redirect()->back()->withFragment('files')
->with('success', trans('admin/hardware/message.deletefile.success'));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function store(UploadFileRequest $request, $consumableId = null)
}


return redirect()->route('consumables.show', $consumable->id)->with('success', trans('general.file_upload_success'));
return redirect()->route('consumables.show', $consumable->id)->withFragment('files')->with('success', trans('general.file_upload_success'));

}

Expand Down Expand Up @@ -89,7 +89,7 @@ public function destroy($consumableId = null, $fileId = null)

$log->delete();

return redirect()->back()
return redirect()->back()->withFragment('files')
->with('success', trans('admin/hardware/message.deletefile.success'));
}

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Users/UserFilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function store(UploadFileRequest $request, $userId = null)
$logActions[] = $logAction;
}
// dd($logActions);
return redirect()->back()->with('success', trans('admin/users/message.upload.success'));
return redirect()->back()->withFragment('files')->with('success', trans('admin/users/message.upload.success'));
}
return redirect()->back()->with('error', trans('admin/users/message.upload.nofiles'));

Expand Down Expand Up @@ -87,7 +87,7 @@ public function destroy($userId = null, $fileId = null)

if (Storage::exists($rel_path.'/'.$filename)) {
Storage::delete($rel_path.'/'.$filename);
return redirect()->back()->with('success', trans('admin/users/message.deletefile.success'));
return redirect()->back()->withFragment('files')->with('success', trans('admin/users/message.deletefile.success'));
}

}
Expand Down
3 changes: 0 additions & 3 deletions app/Http/Requests/UploadFileRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public function handleFile(string $dirname, string $name_prefix, $file): string
$extension = $file->getClientOriginalExtension();
$file_name = $name_prefix.'-'.str_random(8).'-'.str_slug(basename($file->getClientOriginalName(), '.'.$extension)).'.'.$file->guessExtension();


Log::debug("Your filetype IS: ".$file->getMimeType());
// Check for SVG and sanitize it
if ($file->getMimeType() === 'image/svg+xml') {
Log::debug('This is an SVG');
Expand All @@ -66,7 +64,6 @@ public function handleFile(string $dirname, string $name_prefix, $file): string

} else {
$put_results = Storage::put($dirname.$file_name, file_get_contents($file));
Log::debug("Here are the '$put_results' (should be 0 or 1 or true or false or something?)");
}
return $file_name;
}
Expand Down
4 changes: 2 additions & 2 deletions resources/views/models/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</li>

<li>
<a href="#uploads" data-toggle="tab">
<a href="#files" data-toggle="tab">

<span class="hidden-lg hidden-md">
<i class="fas fa-barcode fa-2x"></i>
Expand Down Expand Up @@ -102,7 +102,7 @@ class="table table-striped snipe-table"
</div> <!-- /.tab-pane assets -->


<div class="tab-pane fade" id="uploads">
<div class="tab-pane fade" id="files">

<div class="row">
<div class="col-md-12">
Expand Down

0 comments on commit 8db8d4b

Please sign in to comment.