Skip to content

Commit

Permalink
Add additional model policy methods. (#196)
Browse files Browse the repository at this point in the history
* Add additional model policy methods.

* Add additional permissions to config.

* Update stub and config.
  • Loading branch information
frankperez87 authored Sep 21, 2024
1 parent d68c574 commit a51671e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
13 changes: 6 additions & 7 deletions config/filament-spatie-roles-permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
],

'should_show_permissions_for_roles' => true,

/*
* Set as true to use simple modal resource.
*/
Expand Down Expand Up @@ -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',
],

/*
Expand Down
40 changes: 40 additions & 0 deletions src/Commands/stubs/genericPolicy.stub
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -56,11 +64,43 @@ 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.
*/
public function forceDelete({{ user }} $user, {{ model }} ${{ modelVariable }}): bool
{
return $user->checkPermissionTo('{{ forceDeletePermission }}');
}

/**
* Determine whether the user can permanently delete any models.
*/
public function forceDeleteAny({{ user }} $user): bool
{
return $user->checkPermissionTo('{{ forceDeleteAnyPermission }}');
}
}

0 comments on commit a51671e

Please sign in to comment.