From ae9085b11faddbd9d08f15f527ebc4b01826f178 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 4 Jul 2024 20:49:22 +0100 Subject: [PATCH] Modernize use statements, switch to auth() Signed-off-by: snipe --- .../AssetMaintenancesController.php | 37 +++---- .../AssetModelsFilesController.php | 4 +- .../Assets/AssetCheckinController.php | 4 +- .../Assets/AssetCheckoutController.php | 4 +- .../Assets/AssetFilesController.php | 4 +- .../Controllers/Assets/AssetsController.php | 28 +++--- .../Assets/BulkAssetsController.php | 10 +- app/Http/Controllers/Auth/LoginController.php | 10 +- .../Controllers/BulkAssetModelsController.php | 5 +- app/Http/Controllers/CategoriesController.php | 5 +- app/Http/Controllers/CompaniesController.php | 2 +- .../Components/ComponentCheckinController.php | 2 +- .../ComponentCheckoutController.php | 4 +- .../ConsumableCheckoutController.php | 4 +- app/Http/Controllers/Controller.php | 2 +- .../Controllers/CustomFieldsController.php | 6 +- .../Controllers/CustomFieldsetsController.php | 10 +- app/Http/Controllers/DashboardController.php | 6 +- .../Controllers/DepartmentsController.php | 21 +++- .../Controllers/DepreciationsController.php | 4 +- app/Http/Controllers/GroupsController.php | 6 +- app/Http/Controllers/HealthController.php | 7 +- .../Kits/CheckoutKitController.php | 2 +- .../Kits/PredefinedKitsController.php | 28 +++--- app/Http/Controllers/LabelsController.php | 5 +- .../Licenses/LicenseCheckinController.php | 2 +- .../Licenses/LicenseCheckoutController.php | 4 +- app/Http/Controllers/LocationsController.php | 8 +- .../Controllers/ManufacturersController.php | 6 +- app/Http/Controllers/ModalController.php | 2 +- app/Http/Controllers/ProfileController.php | 18 ++-- app/Http/Controllers/ReportsController.php | 12 +-- app/Http/Controllers/SettingsController.php | 99 ++++++++++--------- .../Controllers/StatuslabelsController.php | 2 +- app/Http/Controllers/SuppliersController.php | 4 +- .../Controllers/Users/BulkUsersController.php | 4 +- .../Controllers/Users/UsersController.php | 12 +-- app/Http/Controllers/ViewAssetsController.php | 17 ++-- app/Http/Middleware/CheckForDebug.php | 2 +- app/Http/Middleware/CheckForTwoFactor.php | 6 +- app/Http/Requests/DeleteUserRequest.php | 4 +- app/Http/Transformers/AssetsTransformer.php | 6 +- app/Importer/AssetImporter.php | 2 +- app/Importer/LocationImporter.php | 2 +- app/Listeners/CheckoutableListener.php | 4 +- app/Livewire/OauthClients.php | 18 ++-- app/Livewire/PersonalAccessTokens.php | 6 +- app/Models/Actionlog.php | 8 +- app/Models/Asset.php | 2 +- app/Models/Company.php | 22 ++--- app/Models/Loggable.php | 16 +-- app/Services/PredefinedKitCheckoutService.php | 2 +- database/factories/CategoryFactory.php | 28 ++++++ resources/lang/en-US/mail.php | 1 + .../forms/edit/company-select.blade.php | 1 - 55 files changed, 286 insertions(+), 254 deletions(-) diff --git a/app/Http/Controllers/AssetMaintenancesController.php b/app/Http/Controllers/AssetMaintenancesController.php index c9ffea9a4c..02be1e6061 100644 --- a/app/Http/Controllers/AssetMaintenancesController.php +++ b/app/Http/Controllers/AssetMaintenancesController.php @@ -2,17 +2,14 @@ namespace App\Http\Controllers; -use App\Helpers\Helper; use App\Models\Asset; use App\Models\AssetMaintenance; use App\Models\Company; use Illuminate\Support\Facades\Auth; use Carbon\Carbon; use Illuminate\Http\Request; -use Slack; -use Str; -use TCPDF; -use View; +use \Illuminate\Contracts\View\View; +use \Illuminate\Http\RedirectResponse; /** * This controller handles all actions related to Asset Maintenance for @@ -29,9 +26,8 @@ class AssetMaintenancesController extends Controller * @author Vincent Sposato * @version v1.0 * @since [v1.8] - * @return View */ - private static function getInsufficientPermissionsRedirect() + private static function getInsufficientPermissionsRedirect(): RedirectResponse { return redirect()->route('maintenances.index') ->with('error', trans('general.insufficient_permissions')); @@ -46,9 +42,8 @@ class AssetMaintenancesController extends Controller * @author Vincent Sposato * @version v1.0 * @since [v1.8] - * @return View */ - public function index() + public function index() : View { $this->authorize('view', Asset::class); return view('asset_maintenances/index'); @@ -63,7 +58,7 @@ class AssetMaintenancesController extends Controller * @since [v1.8] * @return mixed */ - public function create() + public function create() : View { $this->authorize('update', Asset::class); $asset = null; @@ -92,9 +87,8 @@ class AssetMaintenancesController extends Controller * @author Vincent Sposato * @version v1.0 * @since [v1.8] - * @return mixed */ - public function store(Request $request) + public function store(Request $request) : RedirectResponse { $this->authorize('update', Asset::class); // create a new model instance @@ -144,9 +138,8 @@ class AssetMaintenancesController extends Controller * @param int $assetMaintenanceId * @version v1.0 * @since [v1.8] - * @return mixed */ - public function edit($assetMaintenanceId = null) + public function edit($assetMaintenanceId = null) : View | RedirectResponse { $this->authorize('update', Asset::class); // Check if the asset maintenance exists @@ -162,14 +155,9 @@ class AssetMaintenancesController extends Controller return static::getInsufficientPermissionsRedirect(); } - // Prepare Improvement Type List - $assetMaintenanceType = [ - '' => 'Select an improvement type', - ] + AssetMaintenance::getImprovementOptions(); + $assetMaintenanceType = ['' => 'Select an improvement type'] + AssetMaintenance::getImprovementOptions(); - // Get Supplier List - // Render the view return view('asset_maintenances/edit') ->with('selectedAsset', null) ->with('assetMaintenanceType', $assetMaintenanceType) @@ -183,11 +171,10 @@ class AssetMaintenancesController extends Controller * @author Vincent Sposato * @param Request $request * @param int $assetMaintenanceId - * @return mixed * @version v1.0 * @since [v1.8] */ - public function update(Request $request, $assetMaintenanceId = null) + public function update(Request $request, $assetMaintenanceId = null) : View | RedirectResponse { $this->authorize('update', Asset::class); // Check if the asset maintenance exists @@ -255,9 +242,8 @@ class AssetMaintenancesController extends Controller * @param int $assetMaintenanceId * @version v1.0 * @since [v1.8] - * @return mixed */ - public function destroy($assetMaintenanceId) + public function destroy($assetMaintenanceId) : RedirectResponse { $this->authorize('update', Asset::class); // Check if the asset maintenance exists @@ -284,9 +270,8 @@ class AssetMaintenancesController extends Controller * @param int $assetMaintenanceId * @version v1.0 * @since [v1.8] - * @return View */ - public function show($assetMaintenanceId) + public function show($assetMaintenanceId) : View | RedirectResponse { $this->authorize('view', Asset::class); diff --git a/app/Http/Controllers/AssetModelsFilesController.php b/app/Http/Controllers/AssetModelsFilesController.php index c8247ffc15..8e0512801b 100644 --- a/app/Http/Controllers/AssetModelsFilesController.php +++ b/app/Http/Controllers/AssetModelsFilesController.php @@ -54,7 +54,7 @@ class AssetModelsFilesController extends Controller * @param int $modelId * @param int $fileId * @since [v1.0] - * @return View + * @return \Illuminate\Contracts\View\View * @throws \Illuminate\Auth\Access\AuthorizationException */ public function show($modelId = null, $fileId = null) @@ -101,7 +101,7 @@ class AssetModelsFilesController extends Controller * @param int $modelId * @param int $fileId * @since [v1.0] - * @return View + * @return \Illuminate\Contracts\View\View * @throws \Illuminate\Auth\Access\AuthorizationException */ public function destroy($modelId = null, $fileId = null) diff --git a/app/Http/Controllers/Assets/AssetCheckinController.php b/app/Http/Controllers/Assets/AssetCheckinController.php index 73f4838a6a..10aa957942 100644 --- a/app/Http/Controllers/Assets/AssetCheckinController.php +++ b/app/Http/Controllers/Assets/AssetCheckinController.php @@ -26,7 +26,7 @@ class AssetCheckinController extends Controller * @author [A. Gianotto] [] * @param int $assetId * @param string $backto - * @return View + * @return \Illuminate\Contracts\View\View * @throws \Illuminate\Auth\Access\AuthorizationException * @since [v1.0] */ @@ -136,7 +136,7 @@ class AssetCheckinController extends Controller // Was the asset updated? if ($asset->save()) { - event(new CheckoutableCheckedIn($asset, $target, Auth::user(), $request->input('note'), $checkin_at, $originalValues)); + event(new CheckoutableCheckedIn($asset, $target, auth()->user(), $request->input('note'), $checkin_at, $originalValues)); return Helper::getRedirectOption($asset, $assetId, 'Assets'); } // Redirect to the asset management page with error diff --git a/app/Http/Controllers/Assets/AssetCheckoutController.php b/app/Http/Controllers/Assets/AssetCheckoutController.php index 36f00f0fc6..dfc11f1fc7 100644 --- a/app/Http/Controllers/Assets/AssetCheckoutController.php +++ b/app/Http/Controllers/Assets/AssetCheckoutController.php @@ -23,7 +23,7 @@ class AssetCheckoutController extends Controller * @author [A. Gianotto] [] * @param int $assetId * @since [v1.0] - * @return View + * @return \Illuminate\Contracts\View\View */ public function create($assetId) { @@ -72,7 +72,7 @@ class AssetCheckoutController extends Controller return redirect()->route('hardware.show', $asset->id)->with('error', trans('admin/hardware/general.model_invalid_fix')); } - $admin = Auth::user(); + $admin = auth()->user(); $target = $this->determineCheckoutTarget(); diff --git a/app/Http/Controllers/Assets/AssetFilesController.php b/app/Http/Controllers/Assets/AssetFilesController.php index 01ff0288ef..fcd3375f8d 100644 --- a/app/Http/Controllers/Assets/AssetFilesController.php +++ b/app/Http/Controllers/Assets/AssetFilesController.php @@ -54,7 +54,7 @@ class AssetFilesController extends Controller * @param int $assetId * @param int $fileId * @since [v1.0] - * @return View + * @return \Illuminate\Contracts\View\View * @throws \Illuminate\Auth\Access\AuthorizationException */ public function show($assetId = null, $fileId = null) @@ -105,7 +105,7 @@ class AssetFilesController extends Controller * @param int $assetId * @param int $fileId * @since [v1.0] - * @return View + * @return \Illuminate\Contracts\View\View * @throws \Illuminate\Auth\Access\AuthorizationException */ public function destroy($assetId = null, $fileId = null) diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index 82c68eb01a..ec258b88ec 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -55,7 +55,7 @@ class AssetsController extends Controller * @see AssetController::getDatatable() method that generates the JSON response * @since [v1.0] * @param Request $request - * @return View + * @return \Illuminate\Contracts\View\View * @throws \Illuminate\Auth\Access\AuthorizationException */ public function index(Request $request) @@ -72,7 +72,7 @@ class AssetsController extends Controller * @author [A. Gianotto] [] * @since [v1.0] * @param Request $request - * @return View + * @return \Illuminate\Contracts\View\View * @internal param int $model_id */ public function create(Request $request) @@ -198,7 +198,7 @@ class AssetsController extends Controller } if (isset($target)) { - $asset->checkOut($target, Auth::user(), date('Y-m-d H:i:s'), $request->input('expected_checkin', null), 'Checked out on asset creation', $request->get('name'), $location); + $asset->checkOut($target, auth()->user(), date('Y-m-d H:i:s'), $request->input('expected_checkin', null), 'Checked out on asset creation', $request->get('name'), $location); } $success = true; @@ -229,7 +229,7 @@ class AssetsController extends Controller * @author [A. Gianotto] [] * @param int $assetId * @since [v1.0] - * @return View + * @return \Illuminate\Contracts\View\View */ public function edit($assetId = null) { @@ -252,7 +252,7 @@ class AssetsController extends Controller * @author [A. Gianotto] [] * @param int $assetId * @since [v1.0] - * @return View + * @return \Illuminate\Contracts\View\View */ public function show($assetId = null) { @@ -561,7 +561,7 @@ class AssetsController extends Controller * * @author [L. Swartzendruber] [ * @param int $assetId - * @return View + * @return \Illuminate\Contracts\View\View */ public function getLabel($assetId = null) { @@ -585,7 +585,7 @@ class AssetsController extends Controller * @author [A. Gianotto] [] * @param int $assetId * @since [v1.0] - * @return View + * @return \Illuminate\Contracts\View\View */ public function getClone($assetId = null) { @@ -614,7 +614,7 @@ class AssetsController extends Controller * * @author [A. Gianotto] [] * @since [v1.0] - * @return View + * @return \Illuminate\Contracts\View\View */ public function getImportHistory() { @@ -636,7 +636,7 @@ class AssetsController extends Controller * * @author [A. Gianotto] [] * @since [v3.3] - * @return View + * @return \Illuminate\Contracts\View\View */ public function postImportHistory(Request $request) { @@ -730,8 +730,8 @@ class AssetsController extends Controller Actionlog::firstOrCreate([ 'item_id' => $asset->id, 'item_type' => Asset::class, - 'user_id' => Auth::user()->id, - 'note' => 'Checkout imported by '.Auth::user()->present()->fullName().' from history importer', + 'user_id' => auth()->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'], @@ -758,8 +758,8 @@ class AssetsController extends Controller Actionlog::firstOrCreate([ 'item_id' => $item[$asset_tag][$batch_counter]['asset_id'], 'item_type' => Asset::class, - 'user_id' => Auth::user()->id, - 'note' => 'Checkin imported by '.Auth::user()->present()->fullName().' from history importer', + 'user_id' => auth()->id(), + 'note' => 'Checkin imported by '.auth()->user()->present()->fullName().' from history importer', 'target_id' => null, 'created_at' => $checkin_date, 'action_type' => 'checkin', @@ -796,7 +796,7 @@ class AssetsController extends Controller * @author [A. Gianotto] [] * @param int $assetId * @since [v1.0] - * @return View + * @return \Illuminate\Contracts\View\View */ public function getRestore($assetId = null) { diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index ffbf81944b..c2b5c73696 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -36,7 +36,7 @@ class BulkAssetsController extends Controller * action would make a lot more sense here and make things a lot more clear. * * @author [A. Gianotto] [] - * @return View + * @return \Illuminate\Contracts\View\View * @internal param int $assetId * @since [v2.0] * @throws \Illuminate\Auth\Access\AuthorizationException @@ -471,7 +471,7 @@ class BulkAssetsController extends Controller * * @author [A. Gianotto] [] * @param Request $request - * @return View + * @return \Illuminate\Contracts\View\View * @throws \Illuminate\Auth\Access\AuthorizationException * @internal param array $assets * @since [v2.0] @@ -505,7 +505,7 @@ class BulkAssetsController extends Controller /** * Show Bulk Checkout Page - * @return View View to checkout multiple assets + * @return \Illuminate\Contracts\View\View View to checkout multiple assets */ public function showCheckout() { @@ -517,7 +517,7 @@ class BulkAssetsController extends Controller /** * Process Multiple Checkout Request - * @return View + * @return \Illuminate\Contracts\View\View */ public function storeCheckout(AssetCheckoutRequest $request) { @@ -525,7 +525,7 @@ class BulkAssetsController extends Controller $this->authorize('checkout', Asset::class); try { - $admin = Auth::user(); + $admin = auth()->user(); $target = $this->determineCheckoutTarget(); diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index ac19a57a72..9ac976b43c 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -127,7 +127,7 @@ class LoginController extends Controller $saml->clearData(); } - if ($user = Auth::user()) { + if ($user = auth()->user()) { $user->last_login = \Carbon::now(); $user->saveQuietly(); } @@ -326,7 +326,7 @@ class LoginController extends Controller } } - if ($user = Auth::user()) { + if ($user = auth()->user()) { $user->last_login = \Carbon::now(); $user->activated = 1; $user->saveQuietly(); @@ -350,7 +350,7 @@ class LoginController extends Controller } $settings = Setting::getSettings(); - $user = Auth::user(); + $user = auth()->user(); // We wouldn't normally see this page if 2FA isn't enforced via the // \App\Http\Middleware\CheckForTwoFactor middleware AND if a device isn't enrolled, @@ -398,7 +398,7 @@ class LoginController extends Controller return redirect()->route('login')->with('error', trans('auth/general.login_prompt')); } - $user = Auth::user(); + $user = auth()->user(); // Check whether there is a device enrolled. // This *should* be handled via the \App\Http\Middleware\CheckForTwoFactor middleware @@ -427,7 +427,7 @@ class LoginController extends Controller return redirect()->route('two-factor')->with('error', trans('auth/message.two_factor.code_required')); } - $user = Auth::user(); + $user = auth()->user(); $secret = $request->input('two_factor_secret'); if (Google2FA::verifyKey($user->two_factor_secret, $secret)) { diff --git a/app/Http/Controllers/BulkAssetModelsController.php b/app/Http/Controllers/BulkAssetModelsController.php index 5437791aa8..672fc30079 100644 --- a/app/Http/Controllers/BulkAssetModelsController.php +++ b/app/Http/Controllers/BulkAssetModelsController.php @@ -5,7 +5,6 @@ namespace App\Http\Controllers; use App\Helpers\Helper; use App\Models\AssetModel; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Input; use Illuminate\Support\Facades\Redirect; class BulkAssetModelsController extends Controller @@ -16,7 +15,7 @@ class BulkAssetModelsController extends Controller * @author [A. Gianotto] [] * @since [v1.7] * @param Request $request - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse */ public function edit(Request $request) { @@ -61,7 +60,7 @@ class BulkAssetModelsController extends Controller * @author [A. Gianotto] [] * @since [v1.7] * @param Request $request - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse */ public function update(Request $request) { diff --git a/app/Http/Controllers/CategoriesController.php b/app/Http/Controllers/CategoriesController.php index d7e83b43d8..c6a51f1b03 100755 --- a/app/Http/Controllers/CategoriesController.php +++ b/app/Http/Controllers/CategoriesController.php @@ -7,7 +7,6 @@ use App\Http\Requests\ImageUploadRequest; use App\Models\Category as Category; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Storage; -use Str; /** * This class controls all actions related to Categories for @@ -91,7 +90,7 @@ class CategoriesController extends Controller * @see CategoriesController::postEdit() method saves the data * @param int $categoryId * @since [v1.0] - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse * @throws \Illuminate\Auth\Access\AuthorizationException */ public function edit($categoryId = null) @@ -178,7 +177,7 @@ class CategoriesController extends Controller * @author [A. Gianotto] [] * @see CategoriesController::getDataView() method that generates the JSON response * @param $id - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse * @throws \Illuminate\Auth\Access\AuthorizationException * @since [v1.8] */ diff --git a/app/Http/Controllers/CompaniesController.php b/app/Http/Controllers/CompaniesController.php index 63205a598d..646f2c4384 100644 --- a/app/Http/Controllers/CompaniesController.php +++ b/app/Http/Controllers/CompaniesController.php @@ -81,7 +81,7 @@ final class CompaniesController extends Controller * @author [Abdullah Alansari] [] * @since [v1.8] * @param int $companyId - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse * @throws \Illuminate\Auth\Access\AuthorizationException */ public function edit($companyId) diff --git a/app/Http/Controllers/Components/ComponentCheckinController.php b/app/Http/Controllers/Components/ComponentCheckinController.php index 9f4724e353..b59237a5d0 100644 --- a/app/Http/Controllers/Components/ComponentCheckinController.php +++ b/app/Http/Controllers/Components/ComponentCheckinController.php @@ -95,7 +95,7 @@ class ComponentCheckinController extends Controller $asset = Asset::find($component_assets->asset_id); - event(new CheckoutableCheckedIn($component, $asset, Auth::user(), $request->input('note'), Carbon::now())); + event(new CheckoutableCheckedIn($component, $asset, auth()->user(), $request->input('note'), Carbon::now())); if ($backto == 'asset'){ return redirect()->route('hardware.show', $asset->id)->with('success', trans('admin/components/message.checkin.success')); diff --git a/app/Http/Controllers/Components/ComponentCheckoutController.php b/app/Http/Controllers/Components/ComponentCheckoutController.php index 79ff57e7df..fc319b47de 100644 --- a/app/Http/Controllers/Components/ComponentCheckoutController.php +++ b/app/Http/Controllers/Components/ComponentCheckoutController.php @@ -100,14 +100,14 @@ class ComponentCheckoutController extends Controller $component->asset_id = $request->input('asset_id'); $component->assets()->attach($component->id, [ 'component_id' => $component->id, - 'user_id' => Auth::user(), + 'user_id' => auth()->user(), 'created_at' => date('Y-m-d H:i:s'), 'assigned_qty' => $request->input('assigned_qty'), 'asset_id' => $request->input('asset_id'), 'note' => $request->input('note'), ]); - event(new CheckoutableCheckedOut($component, $asset, Auth::user(), $request->input('note'))); + event(new CheckoutableCheckedOut($component, $asset, auth()->user(), $request->input('note'))); return redirect()->route('components.index')->with('success', trans('admin/components/message.checkout.success')); } diff --git a/app/Http/Controllers/Consumables/ConsumableCheckoutController.php b/app/Http/Controllers/Consumables/ConsumableCheckoutController.php index d838ee5696..919cd1698f 100644 --- a/app/Http/Controllers/Consumables/ConsumableCheckoutController.php +++ b/app/Http/Controllers/Consumables/ConsumableCheckoutController.php @@ -82,7 +82,7 @@ class ConsumableCheckoutController extends Controller return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.checkout.unavailable')); } - $admin_user = Auth::user(); + $admin_user = auth()->user(); $assigned_to = e($request->input('assigned_to')); // Check if the user exists @@ -102,7 +102,7 @@ class ConsumableCheckoutController extends Controller 'note' => $request->input('note'), ]); } - event(new CheckoutableCheckedOut($consumable, $user, Auth::user(), $request->input('note'))); + event(new CheckoutableCheckedOut($consumable, $user, auth()->user(), $request->input('note'))); // Redirect to the new consumable page return redirect()->route('consumables.index')->with('success', trans('admin/consumables/message.checkout.success')); diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index c716fff368..74fff19a37 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -35,6 +35,6 @@ abstract class Controller extends BaseController public function __construct() { view()->share('signedIn', Auth::check()); - view()->share('user', Auth::user()); + view()->share('user', auth()->user()); } } diff --git a/app/Http/Controllers/CustomFieldsController.php b/app/Http/Controllers/CustomFieldsController.php index 94b45552fd..43d2fbfab1 100644 --- a/app/Http/Controllers/CustomFieldsController.php +++ b/app/Http/Controllers/CustomFieldsController.php @@ -25,7 +25,7 @@ class CustomFieldsController extends Controller * * @author [Brady Wetherington] [] * @since [v1.8] - * @return \Illuminate\Support\Facades\View + * @return \Illuminate\Contracts\View\View * @throws \Illuminate\Auth\Access\AuthorizationException */ public function index() @@ -60,7 +60,7 @@ class CustomFieldsController extends Controller * @see CustomFieldsController::storeField() * @author [Brady Wetherington] [] * @since [v1.8] - * @return \Illuminate\Support\Facades\View + * @return \Illuminate\Contracts\View\View * @throws \Illuminate\Auth\Access\AuthorizationException */ public function create(Request $request) @@ -202,7 +202,7 @@ class CustomFieldsController extends Controller * @author [A. Gianotto] [] * @param int $id * @since [v4.0] - * @return \Illuminate\Support\Facades\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse * @throws \Illuminate\Auth\Access\AuthorizationException */ public function edit(Request $request, $id) diff --git a/app/Http/Controllers/CustomFieldsetsController.php b/app/Http/Controllers/CustomFieldsetsController.php index e4382a31ea..64ba9dfb1c 100644 --- a/app/Http/Controllers/CustomFieldsetsController.php +++ b/app/Http/Controllers/CustomFieldsetsController.php @@ -34,7 +34,7 @@ class CustomFieldsetsController extends Controller * * @author [Brady Wetherington] [] * @param int $id - * @return \Illuminate\Support\Facades\View + * @return \Illuminate\Contracts\View\View * @throws \Illuminate\Auth\Access\AuthorizationException * @since [v1.8] */ @@ -70,7 +70,7 @@ class CustomFieldsetsController extends Controller * * @author [Brady Wetherington] [] * @since [v1.8] - * @return \Illuminate\Support\Facades\View + * @return \Illuminate\Contracts\View\View * @throws \Illuminate\Auth\Access\AuthorizationException */ public function create() @@ -95,7 +95,7 @@ class CustomFieldsetsController extends Controller $fieldset = new CustomFieldset([ 'name' => $request->get('name'), - 'user_id' => Auth::user()->id, + 'user_id' => auth()->id(), ]); $validator = Validator::make($request->all(), $fieldset->rules); @@ -175,7 +175,7 @@ class CustomFieldsetsController extends Controller * @author [Brady Wetherington] [] * @param int $id * @since [v1.8] - * @return View + * @return \Illuminate\Contracts\View\View * @throws \Illuminate\Auth\Access\AuthorizationException */ public function destroy($id) @@ -203,7 +203,7 @@ class CustomFieldsetsController extends Controller * * @author [Brady Wetherington] [] * @since [v1.8] - * @return View + * @return \Illuminate\Contracts\View\View */ public function associate(Request $request, $id) { diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 89283a7c21..2366503c64 100755 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -21,12 +21,12 @@ class DashboardController extends Controller * * @author [A. Gianotto] [] * @since [v1.0] - * @return View + * @return \Illuminate\Contracts\View\View */ public function index() { // Show the page - if (Auth::user()->hasAccess('admin')) { + if (auth()->user()->hasAccess('admin')) { $asset_stats = null; $counts['asset'] = \App\Models\Asset::count(); @@ -34,7 +34,7 @@ class DashboardController extends Controller $counts['license'] = \App\Models\License::assetcount(); $counts['consumable'] = \App\Models\Consumable::count(); $counts['component'] = \App\Models\Component::count(); - $counts['user'] = \App\Models\Company::scopeCompanyables(Auth::user())->count(); + $counts['user'] = \App\Models\Company::scopeCompanyables(auth()->user())->count(); $counts['grand_total'] = $counts['asset'] + $counts['accessory'] + $counts['license'] + $counts['consumable']; if ((! file_exists(storage_path().'/oauth-private.key')) || (! file_exists(storage_path().'/oauth-public.key'))) { diff --git a/app/Http/Controllers/DepartmentsController.php b/app/Http/Controllers/DepartmentsController.php index 62823098ba..51de30c88e 100644 --- a/app/Http/Controllers/DepartmentsController.php +++ b/app/Http/Controllers/DepartmentsController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers; use App\Http\Requests\ImageUploadRequest; use App\Models\Department; +use App\Models\Company; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Storage; @@ -25,7 +26,7 @@ class DepartmentsController extends Controller * @see AssetController::getDatatable() method that generates the JSON response * @since [v4.0] * @param Request $request - * @return \Illuminate\Support\Facades\View + * @return \Illuminate\Contracts\View\View * @throws \Illuminate\Auth\Access\AuthorizationException */ public function index(Request $request) @@ -45,7 +46,7 @@ class DepartmentsController extends Controller * @author [A. Gianotto] [] * @since [v4.0] * @param ImageUploadRequest $request - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\RedirectResponse * @throws \Illuminate\Auth\Access\AuthorizationException */ public function store(ImageUploadRequest $request) @@ -53,7 +54,7 @@ class DepartmentsController extends Controller $this->authorize('create', Department::class); $department = new Department; $department->fill($request->all()); - $department->user_id = Auth::user()->id; + $department->user_id = auth()->id(); $department->manager_id = ($request->filled('manager_id') ? $request->input('manager_id') : null); $department->location_id = ($request->filled('location_id') ? $request->input('location_id') : null); $department->company_id = ($request->filled('company_id') ? $request->input('company_id') : null); @@ -73,7 +74,7 @@ class DepartmentsController extends Controller * @author [A. Gianotto] [] * @param int $id * @since [v4.0] - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse * @throws \Illuminate\Auth\Access\AuthorizationException */ public function show($id) @@ -145,7 +146,7 @@ class DepartmentsController extends Controller * @see LocationsController::postCreate() method that validates and stores * @param int $departmentId * @since [v1.0] - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse * @throws \Illuminate\Auth\Access\AuthorizationException */ public function edit($departmentId = null) @@ -159,6 +160,16 @@ class DepartmentsController extends Controller return view('departments/edit', compact('item')); } + /** + * Save updated Department information. + * + * @author [A. Gianotto] [] + * @see LocationsController::postCreate() method that validates and stores + * @param int $departmentId + * @since [v1.0] + * @return \Illuminate\Http\RedirectResponse + * @throws \Illuminate\Auth\Access\AuthorizationException + */ public function update(ImageUploadRequest $request, $id) { if (is_null($department = Department::find($id))) { diff --git a/app/Http/Controllers/DepreciationsController.php b/app/Http/Controllers/DepreciationsController.php index 70bfb78cb5..f453e4998e 100755 --- a/app/Http/Controllers/DepreciationsController.php +++ b/app/Http/Controllers/DepreciationsController.php @@ -87,7 +87,7 @@ class DepreciationsController extends Controller * @see DepreciationsController::postEdit() * @param int $depreciationId * @since [v1.0] - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse * @throws \Illuminate\Auth\Access\AuthorizationException */ public function edit($depreciationId = null) @@ -175,7 +175,7 @@ class DepreciationsController extends Controller * @see DepreciationsController::postEdit() * @param int $depreciationId * @since [v1.0] - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse * @throws \Illuminate\Auth\Access\AuthorizationException */ public function show($id) diff --git a/app/Http/Controllers/GroupsController.php b/app/Http/Controllers/GroupsController.php index bfc8907524..9cb68e3a7a 100755 --- a/app/Http/Controllers/GroupsController.php +++ b/app/Http/Controllers/GroupsController.php @@ -64,7 +64,7 @@ class GroupsController extends Controller $group = new Group(); $group->name = $request->input('name'); $group->permissions = json_encode($request->input('permission')); - $group->created_by = Auth::user()->id; + $group->created_by = auth()->id(); if ($group->save()) { return redirect()->route('groups.index')->with('success', trans('admin/groups/message.success.create')); @@ -80,7 +80,7 @@ class GroupsController extends Controller * @see GroupsController::postEdit() * @param int $id * @since [v1.0] - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse */ public function edit($id) { @@ -154,7 +154,7 @@ class GroupsController extends Controller * * @author [A. Gianotto] [] * @param $id - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse * @since [v4.0.11] */ public function show($id) diff --git a/app/Http/Controllers/HealthController.php b/app/Http/Controllers/HealthController.php index 456f6b6f94..c75b903b0b 100644 --- a/app/Http/Controllers/HealthController.php +++ b/app/Http/Controllers/HealthController.php @@ -5,10 +5,13 @@ namespace App\Http\Controllers; use Illuminate\Routing\Controller as BaseController; /** - * This controller provide the healthz route for + * This controller provide the health route for * the Snipe-IT Asset Management application. * - * @version v1.0 + * @version v1.0 + * + * @return \Illuminate\Http\JsonResponse + */ class HealthController extends BaseController { diff --git a/app/Http/Controllers/Kits/CheckoutKitController.php b/app/Http/Controllers/Kits/CheckoutKitController.php index d806f7d170..c75e4ea8f0 100644 --- a/app/Http/Controllers/Kits/CheckoutKitController.php +++ b/app/Http/Controllers/Kits/CheckoutKitController.php @@ -33,7 +33,7 @@ class CheckoutKitController extends Controller * Show Bulk Checkout Page * * @author [D. Minaev.] [] - * @return View View to checkout + * @return \Illuminate\Contracts\View\View View to checkout */ public function showCheckout($kit_id) { diff --git a/app/Http/Controllers/Kits/PredefinedKitsController.php b/app/Http/Controllers/Kits/PredefinedKitsController.php index 67d148b5ee..187f5aad14 100644 --- a/app/Http/Controllers/Kits/PredefinedKitsController.php +++ b/app/Http/Controllers/Kits/PredefinedKitsController.php @@ -73,7 +73,7 @@ class PredefinedKitsController extends Controller * @author [D. Minaev] [] * @since [v1.0] * @param int $kit_id - * @return View + * @return \Illuminate\Contracts\View\View */ public function edit($kit_id = null) { @@ -150,7 +150,7 @@ class PredefinedKitsController extends Controller * @author [D. Minaev] [] * @since [v1.0] * @param int $modelId - * @return View + * @return \Illuminate\Contracts\View\View */ public function show($kit_id = null) { @@ -162,7 +162,7 @@ class PredefinedKitsController extends Controller * * @author [D. Minaev] [] * @param int $kit_id - * @return View + * @return \Illuminate\Contracts\View\View */ public function editModel($kit_id, $model_id) { @@ -184,7 +184,7 @@ class PredefinedKitsController extends Controller * * @author [D. Minaev] [] * @param int $modelId - * @return View + * @return \Illuminate\Contracts\View\View */ public function updateModel(Request $request, $kit_id, $model_id) { @@ -214,7 +214,7 @@ class PredefinedKitsController extends Controller * * @author [D. Minaev] [] * @param int $modelId - * @return View + * @return \Illuminate\Contracts\View\View */ public function detachModel($kit_id, $model_id) { @@ -237,7 +237,7 @@ class PredefinedKitsController extends Controller * @author [D. Minaev] [] * @param int $kit_id * @param int $license_id - * @return View + * @return \Illuminate\Contracts\View\View */ public function editLicense($kit_id, $license_id) { @@ -262,7 +262,7 @@ class PredefinedKitsController extends Controller * @author [D. Minaev] [] * @param int $kit_id * @param int $license_id - * @return View + * @return \Illuminate\Contracts\View\View */ public function updateLicense(Request $request, $kit_id, $license_id) { @@ -293,7 +293,7 @@ class PredefinedKitsController extends Controller * @author [D. Minaev] [] * @param int $kit_id * @param int $license_id - * @return View + * @return \Illuminate\Contracts\View\View */ public function detachLicense($kit_id, $license_id) { @@ -316,7 +316,7 @@ class PredefinedKitsController extends Controller * @author [D. Minaev] [] * @param int $kit_id * @param int $accessoryId - * @return View + * @return \Illuminate\Contracts\View\View */ public function editAccessory($kit_id, $accessory_id) { @@ -341,7 +341,7 @@ class PredefinedKitsController extends Controller * @author [D. Minaev] [] * @param int $kit_id * @param int $accessory_id - * @return View + * @return \Illuminate\Contracts\View\View */ public function updateAccessory(Request $request, $kit_id, $accessory_id) { @@ -371,7 +371,7 @@ class PredefinedKitsController extends Controller * * @author [D. Minaev] [] * @param int $accessory_id - * @return View + * @return \Illuminate\Contracts\View\View */ public function detachAccessory($kit_id, $accessory_id) { @@ -394,7 +394,7 @@ class PredefinedKitsController extends Controller * @author [D. Minaev] [] * @param int $kit_id * @param int $consumable_id - * @return View + * @return \Illuminate\Contracts\View\View */ public function editConsumable($kit_id, $consumable_id) { @@ -419,7 +419,7 @@ class PredefinedKitsController extends Controller * @author [D. Minaev] [] * @param int $kit_id * @param int $consumableId - * @return View + * @return \Illuminate\Contracts\View\View */ public function updateConsumable(Request $request, $kit_id, $consumable_id) { @@ -449,7 +449,7 @@ class PredefinedKitsController extends Controller * * @author [D. Minaev] [] * @param int $consumable_id - * @return View + * @return \Illuminate\Contracts\View\View */ public function detachConsumable($kit_id, $consumable_id) { diff --git a/app/Http/Controllers/LabelsController.php b/app/Http/Controllers/LabelsController.php index 1c5715b35f..98b030d85c 100755 --- a/app/Http/Controllers/LabelsController.php +++ b/app/Http/Controllers/LabelsController.php @@ -14,8 +14,6 @@ use App\Models\Setting; use App\Models\Supplier; use App\Models\User; use App\View\Label as LabelView; -use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Storage; class LabelsController extends Controller { @@ -23,7 +21,7 @@ class LabelsController extends Controller * Returns the Label view with test data * * @param string $labelName - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse * @author Grant Le Roux */ public function show(string $labelName) @@ -96,6 +94,5 @@ class LabelsController extends Controller ->with('bulkedit', false) ->with('count', 0); - return redirect()->route('home')->with('error', trans('admin/labels/message.does_not_exist')); } } diff --git a/app/Http/Controllers/Licenses/LicenseCheckinController.php b/app/Http/Controllers/Licenses/LicenseCheckinController.php index be71dfc4d2..e863aa860e 100644 --- a/app/Http/Controllers/Licenses/LicenseCheckinController.php +++ b/app/Http/Controllers/Licenses/LicenseCheckinController.php @@ -102,7 +102,7 @@ class LicenseCheckinController extends Controller // Was the asset updated? if ($licenseSeat->save()) { - event(new CheckoutableCheckedIn($licenseSeat, $return_to, Auth::user(), $request->input('notes'))); + event(new CheckoutableCheckedIn($licenseSeat, $return_to, auth()->user(), $request->input('notes'))); if ($backTo == 'user') { return redirect()->route('users.show', $return_to->id)->with('success', trans('admin/licenses/message.checkin.success')); diff --git a/app/Http/Controllers/Licenses/LicenseCheckoutController.php b/app/Http/Controllers/Licenses/LicenseCheckoutController.php index d3887d365c..83bcb52a7c 100644 --- a/app/Http/Controllers/Licenses/LicenseCheckoutController.php +++ b/app/Http/Controllers/Licenses/LicenseCheckoutController.php @@ -119,7 +119,7 @@ class LicenseCheckoutController extends Controller $licenseSeat->assigned_to = $target->assigned_to; } if ($licenseSeat->save()) { - event(new CheckoutableCheckedOut($licenseSeat, $target, Auth::user(), request('notes'))); + event(new CheckoutableCheckedOut($licenseSeat, $target, auth()->user(), request('notes'))); return true; } @@ -136,7 +136,7 @@ class LicenseCheckoutController extends Controller $licenseSeat->assigned_to = request('assigned_to'); if ($licenseSeat->save()) { - event(new CheckoutableCheckedOut($licenseSeat, $target, Auth::user(), request('notes'))); + event(new CheckoutableCheckedOut($licenseSeat, $target, auth()->user(), request('notes'))); return true; } diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php index 938c76fe12..dcdd937429 100755 --- a/app/Http/Controllers/LocationsController.php +++ b/app/Http/Controllers/LocationsController.php @@ -100,7 +100,7 @@ class LocationsController extends Controller * @see LocationsController::postCreate() method that validates and stores * @param int $locationId * @since [v1.0] - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse * @throws \Illuminate\Auth\Access\AuthorizationException */ public function edit($locationId = null) @@ -202,7 +202,7 @@ class LocationsController extends Controller * @author [A. Gianotto] [] * @param int $id * @since [v1.0] - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse */ public function show($id = null) { @@ -240,7 +240,7 @@ class LocationsController extends Controller * @author [A. Gianotto] [] * @param int $locationId * @since [v6.0.14] - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse */ public function getClone($locationId = null) { @@ -282,7 +282,7 @@ class LocationsController extends Controller * * @author [A. Gianotto] [] * @since [v6.3.1] - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse */ public function postBulkDelete(Request $request) { diff --git a/app/Http/Controllers/ManufacturersController.php b/app/Http/Controllers/ManufacturersController.php index 833c5b6977..78b7a04407 100755 --- a/app/Http/Controllers/ManufacturersController.php +++ b/app/Http/Controllers/ManufacturersController.php @@ -92,7 +92,7 @@ class ManufacturersController extends Controller * @see ManufacturersController::update() * @param int $manufacturerId * @since [v1.0] - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse * @throws \Illuminate\Auth\Access\AuthorizationException */ public function edit($manufacturerId = null) @@ -197,7 +197,7 @@ class ManufacturersController extends Controller * @author [A. Gianotto] [] * @param int $manufacturerId * @since [v1.0] - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse * @throws \Illuminate\Auth\Access\AuthorizationException */ public function show($manufacturerId = null) @@ -238,7 +238,7 @@ class ManufacturersController extends Controller $logaction->item_type = Manufacturer::class; $logaction->item_id = $manufacturer->id; $logaction->created_at = date('Y-m-d H:i:s'); - $logaction->user_id = Auth::user()->id; + $logaction->user_id = auth()->id(); $logaction->logaction('restore'); // Redirect them to the deleted page if there are more, otherwise the section index diff --git a/app/Http/Controllers/ModalController.php b/app/Http/Controllers/ModalController.php index 6f6b39dd12..fab491a5f4 100644 --- a/app/Http/Controllers/ModalController.php +++ b/app/Http/Controllers/ModalController.php @@ -15,7 +15,7 @@ class ModalController extends Controller * @version v5.3.7-pre * @author [Brady Wetherington] [] * @author [A. Gianotto] [authorize('self.profile'); - $user = Auth::user(); + $user = auth()->user(); return view('account/profile', compact('user')); } @@ -43,7 +43,7 @@ class ProfileController extends Controller public function postIndex(ImageUploadRequest $request) { $this->authorize('self.profile'); - $user = Auth::user(); + $user = auth()->user(); $user->first_name = $request->input('first_name'); $user->last_name = $request->input('last_name'); $user->website = $request->input('website'); @@ -97,11 +97,11 @@ class ProfileController extends Controller /** * User change email page. * - * @return View + * @return \Illuminate\Contracts\View\View */ public function password() { - $user = Auth::user(); + $user = auth()->user(); return view('account/change-password', compact('user')); } @@ -117,7 +117,7 @@ class ProfileController extends Controller return redirect()->route('account.password.index')->with('error', trans('admin/users/table.lock_passwords')); } - $user = Auth::user(); + $user = auth()->user(); if ($user->ldap_import == '1') { return redirect()->route('account.password.index')->with('error', trans('admin/users/message.error.password_ldap')); } @@ -178,7 +178,7 @@ class ProfileController extends Controller * * @author [A. Gianotto] [] * @since [v4.0] - * @return View + * @return \Illuminate\Contracts\View\View */ public function getMenuState(Request $request) { @@ -199,10 +199,10 @@ class ProfileController extends Controller */ public function printInventory() { - $show_user = Auth::user(); + $show_user = auth()->user(); return view('users/print') - ->with('assets', Auth::user()->assets) + ->with('assets', auth()->user()->assets) ->with('licenses', $show_user->licenses()->get()) ->with('accessories', $show_user->accessories()->get()) ->with('consumables', $show_user->consumables()->get()) @@ -220,7 +220,7 @@ class ProfileController extends Controller public function emailAssetList() { - if (!$user = User::find(Auth::user()->id)) { + if (!$user = User::find(auth()->id())) { return redirect()->back() ->with('error', trans('admin/users/message.user_not_found', ['id' => $id])); } diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 67a73d0dc0..16c2c33893 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -47,7 +47,7 @@ class ReportsController extends Controller * * @author [A. Gianotto] [] * @since [v1.0] - * @return View + * @return \Illuminate\Contracts\View\View */ public function getAccessoryReport() { @@ -104,7 +104,7 @@ class ReportsController extends Controller * * @author [A. Gianotto] [] * @since [v1.0] - * @return View + * @return \Illuminate\Contracts\View\View */ public function getDeprecationReport() { @@ -197,7 +197,7 @@ class ReportsController extends Controller * * @author [A. Gianotto] [] * @since [v4.0] - * @return View + * @return \Illuminate\Contracts\View\View */ public function audit() { @@ -212,7 +212,7 @@ class ReportsController extends Controller * * @author [A. Gianotto] [] * @since [v1.0] - * @return View + * @return \Illuminate\Contracts\View\View */ public function getActivityReport() { @@ -328,7 +328,7 @@ class ReportsController extends Controller * * @author [A. Gianotto] [] * @since [v1.0] - * @return View + * @return \Illuminate\Contracts\View\View */ public function getLicenseReport() { @@ -1015,7 +1015,7 @@ class ReportsController extends Controller /** * getImprovementsReport * - * @return View + * @return \Illuminate\Contracts\View\View * @author Vincent Sposato * @version v1.0 */ diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 7fefbf9090..0fa3084109 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -19,7 +19,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Storage; use Illuminate\Validation\Rule; -use Redirect; +use Illuminate\View\View; use Illuminate\Support\Str; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Auth; @@ -47,7 +47,7 @@ class SettingsController extends Controller * * @since [v3.0] * - * @return View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\Response */ public function getSetupIndex() { @@ -215,7 +215,7 @@ class SettingsController extends Controller * * @since [v3.0] * - * @return View + * @return \Illuminate\Contracts\View\View */ public function getSetupUser() { @@ -231,7 +231,7 @@ class SettingsController extends Controller * * @since [v3.0] * - * @return View + * @return \Illuminate\Contracts\View\View */ public function getSetupDone() { @@ -248,7 +248,7 @@ class SettingsController extends Controller * * @since [v3.0] * - * @return View + * @return \Illuminate\Contracts\View\View */ public function getSetupMigrate() { @@ -271,7 +271,7 @@ class SettingsController extends Controller * * @since [v1.0] * - * @return View + * @return \Illuminate\Contracts\View\View */ public function index() { @@ -287,7 +287,7 @@ class SettingsController extends Controller * * @since [v1.0] * - * @return View + * @return \Illuminate\Contracts\View\View */ public function getEdit() { @@ -303,7 +303,7 @@ class SettingsController extends Controller * * @since [v1.0] * - * @return View + * @return \Illuminate\Contracts\View\View */ public function getSettings() { @@ -319,7 +319,7 @@ class SettingsController extends Controller * * @since [v1.0] * - * @return View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse */ public function postSettings(Request $request) { @@ -376,7 +376,7 @@ class SettingsController extends Controller * * @since [v1.0] * - * @return View + * @return \Illuminate\Contracts\View\View */ public function getBranding() { @@ -494,7 +494,7 @@ class SettingsController extends Controller * * @since [v1.0] * - * @return View + * @return \Illuminate\Contracts\View\View */ public function getSecurity() { @@ -510,7 +510,7 @@ class SettingsController extends Controller * * @since [v1.0] * - * @return View + * @return \Illuminate\Http\RedirectResponse */ public function postSecurity(Request $request) { @@ -568,7 +568,7 @@ class SettingsController extends Controller * * @since [v1.0] * - * @return View + * @return \Illuminate\Contracts\View\View */ public function getLocalization() { @@ -584,7 +584,7 @@ class SettingsController extends Controller * * @since [v1.0] * - * @return View + * @return \Illuminate\Http\RedirectResponse */ public function postLocalization(Request $request) { @@ -616,7 +616,7 @@ class SettingsController extends Controller * * @since [v1.0] * - * @return View + * @return \Illuminate\Contracts\View\View */ public function getAlerts() { @@ -632,7 +632,7 @@ class SettingsController extends Controller * * @since [v1.0] * - * @return View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse */ public function postAlerts(Request $request) { @@ -689,7 +689,7 @@ class SettingsController extends Controller * * @since [v1.0] * - * @return View + * @return \Illuminate\Contracts\View\View */ public function getSlack() { @@ -705,7 +705,7 @@ class SettingsController extends Controller * * @since [v1.0] * - * @return View + * @return \Illuminate\Contracts\View\View */ public function getAssetTags() { @@ -721,7 +721,7 @@ class SettingsController extends Controller * * @since [v1.0] * - * @return View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse */ public function postAssetTags(Request $request) { @@ -749,7 +749,7 @@ class SettingsController extends Controller * * @since [v1.0] * - * @return View + * @return \Illuminate\Contracts\View\View */ public function getBarcodes() { @@ -766,7 +766,7 @@ class SettingsController extends Controller * * @since [v1.0] * - * @return View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse */ public function postBarcodes(Request $request) { @@ -795,7 +795,7 @@ class SettingsController extends Controller * * @since [v4.0] * - * @return View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse */ public function getPhpInfo() { @@ -814,7 +814,7 @@ class SettingsController extends Controller * * @since [v4.0] * - * @return View + * @return \Illuminate\Contracts\View\View */ public function getLabels() { @@ -830,7 +830,7 @@ class SettingsController extends Controller * * @since [v4.0] * - * @return View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse */ public function postLabels(Request $request) { @@ -907,7 +907,7 @@ class SettingsController extends Controller * * @since [v4.0] * - * @return View + * @return \Illuminate\Contracts\View\View */ public function getLdapSettings() { @@ -942,7 +942,7 @@ class SettingsController extends Controller * * @since [v4.0] * - * @return View + * @return \Illuminate\Http\RedirectResponse */ public function postLdapSettings(Request $request) { @@ -1001,7 +1001,7 @@ class SettingsController extends Controller * * @since v5.0.0 * - * @return View + * @return \Illuminate\Contracts\View\View */ public function getSamlSettings() { @@ -1017,7 +1017,7 @@ class SettingsController extends Controller * * @since v5.0.0 * - * @return View + * @return \Illuminate\Http\RedirectResponse */ public function postSamlSettings(SettingsSamlRequest $request) { @@ -1061,7 +1061,7 @@ class SettingsController extends Controller * * @author [A. Gianotto] [] * @since [v6.1.1] - * @return View + * @return \Illuminate\Contracts\View\View */ public function getGoogleLoginSettings() { @@ -1074,7 +1074,7 @@ class SettingsController extends Controller * * @author [A. Gianotto] [] * @since [v6.1.1] - * @return View + * @return \Illuminate\Http\RedirectResponse */ public function postGoogleLoginSettings(Request $request) { @@ -1104,7 +1104,7 @@ class SettingsController extends Controller * * @since [v1.8] * - * @return View + * @return \Illuminate\Contracts\View\View */ public function getBackups() { @@ -1179,7 +1179,7 @@ class SettingsController extends Controller * * @since [v1.8] * - * @return Storage + * @return \Illuminate\Http\RedirectResponse */ public function downloadFile($filename = null) { @@ -1205,7 +1205,7 @@ class SettingsController extends Controller * * @since [v1.8] * - * @return View + * @return \Illuminate\Http\RedirectResponse */ public function deleteFile($filename = null) { @@ -1231,7 +1231,7 @@ class SettingsController extends Controller } // Hell to the no - Log::warning('User ID '.Auth::user()->id.' is attempting to delete backup file '.$filename.' and is not authorized to.'); + Log::warning('User ID '.auth()->id().' is attempting to delete backup file '.$filename.' and is not authorized to.'); return redirect()->route('settings.backups.index')->with('error', trans('general.backup_delete_not_allowed')); } @@ -1281,7 +1281,7 @@ class SettingsController extends Controller * * @since [v6.0] * - * @return View + * @return \Illuminate\Http\RedirectResponse */ public function postRestore($filename = null) { @@ -1292,7 +1292,7 @@ class SettingsController extends Controller if (Storage::exists($path.'/'.$filename)) { // grab the user's info so we can make sure they exist in the system - $user = User::find(Auth::user()->id); + $user = User::find(auth()->id()); // TODO: run a backup @@ -1352,12 +1352,12 @@ class SettingsController extends Controller * * @since [v4.0] * - * @return View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse */ public function getPurge() { - Log::warning('User '.Auth::user()->username.' (ID'.Auth::user()->id.') is attempting a PURGE'); + Log::warning('User '.auth()->user()->username.' (ID'.auth()->id().') is attempting a PURGE'); if (config('app.allow_purge')=='true') { return view('settings.purge-form'); @@ -1373,11 +1373,11 @@ class SettingsController extends Controller * * @since [v3.0] * - * @return View + * @return \Illuminate\Http\RedirectResponse */ public function postPurge(Request $request) { - Log::warning('User '.Auth::user()->username.' (ID'.Auth::user()->id.') is attempting a PURGE'); + Log::warning('User '.auth()->user()->username.' (ID'.auth()->id().') is attempting a PURGE'); if (config('app.allow_purge')=='true') { Log::debug('Purging is not allowed via the .env'); @@ -1386,7 +1386,7 @@ class SettingsController extends Controller if ($request->input('confirm_purge')=='DELETE') { - Log::warning('User ID ' . Auth::user()->id . ' initiated a PURGE!'); + Log::warning('User ID ' . auth()->id() . ' initiated a PURGE!'); // Run a backup immediately before processing Artisan::call('backup:run'); Artisan::call('snipeit:purge', ['--force' => 'true', '--no-interaction' => true]); @@ -1404,7 +1404,7 @@ class SettingsController extends Controller } } - Log::error('User '.Auth::user()->username.' (ID'.Auth::user()->id.') is attempting to purge deleted data and is not authorized to.'); + Log::error('User '.auth()->user()->username.' (ID'.auth()->id().') is attempting to purge deleted data and is not authorized to.'); // Nope. @@ -1422,7 +1422,7 @@ class SettingsController extends Controller * * @since [v4.0] * - * @return View + * @return \Illuminate\Contracts\View\View */ public function api() { @@ -1436,7 +1436,7 @@ class SettingsController extends Controller * * @since [v3.0] * - * @return \Illuminate\Http\RedirectResponse + * @return \Illuminate\Http\JsonResponse */ public function ajaxTestEmail() { @@ -1446,12 +1446,21 @@ class SettingsController extends Controller 'email' => config('mail.from.address'), ])->notify(new MailTest()); - return response()->json(Helper::formatStandardApiResponse('success', null, 'Maiol sent!')); + return response()->json(Helper::formatStandardApiResponse('success', null, trans('mail_sent.mail_sent'))); } catch (\Exception $e) { return response()->json(Helper::formatStandardApiResponse('success', null, $e->getMessage())); } } + + + /** + * Get login attempts view + * + * @author [A. Gianotto] [] + * + * @return \Illuminate\Contracts\View\View + */ public function getLoginAttempts() { return view('settings.logins'); diff --git a/app/Http/Controllers/StatuslabelsController.php b/app/Http/Controllers/StatuslabelsController.php index 0c559560e0..aba678d47c 100755 --- a/app/Http/Controllers/StatuslabelsController.php +++ b/app/Http/Controllers/StatuslabelsController.php @@ -96,7 +96,7 @@ class StatuslabelsController extends Controller * Statuslabel update. * * @param int $statuslabelId - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse * @throws \Illuminate\Auth\Access\AuthorizationException */ public function edit($statuslabelId = null) diff --git a/app/Http/Controllers/SuppliersController.php b/app/Http/Controllers/SuppliersController.php index b901224714..86b6147bd4 100755 --- a/app/Http/Controllers/SuppliersController.php +++ b/app/Http/Controllers/SuppliersController.php @@ -82,7 +82,7 @@ class SuppliersController extends Controller * Supplier update. * * @param int $supplierId - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse * @throws \Illuminate\Auth\Access\AuthorizationException */ public function edit($supplierId = null) @@ -174,7 +174,7 @@ class SuppliersController extends Controller * Get the asset information to present to the supplier view page * * @param null $supplierId - * @return \Illuminate\Contracts\View\View + * @return \Illuminate\Contracts\View\View | \Illuminate\Http\RedirectResponse * @internal param int $assetId */ public function show($supplierId = null) diff --git a/app/Http/Controllers/Users/BulkUsersController.php b/app/Http/Controllers/Users/BulkUsersController.php index efac5a8d33..b0683e2cbc 100644 --- a/app/Http/Controllers/Users/BulkUsersController.php +++ b/app/Http/Controllers/Users/BulkUsersController.php @@ -102,7 +102,7 @@ class BulkUsersController extends Controller // Remove the user from any updates. $user_raw_array = array_diff($user_raw_array, [Auth::id()]); $manager_conflict = false; - $users = User::whereIn('id', $user_raw_array)->where('id', '!=', Auth::user()->id)->get(); + $users = User::whereIn('id', $user_raw_array)->where('id', '!=', auth()->id())->get(); $return_array = [ 'success' => trans('admin/users/message.success.update_bulk'), @@ -318,7 +318,7 @@ class BulkUsersController extends Controller // Get the users $merge_into_user = User::find($request->input('merge_into_id')); $users_to_merge = User::whereIn('id', $user_ids_to_merge)->with('assets', 'manager', 'userlog', 'licenses', 'consumables', 'accessories', 'managedLocations','uploads', 'acceptances')->get(); - $admin = User::find(Auth::user()->id); + $admin = User::find(auth()->id()); // Walk users foreach ($users_to_merge as $user_to_merge) { diff --git a/app/Http/Controllers/Users/UsersController.php b/app/Http/Controllers/Users/UsersController.php index 0b16dd0a95..7cff29fe59 100755 --- a/app/Http/Controllers/Users/UsersController.php +++ b/app/Http/Controllers/Users/UsersController.php @@ -117,7 +117,7 @@ class UsersController extends Controller $user->zip = $request->input('zip', null); $user->remote = $request->input('remote', 0); $user->website = $request->input('website', null); - $user->created_by = Auth::user()->id; + $user->created_by = auth()->id(); $user->start_date = $request->input('start_date', null); $user->end_date = $request->input('end_date', null); $user->autoassign_licenses = $request->input('autoassign_licenses', 0); @@ -125,7 +125,7 @@ class UsersController extends Controller // Strip out the superuser permission if the user isn't a superadmin $permissions_array = $request->input('permission'); - if (! Auth::user()->isSuperUser()) { + if (! auth()->user()->isSuperUser()) { unset($permissions_array['superuser']); } $user->permissions = json_encode($permissions_array); @@ -176,7 +176,7 @@ class UsersController extends Controller * @author [A. Gianotto] [] * @since [v1.0] * @param $permissions - * @return View + * @return \Illuminate\Contracts\View\View * @internal param int $id * @throws \Illuminate\Auth\Access\AuthorizationException */ @@ -246,7 +246,7 @@ class UsersController extends Controller } // Only save groups if the user is a superuser - if (Auth::user()->isSuperUser()) { + if (auth()->user()->isSuperUser()) { $user->groups()->sync($request->input('groups')); } @@ -300,7 +300,7 @@ class UsersController extends Controller // Strip out the superuser permission if the user isn't a superadmin - if (! Auth::user()->isSuperUser()) { + if (! auth()->user()->isSuperUser()) { unset($permissions_array['superuser']); $permissions_array['superuser'] = $orig_superuser; } @@ -379,7 +379,7 @@ class UsersController extends Controller $logaction->item_type = User::class; $logaction->item_id = $user->id; $logaction->created_at = date('Y-m-d H:i:s'); - $logaction->user_id = Auth::user()->id; + $logaction->user_id = auth()->id(); $logaction->logaction('restore'); // Redirect them to the deleted page if there are more, otherwise the section index diff --git a/app/Http/Controllers/ViewAssetsController.php b/app/Http/Controllers/ViewAssetsController.php index cbff99937d..87a993fa1f 100755 --- a/app/Http/Controllers/ViewAssetsController.php +++ b/app/Http/Controllers/ViewAssetsController.php @@ -36,7 +36,7 @@ class ViewAssetsController extends Controller 'consumables', 'accessories', 'licenses', - )->find(Auth::user()->id); + )->find(auth()->id()); $field_array = array(); @@ -92,7 +92,7 @@ class ViewAssetsController extends Controller } $item = call_user_func([$fullItemType, 'find'], $itemId); - $user = Auth::user(); + $user = auth()->user(); $logaction = new Actionlog(); $logaction->item_id = $data['asset_id'] = $item->id; @@ -102,14 +102,15 @@ class ViewAssetsController extends Controller if ($user->location_id) { $logaction->location_id = $user->location_id; } - $logaction->target_id = $data['user_id'] = Auth::user()->id; + + $logaction->target_id = $data['user_id'] = auth()->id(); $logaction->target_type = User::class; $data['item_quantity'] = $request->has('request-quantity') ? e($request->input('request-quantity')) : 1; $data['requested_by'] = $user->present()->fullName(); $data['item'] = $item; $data['item_type'] = $itemType; - $data['target'] = Auth::user(); + $data['target'] = auth()->user(); if ($fullItemType == Asset::class) { $data['item_url'] = route('hardware.show', $item->id); @@ -147,7 +148,7 @@ class ViewAssetsController extends Controller */ public function getRequestAsset($assetId = null) { - $user = Auth::user(); + $user = auth()->user(); // Check if the asset exists and is requestable if (is_null($asset = Asset::RequestableAssets()->find($assetId))) { @@ -160,7 +161,7 @@ class ViewAssetsController extends Controller } $data['item'] = $asset; - $data['target'] = Auth::user(); + $data['target'] = auth()->user(); $data['item_quantity'] = 1; $settings = Setting::getSettings(); @@ -172,11 +173,11 @@ class ViewAssetsController extends Controller if ($user->location_id) { $logaction->location_id = $user->location_id; } - $logaction->target_id = $data['user_id'] = Auth::user()->id; + $logaction->target_id = $data['user_id'] = auth()->id(); $logaction->target_type = User::class; // If it's already requested, cancel the request. - if ($asset->isRequestedBy(Auth::user())) { + if ($asset->isRequestedBy(auth()->user())) { $asset->cancelRequest(); $asset->decrement('requests_counter', 1); diff --git a/app/Http/Middleware/CheckForDebug.php b/app/Http/Middleware/CheckForDebug.php index 85311cf539..3bf919f1f2 100644 --- a/app/Http/Middleware/CheckForDebug.php +++ b/app/Http/Middleware/CheckForDebug.php @@ -18,7 +18,7 @@ class CheckForDebug { view()->share('debug_in_production', false); - if (((Auth::check() && (Auth::user()->isSuperUser()))) && (app()->environment() == 'production') && (config('app.warn_debug') === true) && (config('app.debug') === true)) { + if (((Auth::check() && (auth()->user()->isSuperUser()))) && (app()->environment() == 'production') && (config('app.warn_debug') === true) && (config('app.debug') === true)) { view()->share('debug_in_production', true); } diff --git a/app/Http/Middleware/CheckForTwoFactor.php b/app/Http/Middleware/CheckForTwoFactor.php index 7846d00ade..b94423d205 100644 --- a/app/Http/Middleware/CheckForTwoFactor.php +++ b/app/Http/Middleware/CheckForTwoFactor.php @@ -38,17 +38,17 @@ class CheckForTwoFactor if ($settings = Setting::getSettings()) { if (Auth::check() && ($settings->two_factor_enabled != '')) { // This user is already 2fa-authed - if ($request->session()->get('2fa_authed')==Auth::user()->id) { + if ($request->session()->get('2fa_authed')==auth()->id()) { return $next($request); } // Two-factor is optional and the user has NOT opted in, let them through - if (($settings->two_factor_enabled == '1') && (Auth::user()->two_factor_optin != '1')) { + if (($settings->two_factor_enabled == '1') && (auth()->user()->two_factor_optin != '1')) { return $next($request); } // Otherwise make sure they're enrolled and show them the 2FA code screen - if ((Auth::user()->two_factor_secret != '') && (Auth::user()->two_factor_enrolled == '1')) { + if ((auth()->user()->two_factor_secret != '') && (auth()->user()->two_factor_enrolled == '1')) { return redirect()->route('two-factor')->with('info', trans('auth/message.two_factor.enter_two_factor_code')); } diff --git a/app/Http/Requests/DeleteUserRequest.php b/app/Http/Requests/DeleteUserRequest.php index 282919d7ae..99574950d8 100644 --- a/app/Http/Requests/DeleteUserRequest.php +++ b/app/Http/Requests/DeleteUserRequest.php @@ -29,7 +29,7 @@ class DeleteUserRequest extends FormRequest if ($user_to_delete) { $this->merge([ 'user' => request()->route('user'), - 'admin_id' => Auth::user()->id, + 'admin_id' => auth()->id(), 'managed_users' => $user_to_delete->managesUsers()->count(), 'managed_locations' => $user_to_delete->managedLocations()->count(), 'assigned_assets' => $user_to_delete->assets()->count(), @@ -48,7 +48,7 @@ class DeleteUserRequest extends FormRequest public function rules(): array { return [ - 'user' => Rule::notIn([auth()->user()->id]), + 'user' => Rule::notIn([auth()->id()]), 'managed_users' => Rule::in([0]), 'managed_locations' => Rule::in([0]), 'assigned_assets' => Rule::in([0]), diff --git a/app/Http/Transformers/AssetsTransformer.php b/app/Http/Transformers/AssetsTransformer.php index eeb10eb0d2..d3a19929e1 100644 --- a/app/Http/Transformers/AssetsTransformer.php +++ b/app/Http/Transformers/AssetsTransformer.php @@ -231,7 +231,7 @@ class AssetsTransformer 'expected_checkin' => Helper::getFormattedDateObject($asset->expected_checkin, 'date'), 'location' => ($asset->location) ? e($asset->location->name) : null, 'status'=> ($asset->assetstatus) ? $asset->present()->statusMeta : null, - 'assigned_to_self' => ($asset->assigned_to == \Auth::user()->id), + 'assigned_to_self' => ($asset->assigned_to == auth()->id()), ]; if (($asset->model) && ($asset->model->fieldset) && ($asset->model->fieldset->fields->count() > 0)) { @@ -258,8 +258,8 @@ class AssetsTransformer $permissions_array['available_actions'] = [ - 'cancel' => ($asset->isRequestedBy(\Auth::user())) ? true : false, - 'request' => ($asset->isRequestedBy(\Auth::user())) ? false : true, + 'cancel' => ($asset->isRequestedBy(auth()->user())) ? true : false, + 'request' => ($asset->isRequestedBy(auth()->user())) ? false : true, ]; $array += $permissions_array; diff --git a/app/Importer/AssetImporter.php b/app/Importer/AssetImporter.php index 02ffa2077c..c32a9fb4c6 100644 --- a/app/Importer/AssetImporter.php +++ b/app/Importer/AssetImporter.php @@ -184,7 +184,7 @@ class AssetImporter extends ItemImporter if (isset($target) && ($target !== false)) { if (!is_null($asset->assigned_to)){ if ($asset->assigned_to != $target->id) { - event(new CheckoutableCheckedIn($asset, User::find($asset->assigned_to), Auth::user(), 'Checkin from CSV Importer', $checkin_date)); + event(new CheckoutableCheckedIn($asset, User::find($asset->assigned_to), auth()->user(), 'Checkin from CSV Importer', $checkin_date)); } } diff --git a/app/Importer/LocationImporter.php b/app/Importer/LocationImporter.php index 3b1b65b08f..e344b6beaf 100644 --- a/app/Importer/LocationImporter.php +++ b/app/Importer/LocationImporter.php @@ -65,7 +65,7 @@ class LocationImporter extends ItemImporter $this->item['ldap_ou'] = trim($this->findCsvMatch($row, 'ldap_ou')); $this->item['manager'] = trim($this->findCsvMatch($row, 'manager')); $this->item['manager_username'] = trim($this->findCsvMatch($row, 'manager_username')); - $this->item['user_id'] = \Auth::user()->id; + $this->item['user_id'] = auth()->id(); if ($this->findCsvMatch($row, 'parent_location')) { $this->item['parent_id'] = $this->createOrFetchLocation(trim($this->findCsvMatch($row, 'parent_location'))); diff --git a/app/Listeners/CheckoutableListener.php b/app/Listeners/CheckoutableListener.php index 4bc367f025..63e552233c 100644 --- a/app/Listeners/CheckoutableListener.php +++ b/app/Listeners/CheckoutableListener.php @@ -69,9 +69,9 @@ class CheckoutableListener } } } catch (ClientException $e) { - Log::warning("Exception caught during checkout notification: " . $e->getMessage()); + Log::debug("Exception caught during checkout notification: " . $e->getMessage()); } catch (Exception $e) { - Log::warning("Exception caught during checkout notification: " . $e->getMessage()); + Log::debug("Exception caught during checkout notification: " . $e->getMessage()); } } diff --git a/app/Livewire/OauthClients.php b/app/Livewire/OauthClients.php index 02fc77848b..fda91260c8 100644 --- a/app/Livewire/OauthClients.php +++ b/app/Livewire/OauthClients.php @@ -22,8 +22,8 @@ class OauthClients extends Component public function render() { return view('livewire.oauth-clients', [ - 'clients' => app(ClientRepository::class)->activeForUser(auth()->user()->id), - 'authorized_tokens' => app(TokenRepository::class)->forUser(auth()->user()->id)->where('revoked', false), + 'clients' => app(ClientRepository::class)->activeForUser(auth()->id()), + 'authorized_tokens' => app(TokenRepository::class)->forUser(auth()->id())->where('revoked', false), ]); } @@ -35,7 +35,7 @@ class OauthClients extends Component ]); app(ClientRepository::class)->create( - auth()->user()->id, + auth()->id(), $this->name, $this->redirect, ); @@ -47,10 +47,10 @@ class OauthClients extends Component { // test for safety // ->delete must be of type Client - thus the model binding - if ($clientId->user_id == auth()->user()->id) { + if ($clientId->user_id == auth()->id()) { app(ClientRepository::class)->delete($clientId); } else { - Log::warning('User ' . auth()->user()->id . ' attempted to delete client ' . $clientId->id . ' which belongs to user ' . $clientId->user_id); + Log::warning('User ' . auth()->id() . ' attempted to delete client ' . $clientId->id . ' which belongs to user ' . $clientId->user_id); $this->authorizationError = 'You are not authorized to delete this client.'; } } @@ -58,10 +58,10 @@ class OauthClients extends Component public function deleteToken($tokenId): void { $token = app(TokenRepository::class)->find($tokenId); - if ($token->user_id == auth()->user()->id) { + if ($token->user_id == auth()->id()) { app(TokenRepository::class)->revokeAccessToken($tokenId); } else { - Log::warning('User ' . auth()->user()->id . ' attempted to delete token ' . $tokenId . ' which belongs to user ' . $token->user_id); + Log::warning('User ' . auth()->id() . ' attempted to delete token ' . $tokenId . ' which belongs to user ' . $token->user_id); $this->authorizationError = 'You are not authorized to delete this token.'; } } @@ -84,12 +84,12 @@ class OauthClients extends Component ]); $client = app(ClientRepository::class)->find($editClientId->id); - if ($client->user_id == auth()->user()->id) { + if ($client->user_id == auth()->id()) { $client->name = $this->editName; $client->redirect = $this->editRedirect; $client->save(); } else { - Log::warning('User ' . auth()->user()->id . ' attempted to edit client ' . $editClientId->id . ' which belongs to user ' . $client->user_id); + Log::warning('User ' . auth()->id() . ' attempted to edit client ' . $editClientId->id . ' which belongs to user ' . $client->user_id); $this->authorizationError = 'You are not authorized to edit this client.'; } diff --git a/app/Livewire/PersonalAccessTokens.php b/app/Livewire/PersonalAccessTokens.php index 69bf1d28a1..79543a609e 100644 --- a/app/Livewire/PersonalAccessTokens.php +++ b/app/Livewire/PersonalAccessTokens.php @@ -23,7 +23,7 @@ class PersonalAccessTokens extends Component public function render() { return view('livewire.personal-access-tokens', [ - 'tokens' => Auth::user()->tokens, + 'tokens' => auth()->user()->tokens, ]); } @@ -38,7 +38,7 @@ class PersonalAccessTokens extends Component { $this->validate(); - $newToken = Auth::user()->createToken($this->name); + $newToken = auth()->user()->createToken($this->name); $this->newTokenString = $newToken->accessToken; @@ -49,6 +49,6 @@ class PersonalAccessTokens extends Component { //this needs safety (though the scope of auth::user might kind of do it...) //seems like it does, test more - Auth::user()->tokens()->find($tokenId)?->delete(); + auth()->user()->tokens()->find($tokenId)?->delete(); } } diff --git a/app/Models/Actionlog.php b/app/Models/Actionlog.php index 90e0e884f8..33e9707f2a 100755 --- a/app/Models/Actionlog.php +++ b/app/Models/Actionlog.php @@ -4,7 +4,7 @@ namespace App\Models; use App\Models\Traits\Searchable; use App\Presenters\Presentable; -use Carbon; +use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Facades\Auth; @@ -81,14 +81,14 @@ class Actionlog extends SnipeModel parent::boot(); static::creating(function (self $actionlog) { // If the admin is a superadmin, let's see if the target instead has a company. - if (Auth::user() && Auth::user()->isSuperUser()) { + if (auth()->user() && auth()->user()->isSuperUser()) { if ($actionlog->target) { $actionlog->company_id = $actionlog->target->company_id; } elseif ($actionlog->item) { $actionlog->company_id = $actionlog->item->company_id; } - } elseif (Auth::user() && Auth::user()->company) { - $actionlog->company_id = Auth::user()->company_id; + } elseif (auth()->user() && auth()->user()->company) { + $actionlog->company_id = auth()->user()->company_id; } }); } diff --git a/app/Models/Asset.php b/app/Models/Asset.php index a3d603551f..5f5e0cd603 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -369,7 +369,7 @@ class Asset extends Depreciable } elseif (get_class($admin) === \App\Models\User::class) { $checkedOutBy = $admin; } else { - $checkedOutBy = Auth::user(); + $checkedOutBy = auth()->user(); } event(new CheckoutableCheckedOut($this, $target, $checkedOutBy, $note, $originalValues)); diff --git a/app/Models/Company.php b/app/Models/Company.php index ea8a28b7e1..657b34390b 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -106,7 +106,7 @@ final class Company extends SnipeModel if (! static::isFullMultipleCompanySupportEnabled()) { return static::getIdFromInput($unescaped_input); } else { - $current_user = Auth::user(); + $current_user = auth()->user(); // Super users should be able to set a company to whatever they need if ($current_user->isSuperUser()) { @@ -157,24 +157,24 @@ final class Company extends SnipeModel } - if (Auth::user()) { + if (auth()->user()) { Log::warning('Companyable is '.$companyable); - $current_user_company_id = Auth::user()->company_id; + $current_user_company_id = auth()->user()->company_id; $companyable_company_id = $companyable->company_id; - return $current_user_company_id == null || $current_user_company_id == $companyable_company_id || Auth::user()->isSuperUser(); + return $current_user_company_id == null || $current_user_company_id == $companyable_company_id || auth()->user()->isSuperUser(); } } public static function isCurrentUserAuthorized() { - return (! static::isFullMultipleCompanySupportEnabled()) || (Auth::user()->isSuperUser()); + return (! static::isFullMultipleCompanySupportEnabled()) || (auth()->user()->isSuperUser()); } public static function canManageUsersCompanies() { - return ! static::isFullMultipleCompanySupportEnabled() || Auth::user()->isSuperUser() || - Auth::user()->company_id == null; + return ! static::isFullMultipleCompanySupportEnabled() || auth()->user()->isSuperUser() || + auth()->user()->company_id == null; } /** @@ -200,7 +200,7 @@ final class Company extends SnipeModel */ public static function getIdForUser($unescaped_input) { - if (! static::isFullMultipleCompanySupportEnabled() || Auth::user()->isSuperUser()) { + if (! static::isFullMultipleCompanySupportEnabled() || auth()->user()->isSuperUser()) { return static::getIdFromInput($unescaped_input); } else { return static::getIdForCurrentUser($unescaped_input); @@ -259,7 +259,7 @@ final class Company extends SnipeModel public static function scopeCompanyables($query, $column = 'company_id', $table_name = null) { // If not logged in and hitting this, assume we are on the command line and don't scope?' - if (! static::isFullMultipleCompanySupportEnabled() || (Auth::hasUser() && Auth::user()->isSuperUser()) || (! Auth::hasUser())) { + if (! static::isFullMultipleCompanySupportEnabled() || (Auth::hasUser() && auth()->user()->isSuperUser()) || (! Auth::hasUser())) { return $query; } else { return static::scopeCompanyablesDirectly($query, $column, $table_name); @@ -277,7 +277,7 @@ final class Company extends SnipeModel // Get the company ID of the logged-in user, or set it to null if there is no company associated with the user if (Auth::hasUser()) { - $company_id = Auth::user()->company_id; + $company_id = auth()->user()->company_id; } else { $company_id = null; } @@ -309,7 +309,7 @@ final class Company extends SnipeModel if (count($companyable_names) == 0) { throw new Exception('No Companyable Children to scope'); - } elseif (! static::isFullMultipleCompanySupportEnabled() || (Auth::hasUser() && Auth::user()->isSuperUser())) { + } elseif (! static::isFullMultipleCompanySupportEnabled() || (Auth::hasUser() && auth()->user()->isSuperUser())) { return $query; } else { $f = function ($q) { diff --git a/app/Models/Loggable.php b/app/Models/Loggable.php index f855b41253..ae5d554882 100644 --- a/app/Models/Loggable.php +++ b/app/Models/Loggable.php @@ -36,8 +36,8 @@ trait Loggable { $log = new Actionlog; $log = $this->determineLogItemType($log); - if (Auth::user()) { - $log->user_id = Auth::user()->id; + if (auth()->user()) { + $log->user_id = auth()->id(); } if (! isset($target)) { @@ -148,8 +148,8 @@ trait Loggable $log->action_date = date('Y-m-d H:i:s'); } - if (Auth::user()) { - $log->user_id = Auth::user()->id; + if (auth()->user()) { + $log->user_id = auth()->id(); } $changed = []; @@ -225,7 +225,7 @@ trait Loggable } $log->location_id = ($location_id) ? $location_id : null; $log->note = $note; - $log->user_id = Auth::user()->id; + $log->user_id = auth()->id(); $log->filename = $filename; $log->logaction('audit'); @@ -249,8 +249,8 @@ trait Loggable public function logCreate($note = null) { $user_id = -1; - if (Auth::user()) { - $user_id = Auth::user()->id; + if (auth()->user()) { + $user_id = auth()->id(); } $log = new Actionlog; if (static::class == LicenseSeat::class) { @@ -284,7 +284,7 @@ trait Loggable $log->item_type = static::class; $log->item_id = $this->id; } - $log->user_id = Auth::user()->id; + $log->user_id = auth()->id(); $log->note = $note; $log->target_id = null; $log->created_at = date('Y-m-d H:i:s'); diff --git a/app/Services/PredefinedKitCheckoutService.php b/app/Services/PredefinedKitCheckoutService.php index 7ef28c9ee0..d683875395 100644 --- a/app/Services/PredefinedKitCheckoutService.php +++ b/app/Services/PredefinedKitCheckoutService.php @@ -54,7 +54,7 @@ class PredefinedKitCheckoutService $expected_checkin = $request->get('expected_checkin'); } - $admin = Auth::user(); + $admin = auth()->user(); $note = e($request->get('note')); diff --git a/database/factories/CategoryFactory.php b/database/factories/CategoryFactory.php index fe6bc255b7..2a89c12892 100644 --- a/database/factories/CategoryFactory.php +++ b/database/factories/CategoryFactory.php @@ -178,4 +178,32 @@ class CategoryFactory extends Factory 'category_type' => 'accessory', ]); } + + public function forAssets() + { + return $this->state([ + 'category_type' => 'asset', + ]); + } + + public function forLicenses() + { + return $this->state([ + 'category_type' => 'license', + ]); + } + + public function forComponents() + { + return $this->state([ + 'category_type' => 'component', + ]); + } + + public function forConsumables() + { + return $this->state([ + 'category_type' => 'consumable', + ]); + } } diff --git a/resources/lang/en-US/mail.php b/resources/lang/en-US/mail.php index 759ff0f5e8..56b2c91f11 100644 --- a/resources/lang/en-US/mail.php +++ b/resources/lang/en-US/mail.php @@ -90,4 +90,5 @@ return [ 'welcome_to' => 'Welcome to :web!', 'your_assets' => 'View Your Assets', 'your_credentials' => 'Your Snipe-IT credentials', + 'mail_sent' => 'Mail sent successfully!', ]; diff --git a/resources/views/partials/forms/edit/company-select.blade.php b/resources/views/partials/forms/edit/company-select.blade.php index f4da23421c..59a4748da1 100644 --- a/resources/views/partials/forms/edit/company-select.blade.php +++ b/resources/views/partials/forms/edit/company-select.blade.php @@ -33,7 +33,6 @@ {!! $errors->first($fieldname, '
:message
') !!} - {!! $errors->first($fieldname, '
') !!} @endif