mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
more work
This commit is contained in:
parent
b1d62cc478
commit
a524c0b418
|
@ -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
|
|
||||||
{
|
|
||||||
}
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Actions\CheckoutRequests;
|
namespace App\Actions\CheckoutRequests;
|
||||||
|
|
||||||
|
use App\Helpers\Helper;
|
||||||
use App\Models\Actionlog;
|
use App\Models\Actionlog;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
|
@ -9,25 +10,28 @@ use App\Models\Setting;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Notifications\RequestAssetCancelation;
|
use App\Notifications\RequestAssetCancelation;
|
||||||
use App\Notifications\RequestAssetNotification;
|
use App\Notifications\RequestAssetNotification;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Lorisleiva\Actions\Concerns\AsAction;
|
use Lorisleiva\Actions\Concerns\AsAction;
|
||||||
use Illuminate\Log;
|
|
||||||
|
|
||||||
class CreateCheckoutRequest
|
class CreateCheckoutRequest
|
||||||
{
|
{
|
||||||
use AsAction;
|
use AsAction;
|
||||||
|
|
||||||
|
public string $status;
|
||||||
|
|
||||||
public function handle($assetId)
|
public function handle($assetId)
|
||||||
{
|
{
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
|
|
||||||
// Check if the asset exists and is requestable
|
// Check if the asset exists and is requestable
|
||||||
if (is_null($asset = Asset::RequestableAssets()->find($assetId))) {
|
if (is_null($asset = Asset::RequestableAssets()->find($assetId))) {
|
||||||
return redirect()->route('requestable-assets')
|
$this->status = 'doesNotExist';
|
||||||
->with('error', trans('admin/hardware/message.does_not_exist_or_not_requestable'));
|
return false;
|
||||||
}
|
}
|
||||||
if (!Company::isCurrentUserHasAccess($asset)) {
|
if (!Company::isCurrentUserHasAccess($asset)) {
|
||||||
return redirect()->route('requestable-assets')
|
$this->status = 'accessDenied';
|
||||||
->with('error', trans('general.insufficient_permissions'));
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$data['item'] = $asset;
|
$data['item'] = $asset;
|
||||||
|
@ -57,8 +61,8 @@ class CreateCheckoutRequest
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::warning($e);
|
Log::warning($e);
|
||||||
}
|
}
|
||||||
return redirect()->route('requestable-assets')
|
$this->status = 'cancelled';
|
||||||
->with('success')->with('success', trans('admin/hardware/message.requests.canceled'));
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$logaction->logaction('requested');
|
$logaction->logaction('requested');
|
||||||
|
@ -67,9 +71,28 @@ class CreateCheckoutRequest
|
||||||
try {
|
try {
|
||||||
$settings->notify(new RequestAssetNotification($data));
|
$settings->notify(new RequestAssetNotification($data));
|
||||||
} catch (\Exception $e) {
|
} 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')),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,7 +145,11 @@ class ViewAssetsController extends Controller
|
||||||
*/
|
*/
|
||||||
public function getRequestAsset($assetId = null): void
|
public function getRequestAsset($assetId = null): void
|
||||||
{
|
{
|
||||||
CreateCheckoutRequest::run($assetId);
|
$request = CreateCheckoutRequest::run($assetId);
|
||||||
|
|
||||||
|
if (!$request) {
|
||||||
|
\Log::debug('problem');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRequestedAssets() : View
|
public function getRequestedAssets() : View
|
||||||
|
|
Loading…
Reference in a new issue