Add policy for action events

This commit is contained in:
2023-12-08 10:45:01 +05:00
parent 374dfe8da1
commit a4265e488c
4 changed files with 96 additions and 8 deletions

View File

@@ -27,7 +27,7 @@ class LoanOrderFieldsForDetail
/**
* Loan order fields for detail
*/
public static function make(): array
public static function make($resource): array
{
return [
ID::make()->hide(),
@@ -160,8 +160,8 @@ class LoanOrderFieldsForDetail
->size('w-1/2'),
]),
MorphMany::make(__('Actions'), 'actions', config('nova.actions.resource'))
->canSeeWhen('isAdmin', $this)
// MorphMany::make(__('Actions'), 'actions', config('nova.actions.resource'))
// ->canSee(fn () => true)
];
}
}

View File

@@ -157,7 +157,7 @@ class LoanOrder extends Resource
*/
public function fieldsForDetail(): array
{
return LoanOrderFieldsForDetail::make();
return LoanOrderFieldsForDetail::make($this);
}
/**
@@ -380,6 +380,9 @@ class LoanOrder extends Resource
->creationRules('required')
->updateRules('nullable'),
]),
MorphMany::make(__('Actions'), 'actions', config('nova.actions.resource'))
->canSee(fn ($request) => false)
];
}

View File

@@ -0,0 +1,74 @@
<?php
namespace App\Policies\System\Logs;
use Laravel\Nova\Actions\ActionEvent;
use App\Models\User;
use Illuminate\Auth\Access\Response;
class ActionEventPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
if ($user->isAdmin()) {
return true;
}
return false;
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, ActionEvent $actionEvent): bool
{
if ($user->isAdmin()) {
return true;
}
return false;
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return false;
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, ActionEvent $actionEvent): bool
{
return false;
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, ActionEvent $actionEvent): bool
{
return false;
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, ActionEvent $actionEvent): bool
{
return false;
}
/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, ActionEvent $actionEvent): bool
{
return false;
}
}

View File

@@ -12,11 +12,13 @@ use App\Policies\Branch\BranchPolicy;
use App\Policies\Order\Loan\LoanOrderPolicy;
use App\Policies\Order\Loan\LoanTypePolicy;
use App\Policies\System\Location\ProvincePolicy;
use App\Policies\System\Logs\ActionEventPolicy;
use App\Policies\System\Roles\PermissionPolicy;
use App\Policies\System\Roles\RolePolicy;
use App\Policies\UserPolicy;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
use Laravel\Nova\Actions\ActionEvent;
class AuthServiceProvider extends ServiceProvider
{
@@ -26,16 +28,25 @@ class AuthServiceProvider extends ServiceProvider
* @var array<class-string, class-string>
*/
protected $policies = [
// Orders...
LoanOrder::class => LoanOrderPolicy::class,
// Users...
User::class => UserPolicy::class,
// Roles and permession
Role::class => RolePolicy::class,
Permission::class => PermissionPolicy::class,
Province::class => ProvincePolicy::class,
Branch::class => BranchPolicy::class,
LoanOrder::class => LoanOrderPolicy::class,
// Loan types...
LoanType::class => LoanTypePolicy::class,
// Branches and Provinces...
Branch::class => BranchPolicy::class,
Province::class => ProvincePolicy::class,
// ActionsEvents...
ActionEvent::class => ActionEventPolicy::class,
];
/**