-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Permissions are not updated once assigned a role #2725
Comments
I would expect that calling Checking for a permission will load the permissions relation on the model, but then we destroy and reload that when roles/permissions are changed for that model. Quick test in Tinker using some data similar to what's in the docs: $user = User::first();
$role = Role::find(1); // 'Writer', with one permission: 'edit articles'
$before = $user->hasPermissionTo('edit articles');
$user->assignRole($role);
$afterRole =$user->hasRole(1);
$after = $user->hasPermissionTo('edit articles');
dd(compact('before', 'after'));
|
This is isolated to your tests? If so, can you update the Issue Title to include that factor. This package's test suite does extensive testing of adding and checking roles and permissions to ensure there are no caching issues, etc. If you can create a simple fresh app (the Docs have a section on creating a new app and pushing it to a public github repo) that recreates this specific problem, we can determine whether this is a package bug or a bug in your application, and figure out the fix. |
I have created an app replicating my environment and settings here: https://github.com/manstie/laravel-permissions-example
|
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:But it works if you don't check permissions before assigning the role:
I assume this is some caching issue.
Steps To Reproduce
In the same function:
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
The text was updated successfully, but these errors were encountered: