-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Description
Description
I was writing tests and came across this quirk.
Assuming you've given permission for a role to do a thing, this test still fails:
$role = Role::find(1);
$this->assertFalse($user->hasPermissionTo('do a thing'));
$this->assertFalse($user->hasRole(1));
$user->assignRole($role);
$this->assertTrue($user->hasRole(1));
$this->assertTrue($role->hasPermissionTo('do a thing'));
$this->assertTrue($user->hasPermissionTo('do a thing')); // fails here, same thing with `->can('do a thing');`But it works if you don't check permissions before assigning the role:
$role = Role::find(1);
// Works now that this is commented out
// $this->assertFalse($user->hasPermissionTo('do a thing'));
$this->assertFalse($user->hasRole(1));
$user->assignRole($role);
$this->assertTrue($user->hasRole(1));
$this->assertTrue($role->hasPermissionTo('do a thing'));
$this->assertTrue($user->hasPermissionTo('do a thing')); // works fineI assume this is some caching issue.
Steps To Reproduce
In the same function:
- Check a user for permissions
- Assign a role
- Check user has permission in that role
- Fail
Example Application
https://github.com/manstie/laravel-permissions-example
Version of spatie/laravel-permission package:
6.9
Version of laravel/framework package:
11.9
PHP version:
8.2
Database engine and version:
No response
OS: Windows/Mac/Linux version:
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels