84 lines
1.6 KiB
PHP
84 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\VisaMasterPaymentOrder\Nova\Resources\Concerns;
|
|
|
|
use Illuminate\Auth\Access\AuthorizationException;
|
|
use Illuminate\Http\Request;
|
|
|
|
trait VisaMasterAuth
|
|
{
|
|
/** View */
|
|
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;
|
|
}
|
|
|
|
/** Update */
|
|
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;
|
|
}
|
|
|
|
/** Delete */
|
|
public function authorizeToDelete(Request $request)
|
|
{
|
|
$user = auth()->user();
|
|
|
|
if ($user->isSystemUser()) {
|
|
return;
|
|
}
|
|
|
|
throw new AuthorizationException();
|
|
}
|
|
|
|
/** Force delete */
|
|
public function authorizedToForceDelete(Request $request)
|
|
{
|
|
throw_unless(auth()->user()->isMe(), AuthorizationException::class);
|
|
}
|
|
}
|