Skip to content

A free open source IT asset/license management system

more work

spencerrlongga524c0b418de
diff --git a/_ide_helper_actions.php b/_ide_helper_actions.php
deleted file mode 100644
index a420493954..0000000000
--- a/_ide_helper_actions.php
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-
-namespace App\Actions\CheckoutRequests;
-
-/**
- * @method static \Lorisleiva\Actions\Decorators\JobDecorator|\Lorisleiva\Actions\Decorators\UniqueJobDecorator makeJob(mixed $assetId)
- * @method static \Lorisleiva\Actions\Decorators\UniqueJobDecorator makeUniqueJob(mixed $assetId)
- * @method static \Illuminate\Foundation\Bus\PendingDispatch dispatch(mixed $assetId)
- * @method static \Illuminate\Foundation\Bus\PendingDispatch|\Illuminate\Support\Fluent dispatchIf(bool $boolean, mixed $assetId)
- * @method static \Illuminate\Foundation\Bus\PendingDispatch|\Illuminate\Support\Fluent dispatchUnless(bool $boolean, mixed $assetId)
- * @method static dispatchSync(mixed $assetId)
- * @method static dispatchNow(mixed $assetId)
- * @method static dispatchAfterResponse(mixed $assetId)
- * @method static mixed run(mixed $assetId)
- */
-class CreateCheckoutRequest
-{
-}
-namespace Lorisleiva\Actions\Concerns;
-
-/**
- * @method void asController()
- */
-trait AsController
-{
-}
-/**
- * @method void asListener()
- */
-trait AsListener
-{
-}
-/**
- * @method void asJob()
- */
-trait AsJob
-{
-}
-/**
- * @method void asCommand(\Illuminate\Console\Command $command)
- */
-trait AsCommand
-{
-}
\ No newline at end of file
diff --git a/app/Actions/CheckoutRequests/CreateCheckoutRequest.php b/app/Actions/CheckoutRequests/CreateCheckoutRequest.php
index f7bdc1ad91..a8c6d41368 100644
--- a/app/Actions/CheckoutRequests/CreateCheckoutRequest.php
+++ b/app/Actions/CheckoutRequests/CreateCheckoutRequest.php
@@ -2,6 +2,7 @@
namespace App\Actions\CheckoutRequests;
+use App\Helpers\Helper;
use App\Models\Actionlog;
use App\Models\Asset;
use App\Models\Company;
@@ -9,25 +10,28 @@ use App\Models\Setting;
use App\Models\User;
use App\Notifications\RequestAssetCancelation;
use App\Notifications\RequestAssetNotification;
+use Illuminate\Http\JsonResponse;
+use Illuminate\Http\RedirectResponse;
use Lorisleiva\Actions\Concerns\AsAction;
-use Illuminate\Log;
class CreateCheckoutRequest
{
use AsAction;
+ public string $status;
+
public function handle($assetId)
{
$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'));
+ $this->status = 'doesNotExist';
+ return false;
}
if (!Company::isCurrentUserHasAccess($asset)) {
- return redirect()->route('requestable-assets')
- ->with('error', trans('general.insufficient_permissions'));
+ $this->status = 'accessDenied';
+ return false;
}
$data['item'] = $asset;
@@ -57,8 +61,8 @@ class CreateCheckoutRequest
} catch (\Exception $e) {
Log::warning($e);
}
- return redirect()->route('requestable-assets')
- ->with('success')->with('success', trans('admin/hardware/message.requests.canceled'));
+ $this->status = 'cancelled';
+ return true;
}
$logaction->logaction('requested');
@@ -67,9 +71,28 @@ class CreateCheckoutRequest
try {
$settings->notify(new RequestAssetNotification($data));
} catch (\Exception $e) {
- Log::warning($e);
+ \Log::warning($e);
}
- return redirect()->route('requestable-assets')->with('success')->with('success', trans('admin/hardware/message.requests.success'));
+ return true;
+ }
+
+ public function jsonResponse(): JsonResponse
+ {
+ return match ($this->status) {
+ 'doesNotExist' => response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist_or_not_requestable'))),
+ 'accessDenied' => response()->json(Helper::formatStandardApiResponse('error', null, trans('general.insufficient_permissions'))),
+ default => response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.request_successfully_created'))),
+ };
+ }
+
+ public function htmlResponse(): RedirectResponse
+ {
+ return match ($this->status) {
+ 'doesNotExist' => redirect()->route('requestable-assets')->with('error', trans('admin/hardware/message.does_not_exist_or_not_requestable')),
+ 'accessDenied' => redirect()->route('requestable-assets')->with('error', trans('general.insufficient_permissions')),
+ 'cancelled' => redirect()->route('requestable-assets')->with('success')->with('success', trans('admin/hardware/message.requests.canceled')),
+ default => 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 d9c1f0facf..722974713f 100755
--- a/app/Http/Controllers/ViewAssetsController.php
+++ b/app/Http/Controllers/ViewAssetsController.php
@@ -145,7 +145,11 @@ class ViewAssetsController extends Controller
*/
public function getRequestAsset($assetId = null): void
{
- CreateCheckoutRequest::run($assetId);
+ $request = CreateCheckoutRequest::run($assetId);
+
+ if (!$request) {
+ \Log::debug('problem');
+ }
}
public function getRequestedAssets() : View