A free open source IT asset/license management system
Use intended() for redirect options
snipee37649212861
diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.phpindex 195c2e4611..e36cc4edd8 100644--- a/app/Helpers/Helper.php+++ b/app/Helpers/Helper.php@@ -1547,18 +1547,19 @@ class Helper]) ? 'rtl' : 'ltr';}+static public function getRedirectOption($request, $id, $table, $item_id = null) : RedirectResponse{- $redirect_option = Session::get('redirect_option') ?? $request->redirect_option;- $checkout_to_type = Session::get('checkout_to_type') ?? null;- $checkedInFrom = Session::get('checkedInFrom');- $other_redirect = Session::get('other_redirect');- $backUrl = Session::pull('back_url', route('home'));-+ $redirect_option = session('redirect_option') ?? $request->redirect_option;+ $checkout_to_type = session('checkout_to_type') ?? null;+ $checkedInFrom = session('checkedInFrom');+ $other_redirect = session('other_redirect');+ $backUrl = session()->pull('url.intended', 'home');+// return to previous page- if ($redirect_option === 'back') {- return redirect()->to($backUrl);+ if ($redirect_option == 'back') {+ return redirect()->intended($backUrl);}// return to indexdiff --git a/app/Http/Controllers/Accessories/AccessoriesController.php b/app/Http/Controllers/Accessories/AccessoriesController.phpindex c84d11fae2..9ab9f30068 100755--- a/app/Http/Controllers/Accessories/AccessoriesController.php+++ b/app/Http/Controllers/Accessories/AccessoriesController.php@@ -115,7 +115,7 @@ class AccessoriesController extends Controllerpublic function edit(Accessory $accessory) : View | RedirectResponse{$this->authorize('update', $accessory);- session()->put('back_url', url()->previous());+ session()->put('url.intended', url()->previous());return view('accessories.edit')->with('item', $accessory)->with('category_type', 'accessory');}@@ -204,15 +204,10 @@ class AccessoriesController extends Controller* @author [A. Gianotto] [<[email protected]>]* @param int $accessoryId*/- public function destroy($accessoryId) : RedirectResponse+ public function destroy(Accessory $accessory) : RedirectResponse{- if (is_null($accessory = Accessory::withCount('checkouts as checkouts_count')->find($accessoryId))) {- return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.not_found'));- }-$this->authorize('delete', $accessory);-if ($accessory->checkouts_count > 0) {return redirect()->route('accessories.index')->with('error', trans('admin/accessories/general.delete_disabled'));}diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.phpindex f52a767a98..cece060dc8 100755--- a/app/Http/Controllers/Assets/AssetsController.php+++ b/app/Http/Controllers/Assets/AssetsController.php@@ -312,7 +312,7 @@ class AssetsController extends Controllerpublic function edit(Asset $asset) : View | RedirectResponse{$this->authorize($asset);- session()->put('back_url', url()->previous());+ session()->put('url.intended', url()->previous());return view('hardware/edit')->with('item', $asset)->with('statuslabel_list', Helper::statusLabelList())@@ -508,16 +508,9 @@ class AssetsController extends Controller* @param int $assetId* @since [v1.0]*/- public function destroy(Request $request, $assetId) : RedirectResponse+ public function destroy(Request $request, Asset $asset) : RedirectResponse{- // Check if the asset exists- if (is_null($asset = Asset::find($assetId))) {- // Redirect to the asset management page with error- return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));- }-$this->authorize('delete', $asset);-if ($asset->assignedTo) {$target = $asset->assignedTo;diff --git a/app/Http/Controllers/Components/ComponentsController.php b/app/Http/Controllers/Components/ComponentsController.phpindex 7824212e8c..eecc156c25 100644--- a/app/Http/Controllers/Components/ComponentsController.php+++ b/app/Http/Controllers/Components/ComponentsController.php@@ -117,7 +117,7 @@ class ComponentsController extends Controller{$this->authorize('update', $component);- session()->put('back_url', url()->previous());+ session()->put('url.intended', url()->previous());return view('components/edit')->with('item', $component)->with('category_type', 'component');diff --git a/app/Http/Controllers/Consumables/ConsumablesController.php b/app/Http/Controllers/Consumables/ConsumablesController.phpindex fc03139a95..993a30c458 100644--- a/app/Http/Controllers/Consumables/ConsumablesController.php+++ b/app/Http/Controllers/Consumables/ConsumablesController.php@@ -124,7 +124,7 @@ class ConsumablesController extends Controllerpublic function edit(Consumable $consumable) : View | RedirectResponse{$this->authorize($consumable);- session()->put('back_url', url()->previous());+ session()->put('url.intended', url()->previous());return view('consumables/edit')->with('item', $consumable)->with('category_type', 'consumable');diff --git a/app/Http/Controllers/Licenses/LicensesController.php b/app/Http/Controllers/Licenses/LicensesController.phpindex 25707f30f7..18454aa4e1 100755--- a/app/Http/Controllers/Licenses/LicensesController.php+++ b/app/Http/Controllers/Licenses/LicensesController.php@@ -130,7 +130,7 @@ class LicensesController extends Controller{$this->authorize('update', $license);- session()->put('back_url', url()->previous());+ session()->put('url.intended', url()->previous());$maintained_list = ['' => 'Maintained','1' => 'Yes',diff --git a/app/Http/Controllers/Users/UsersController.php b/app/Http/Controllers/Users/UsersController.phpindex fa273b3a28..540e4461cf 100755--- a/app/Http/Controllers/Users/UsersController.php+++ b/app/Http/Controllers/Users/UsersController.php@@ -203,8 +203,8 @@ class UsersController extends Controllerpublic function edit(User $user){- $this->authorize('update', User::class);- session()->put('back_url', url()->previous());+ $this->authorize('update', $user);+ session()->put('url.intended', url()->previous());$user = User::with(['assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc'])->withTrashed()->find($user->id);if ($user) {@@ -238,7 +238,7 @@ class UsersController extends Controller*/public function update(SaveUserRequest $request, User $user){- $this->authorize('update', User::class);+ $this->authorize('update', $user);// This is a janky hack to prevent people from changing admin demo user data on the public demo.// The $ids 1 and 2 are special since they are seeded as superadmins in the demo seeder.@@ -387,37 +387,35 @@ class UsersController extends Controller* @return \Illuminate\Http\RedirectResponse* @throws \Illuminate\Auth\Access\AuthorizationException*/- public function getRestore($id = null)+ public function getRestore(User $user){- if ($user = User::withTrashed()->find($id)) {- $this->authorize('delete', $user);- if ($user->deleted_at == '') {- return redirect()->back()->with('error', trans('general.not_deleted', ['item_type' => trans('general.user')]));- }+ $this->authorize('delete', $user);- if ($user->restore()) {- $logaction = new Actionlog();- $logaction->item_type = User::class;- $logaction->item_id = $user->id;- $logaction->created_at = date('Y-m-d H:i:s');- $logaction->created_by = auth()->id();- $logaction->logaction('restore');-- // Redirect them to the deleted page if there are more, otherwise the section index- $deleted_users = User::onlyTrashed()->count();- if ($deleted_users > 0) {- return redirect()->back()->with('success', trans('admin/users/message.success.restored'));- }- return redirect()->route('users.index')->with('success', trans('admin/users/message.success.restored'));+ if ($user->deleted_at == '') {+ return redirect()->back()->with('error', trans('general.not_deleted', ['item_type' => trans('general.user')]));+ }+ if ($user->restore()) {+ $logaction = new Actionlog();+ $logaction->item_type = User::class;+ $logaction->item_id = $user->id;+ $logaction->created_at = date('Y-m-d H:i:s');+ $logaction->created_by = auth()->id();+ $logaction->logaction('restore');++ // Redirect them to the deleted page if there are more, otherwise the section index+ $deleted_users = User::onlyTrashed()->count();+ if ($deleted_users > 0) {+ return redirect()->back()->with('success', trans('admin/users/message.success.restored'));}+ return redirect()->route('users.index')->with('success', trans('admin/users/message.success.restored'));- // Check validation to make sure we're not restoring a user with the same username as an existing user- return redirect()->back()->with('error', trans('general.could_not_restore', ['item_type' => trans('general.user'), 'error' => $user->getErrors()->first()]));}- return redirect()->route('users.index')->with('error', trans('admin/users/message.does_not_exist'));+ // Check validation to make sure we're not restoring a user with the same username as an existing user+ return redirect()->back()->with('error', trans('general.could_not_restore', ['item_type' => trans('general.user'), 'error' => $user->getErrors()->first()]));+}/**@@ -432,7 +430,7 @@ class UsersController extends Controllerpublic function show(User $user){// Make sure the user can view users at all- $this->authorize('view', User::class);+ $this->authorize('view', $user);$user = User::with(['consumables',@@ -465,7 +463,7 @@ class UsersController extends Controller*/public function getClone(Request $request, User $user){- $this->authorize('create', User::class);+ $this->authorize('create', $user);// We need to reverse the UI specific logic for our// permissions here before we update the user.@@ -634,9 +632,9 @@ class UsersController extends Controller* @since [v1.8]* @author Aladin Alaily*/- public function printInventory($id)+ public function printInventory(User $user, $id){- $this->authorize('view', User::class);+ $this->authorize('view', $user);$user = User::where('id', $id)->with([diff --git a/resources/views/blade/redirect_submit_options.blade.php b/resources/views/blade/redirect_submit_options.blade.phpindex b75bc28e92..c4b6fc4a4c 100644--- a/resources/views/blade/redirect_submit_options.blade.php+++ b/resources/views/blade/redirect_submit_options.blade.php@@ -20,7 +20,7 @@@if (($options) && (count($options) > 0))<select class="redirect-options form-control select2" data-minimum-results-for-search="Infinity" name="redirect_option" style="min-width: 250px"{{ ($disabled_select ? ' disabled' : '') }}>@foreach ($options as $key => $value)- <option value="{{ $key }}"{{ Session::get('redirect_option') == $key ? ' selected' : ''}}>+ <option value="{{ $key }}"{{ session('redirect_option') == $key ? ' selected' : ''}}>{{ $value }}</option>@endforeach