From a51671e10022b89e627b8805e3cadd98cd69ffb5 Mon Sep 17 00:00:00 2001 From: Frank Perez Date: Sat, 21 Sep 2024 13:24:42 -0400 Subject: [PATCH] Add additional model policy methods. (#196) * Add additional model policy methods. * Add additional permissions to config. * Update stub and config. --- config/filament-spatie-roles-permissions.php | 13 +++---- src/Commands/stubs/genericPolicy.stub | 40 ++++++++++++++++++++ 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/config/filament-spatie-roles-permissions.php b/config/filament-spatie-roles-permissions.php index 62c82e9..39bee0f 100644 --- a/config/filament-spatie-roles-permissions.php +++ b/config/filament-spatie-roles-permissions.php @@ -26,7 +26,7 @@ ], 'should_show_permissions_for_roles' => true, - + /* * Set as true to use simple modal resource. */ @@ -124,14 +124,13 @@ 'createPermission' => 'create', 'updatePermission' => 'update', 'deletePermission' => 'delete', + 'deleteAnyPermission' => 'delete-any', + 'replicatePermission' => 'replicate', 'restorePermission' => 'restore', + 'restoreAnyPermission' => 'restore-any', + 'reorderPermission' => 'reorder', 'forceDeletePermission' => 'force-delete', - - /* - * Additional Resource Permissions - */ - 'replicate', - 'reorder', + 'forceDeleteAnyPermission' => 'force-delete-any', ], /* diff --git a/src/Commands/stubs/genericPolicy.stub b/src/Commands/stubs/genericPolicy.stub index e1358f8..bcc1842 100644 --- a/src/Commands/stubs/genericPolicy.stub +++ b/src/Commands/stubs/genericPolicy.stub @@ -48,6 +48,14 @@ class {{ class }} return $user->checkPermissionTo('{{ deletePermission }}'); } + /** + * Determine whether the user can delete any models. + */ + public function deleteAny({{ user }} $user): bool + { + return $user->checkPermissionTo('{{ deleteAnyPermission }}'); + } + /** * Determine whether the user can restore the model. */ @@ -56,6 +64,30 @@ class {{ class }} return $user->checkPermissionTo('{{ restorePermission }}'); } + /** + * Determine whether the user can restore any models. + */ + public function restoreAny({{ user }} $user): bool + { + return $user->checkPermissionTo('{{ restoreAnyPermission }}'); + } + + /** + * Determine whether the user can replicate the model. + */ + public function replicate({{ user }} $user, {{ model }} ${{ modelVariable }}): bool + { + return $user->checkPermissionTo('{{ replicatePermission }}'); + } + + /** + * Determine whether the user can reorder the models. + */ + public function reorder({{ user }} $user): bool + { + return $user->checkPermissionTo('{{ reorderPermission }}'); + } + /** * Determine whether the user can permanently delete the model. */ @@ -63,4 +95,12 @@ class {{ class }} { return $user->checkPermissionTo('{{ forceDeletePermission }}'); } + + /** + * Determine whether the user can permanently delete any models. + */ + public function forceDeleteAny({{ user }} $user): bool + { + return $user->checkPermissionTo('{{ forceDeleteAnyPermission }}'); + } }