sber permissions

This commit is contained in:
2024-11-07 10:23:24 +05:00
parent 75de39b5ba
commit 0744b372d4
6 changed files with 135 additions and 1 deletions

View File

@@ -0,0 +1,87 @@
<?php
namespace App\Modules\SberPaymentOrder\Nova\Resources\Concerns;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
trait NovaSberPaymentOrderAuth
{
public function authorizeToView(Request $request)
{
$user = auth()->user();
if ($user->isSystemUser()) {
return;
}
if ($this->resource->user_id == auth()->id()) {
return;
}
throw new AuthorizationException();
}
/**
* Edit button
*/
public function authorizedToUpdate(Request $request): bool
{
$user = auth()->user();
if ($user->isSystemUser()) {
return true;
}
return false;
}
/**
* Edit proceess
*/
public function authorizeToUpdate(Request $request): void
{
$user = auth()->user();
if ($user->isSystemUser()) {
return;
}
if ($this->resource->user_id == auth()->id()) {
return;
}
throw new AuthorizationException();
}
/**
* Delete button
*/
public function authorizedToDelete(Request $request)
{
$user = auth()->user();
if ($user->isSystemUser()) {
return true;
}
return false;
}
public function authorizeToDelete(Request $request)
{
$user = auth()->user();
if ($user->isSystemUser()) {
return;
}
throw new AuthorizationException();
}
public function authorizedToForceDelete(Request $request)
{
throw_unless(auth()->user()->isMe(), AuthorizationException::class);
}
}