Replies: 2 comments 2 replies
-
|
Beta Was this translation helpful? Give feedback.
1 reply
-
I have been able to resolve this issue. I've had to make a minor modification for it work seamlessly.
'permission' => \App\Http\Middleware\PermissionMiddleware::class, Now the permission middleware works as expected. 😊 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Description
Using
$this->middleware('permission:update teams')
for example (in a controller's__construct
method) still allows all users access, even if they don't have the 'update teams' permission. This also applies even if we're using the middleware in a route too.I've assigned all permissions to a role, the role is then assigned to the user. I've debugged this further and I can see in
vendor/spatie/laravel-permission/src/Middleware/PermissionMiddleware.php
in the handle() method, the use of$user->canAny($permissions)
allows almost all permissions to return true.This is the RolesAndPermissionSeeder:
If the
$permission
variable in the PermissionMiddleware is an empty array, it does then return false. However, whenever we call$this->middleware('permission:update teams')
, the variable/array is never empty as the defined permission is inside the array.Steps To Reproduce
Adding the following in a TeamsController for example still allows a user to pass through permissions, even if they don't have those permissions assigned to their role.
However, using role works perfectly fine.
The issue is with using
permission
. The same also applies for routes. For example:Still allows the route to be accessed, even if the permission
lorem
does not exist. Testing based on the role also does work once again.Version of spatie/laravel-permission package:
6.9
Version of laravel/framework package:
10.48.20
PHP version:
8.3.9
Database engine and version:
MySQL 8.0
OS: Windows/Mac/Linux version:
No response
Beta Was this translation helpful? Give feedback.
All reactions