diff --git a/_ide_helper_actions.php b/_ide_helper_actions.php new file mode 100644 index 0000000000..a420493954 --- /dev/null +++ b/_ide_helper_actions.php @@ -0,0 +1,44 @@ +user(); + + // Check if the asset exists and is requestable + if (is_null($asset = Asset::RequestableAssets()->find($assetId))) { + return redirect()->route('requestable-assets') + ->with('error', trans('admin/hardware/message.does_not_exist_or_not_requestable')); + } + if (!Company::isCurrentUserHasAccess($asset)) { + return redirect()->route('requestable-assets') + ->with('error', trans('general.insufficient_permissions')); + } + + $data['item'] = $asset; + $data['target'] = auth()->user(); + $data['item_quantity'] = 1; + $settings = Setting::getSettings(); + + $logaction = new Actionlog(); + $logaction->item_id = $data['asset_id'] = $asset->id; + $logaction->item_type = $data['item_type'] = Asset::class; + $logaction->created_at = $data['requested_date'] = date('Y-m-d H:i:s'); + + if ($user->location_id) { + $logaction->location_id = $user->location_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())) { + $asset->cancelRequest(); + $asset->decrement('requests_counter', 1); + + $logaction->logaction('request canceled'); + try { + $settings->notify(new RequestAssetCancelation($data)); + } catch (\Exception $e) { + Log::warning($e); + } + return redirect()->route('requestable-assets') + ->with('success')->with('success', trans('admin/hardware/message.requests.canceled')); + } + + $logaction->logaction('requested'); + $asset->request(); + $asset->increment('requests_counter', 1); + try { + $settings->notify(new RequestAssetNotification($data)); + } catch (\Exception $e) { + Log::warning($e); + } + + return redirect()->route('requestable-assets')->with('success')->with('success', trans('admin/hardware/message.requests.success')); + } +} diff --git a/app/Http/Controllers/ViewAssetsController.php b/app/Http/Controllers/ViewAssetsController.php index 12c300e5bd..d9c1f0facf 100755 --- a/app/Http/Controllers/ViewAssetsController.php +++ b/app/Http/Controllers/ViewAssetsController.php @@ -2,10 +2,10 @@ namespace App\Http\Controllers; +use App\Actions\CheckoutRequests\CreateCheckoutRequest; use App\Models\Actionlog; use App\Models\Asset; use App\Models\AssetModel; -use App\Models\Company; use App\Models\Setting; use App\Models\User; use App\Notifications\RequestAssetCancelation; @@ -13,7 +13,6 @@ use App\Notifications\RequestAssetNotification; use Illuminate\Http\Request; use Illuminate\Http\RedirectResponse; use \Illuminate\Contracts\View\View; -use Log; /** * This controller handles all actions related to the ability for users @@ -144,61 +143,9 @@ class ViewAssetsController extends Controller * Process a specific requested asset * @param null $assetId */ - public function getRequestAsset($assetId = null) : RedirectResponse + public function getRequestAsset($assetId = null): void { - $user = auth()->user(); - - // Check if the asset exists and is requestable - if (is_null($asset = Asset::RequestableAssets()->find($assetId))) { - return redirect()->route('requestable-assets') - ->with('error', trans('admin/hardware/message.does_not_exist_or_not_requestable')); - } - if (! Company::isCurrentUserHasAccess($asset)) { - return redirect()->route('requestable-assets') - ->with('error', trans('general.insufficient_permissions')); - } - - $data['item'] = $asset; - $data['target'] = auth()->user(); - $data['item_quantity'] = 1; - $settings = Setting::getSettings(); - - $logaction = new Actionlog(); - $logaction->item_id = $data['asset_id'] = $asset->id; - $logaction->item_type = $data['item_type'] = Asset::class; - $logaction->created_at = $data['requested_date'] = date('Y-m-d H:i:s'); - - if ($user->location_id) { - $logaction->location_id = $user->location_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())) { - $asset->cancelRequest(); - $asset->decrement('requests_counter', 1); - - $logaction->logaction('request canceled'); - try { - $settings->notify(new RequestAssetCancelation($data)); - } catch (\Exception $e) { - Log::warning($e); - } - return redirect()->route('requestable-assets') - ->with('success')->with('success', trans('admin/hardware/message.requests.canceled')); - } - - $logaction->logaction('requested'); - $asset->request(); - $asset->increment('requests_counter', 1); - try { - $settings->notify(new RequestAssetNotification($data)); - } catch (\Exception $e) { - Log::warning($e); - } - - return redirect()->route('requestable-assets')->with('success')->with('success', trans('admin/hardware/message.requests.success')); + CreateCheckoutRequest::run($assetId); } public function getRequestedAssets() : View diff --git a/composer.json b/composer.json index 6d89312578..c96b11e1bc 100644 --- a/composer.json +++ b/composer.json @@ -50,6 +50,7 @@ "league/csv": "^9.7", "league/flysystem-aws-s3-v3": "^3.0", "livewire/livewire": "^3.5", + "lorisleiva/laravel-actions": "^2.8", "neitanod/forceutf8": "^2.0", "nesbot/carbon": "^2.32", "nunomaduro/collision": "^7.0", @@ -84,7 +85,8 @@ "squizlabs/php_codesniffer": "^3.5", "symfony/css-selector": "^4.4", "symfony/dom-crawler": "^4.4", - "vimeo/psalm": "^5.13" + "vimeo/psalm": "^5.13", + "wulfheart/laravel-actions-ide-helper": "^0.8.0" }, "extra": { "laravel": { diff --git a/composer.lock b/composer.lock index 3f79921b26..09504209f0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3819ab4ef72eb77fabe494c0e746b83b", + "content-hash": "9bbdc0f3c60b21a77208b4c65c2f5bdb", "packages": [ { "name": "alek13/slack", @@ -4535,6 +4535,154 @@ ], "time": "2024-10-01T12:40:06+00:00" }, + { + "name": "lorisleiva/laravel-actions", + "version": "v2.8.4", + "source": { + "type": "git", + "url": "https://github.com/lorisleiva/laravel-actions.git", + "reference": "5a168bfdd3b75dd6ff259019d4aeef784bbd5403" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/lorisleiva/laravel-actions/zipball/5a168bfdd3b75dd6ff259019d4aeef784bbd5403", + "reference": "5a168bfdd3b75dd6ff259019d4aeef784bbd5403", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^10.0|^11.0", + "lorisleiva/lody": "^0.5", + "php": "^8.1" + }, + "require-dev": { + "orchestra/testbench": "^8.0|^9.0", + "pestphp/pest": "^1.23|^2.34", + "phpunit/phpunit": "^9.6|^10.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Lorisleiva\\Actions\\ActionServiceProvider" + ], + "aliases": { + "Action": "Lorisleiva\\Actions\\Facades\\Actions" + } + } + }, + "autoload": { + "psr-4": { + "Lorisleiva\\Actions\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Loris Leiva", + "email": "loris.leiva@gmail.com", + "homepage": "https://lorisleiva.com", + "role": "Developer" + } + ], + "description": "Laravel components that take care of one specific task", + "homepage": "https://github.com/lorisleiva/laravel-actions", + "keywords": [ + "action", + "command", + "component", + "controller", + "job", + "laravel", + "listener", + "object" + ], + "support": { + "issues": "https://github.com/lorisleiva/laravel-actions/issues", + "source": "https://github.com/lorisleiva/laravel-actions/tree/v2.8.4" + }, + "funding": [ + { + "url": "https://github.com/sponsors/lorisleiva", + "type": "github" + } + ], + "time": "2024-09-10T09:57:29+00:00" + }, + { + "name": "lorisleiva/lody", + "version": "v0.5.0", + "source": { + "type": "git", + "url": "https://github.com/lorisleiva/lody.git", + "reference": "c2f51b070e99f3a240d66cf68ef1f232036917fe" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/lorisleiva/lody/zipball/c2f51b070e99f3a240d66cf68ef1f232036917fe", + "reference": "c2f51b070e99f3a240d66cf68ef1f232036917fe", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^9.0|^10.0|^11.0", + "php": "^8.0" + }, + "require-dev": { + "orchestra/testbench": "^9.0", + "pestphp/pest": "^1.20|^2.34", + "phpunit/phpunit": "^9.5.10|^10.5" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Lorisleiva\\Lody\\LodyServiceProvider" + ], + "aliases": { + "Lody": "Lorisleiva\\Lody\\Lody" + } + } + }, + "autoload": { + "psr-4": { + "Lorisleiva\\Lody\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Loris Leiva", + "email": "loris.leiva@gmail.com", + "homepage": "https://lorisleiva.com", + "role": "Developer" + } + ], + "description": "Load files and classes as lazy collections in Laravel.", + "homepage": "https://github.com/lorisleiva/lody", + "keywords": [ + "classes", + "collection", + "files", + "laravel", + "load" + ], + "support": { + "issues": "https://github.com/lorisleiva/lody/issues", + "source": "https://github.com/lorisleiva/lody/tree/v0.5.0" + }, + "funding": [ + { + "url": "https://github.com/sponsors/lorisleiva", + "type": "github" + } + ], + "time": "2024-03-13T12:08:59+00:00" + }, { "name": "masterminds/html5", "version": "2.9.0", @@ -13775,6 +13923,73 @@ }, "time": "2024-03-27T12:14:49+00:00" }, + { + "name": "phpdocumentor/reflection", + "version": "6.0.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/Reflection.git", + "reference": "61e2f1fe7683e9647b9ed8d9e53d08699385267d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/Reflection/zipball/61e2f1fe7683e9647b9ed8d9e53d08699385267d", + "reference": "61e2f1fe7683e9647b9ed8d9e53d08699385267d", + "shasum": "" + }, + "require": { + "nikic/php-parser": "~4.18 || ^5.0", + "php": "8.1.*|8.2.*|8.3.*", + "phpdocumentor/reflection-common": "^2.1", + "phpdocumentor/reflection-docblock": "^5", + "phpdocumentor/type-resolver": "^1.2", + "symfony/polyfill-php80": "^1.28", + "webmozart/assert": "^1.7" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "doctrine/coding-standard": "^12.0", + "mikey179/vfsstream": "~1.2", + "mockery/mockery": "~1.6.0", + "phpspec/prophecy-phpunit": "^2.0", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan": "^1.8", + "phpstan/phpstan-webmozart-assert": "^1.2", + "phpunit/phpunit": "^10.0", + "psalm/phar": "^5.24", + "rector/rector": "^1.0.0", + "squizlabs/php_codesniffer": "^3.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-5.x": "5.3.x-dev", + "dev-6.x": "6.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\": "src/phpDocumentor" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Reflection library to do Static Analysis for PHP Projects", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "support": { + "issues": "https://github.com/phpDocumentor/Reflection/issues", + "source": "https://github.com/phpDocumentor/Reflection/tree/6.0.0" + }, + "time": "2024-05-23T19:28:12+00:00" + }, { "name": "phpmyadmin/sql-parser", "version": "5.10.0", @@ -14872,6 +15087,60 @@ ], "time": "2024-06-11T12:45:25+00:00" }, + { + "name": "riimu/kit-pathjoin", + "version": "v1.2.0", + "source": { + "type": "git", + "url": "https://github.com/Riimu/Kit-PathJoin.git", + "reference": "8ad2656c79527dba9f7f20e1229dcd38abfe8cee" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Riimu/Kit-PathJoin/zipball/8ad2656c79527dba9f7f20e1229dcd38abfe8cee", + "reference": "8ad2656c79527dba9f7f20e1229dcd38abfe8cee", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.3", + "phpunit/phpunit": "^5.7 || ^6.2", + "squizlabs/php_codesniffer": "^3.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Riimu\\Kit\\PathJoin\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Riikka Kalliomäki", + "email": "riikka.kalliomaki@gmail.com", + "homepage": "http://riimu.net" + } + ], + "description": "Cross-platform library for normalizing and joining file system paths", + "homepage": "http://kit.riimu.net", + "keywords": [ + "file", + "join", + "normalize", + "path", + "system" + ], + "support": { + "issues": "https://github.com/Riimu/Kit-PathJoin/issues", + "source": "https://github.com/Riimu/Kit-PathJoin/tree/master" + }, + "time": "2017-07-09T14:41:04+00:00" + }, { "name": "sebastian/cli-parser", "version": "2.0.1", @@ -16640,6 +16909,81 @@ "source": "https://github.com/vimeo/psalm" }, "time": "2024-09-08T18:53:08+00:00" + }, + { + "name": "wulfheart/laravel-actions-ide-helper", + "version": "v0.8.0", + "source": { + "type": "git", + "url": "https://github.com/Wulfheart/laravel-actions-ide-helper.git", + "reference": "48e9d7c89804fcd459a73cc22adee533e7a88deb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Wulfheart/laravel-actions-ide-helper/zipball/48e9d7c89804fcd459a73cc22adee533e7a88deb", + "reference": "48e9d7c89804fcd459a73cc22adee533e7a88deb", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^10.0|^11.0", + "lorisleiva/laravel-actions": "^2.3", + "lorisleiva/lody": "^0.5.0", + "php": "^8.1|^8.2", + "phpdocumentor/reflection": "^5.1|^6.0", + "riimu/kit-pathjoin": "^1.2", + "spatie/laravel-package-tools": "^1.14" + }, + "require-dev": { + "brianium/paratest": "^6.8|^7.4", + "nunomaduro/collision": "^6.1|^8.0", + "orchestra/testbench": "^8.0|^9.0", + "pestphp/pest": "^1.22|^2.34", + "phpunit/phpunit": "^9.5.10|^10.5", + "spatie/invade": "^1.1|^2.0", + "spatie/laravel-ray": "^1.32", + "spatie/pest-plugin-snapshots": "^1.1|^2.1", + "vimeo/psalm": "^5.6" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Wulfheart\\LaravelActionsIdeHelper\\LaravelActionsIdeHelperServiceProvider" + ], + "aliases": { + "LaravelActionsIdeHelper": "Wulfheart\\LaravelActionsIdeHelper\\LaravelActionsIdeHelperFacade" + } + } + }, + "autoload": { + "psr-4": { + "Wulfheart\\LaravelActionsIdeHelper\\": "src", + "Wulfheart\\LaravelActionsIdeHelper\\Database\\Factories\\": "database/factories" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Alexander Wulf", + "email": "dev@alexfwulf.de", + "role": "Developer" + } + ], + "description": "Generate a new IDE Helper file for Laravel Actions.", + "homepage": "https://github.com/wulfheart/laravel-actions-ide-helper", + "keywords": [ + "laravel", + "laravel-actions-ide-helper", + "wulfheart" + ], + "support": { + "issues": "https://github.com/Wulfheart/laravel-actions-ide-helper/issues", + "source": "https://github.com/Wulfheart/laravel-actions-ide-helper/tree/v0.8.0" + }, + "time": "2024-08-30T14:32:22+00:00" } ], "aliases": [],