89 lines
1.8 KiB
PHP
89 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\SberPaymentOrder\Nova\Resources\Concerns;
|
|
|
|
use App\Modules\SberPaymentOrder\Models\SberPaymentOrder;
|
|
use Illuminate\Auth\Access\AuthorizationException;
|
|
use Illuminate\Http\Request;
|
|
|
|
trait NovaSberPaymentOrderAuth
|
|
{
|
|
/** View */
|
|
public function authorizeToView(Request $request)
|
|
{
|
|
$user = auth()->user();
|
|
|
|
if ($user->isSystemUser()) {
|
|
return;
|
|
}
|
|
|
|
/** @var SberPaymentOrder $resource */
|
|
$resource = $this->resource;
|
|
if ($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;
|
|
}
|
|
|
|
/** Update */
|
|
public function authorizeToUpdate(Request $request): void
|
|
{
|
|
$user = auth()->user();
|
|
|
|
if ($user->isSystemUser()) {
|
|
return;
|
|
}
|
|
|
|
/** @var SberPaymentOrder $resource */
|
|
$resource = $this->resource;
|
|
if ($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;
|
|
}
|
|
|
|
/** Delete */
|
|
public function authorizeToDelete(Request $request)
|
|
{
|
|
$user = auth()->user();
|
|
|
|
if ($user->isSystemUser()) {
|
|
return;
|
|
}
|
|
|
|
throw new AuthorizationException;
|
|
}
|
|
|
|
/** Force delete */
|
|
public function authorizedToForceDelete(Request $request)
|
|
{
|
|
return auth()->user()->isMe();
|
|
}
|
|
}
|