Reset relations when permissions are updated or deleted #29
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In my feature and unit tests I am creating users with specific permissions for certain scenarios, this means that I am calling
setPermissions
multiple times in a test and during this process I have encountered the below issues which this PR fixes.Scenario A
When you call the
setPermissions
method the$role->getPermissions
relation returns the previous set of permissions as the model is not refreshed. Changed it so that it calls thesetRelations
method insetPermissions
to reset the relation.Code example to replicate issue
Code
Output
Scenario B
If you call
setPermissions
multiple times on the same model instance where some permissions already exist they get deleted by therevokeAll
method. Then thehasPermission
method is called which is using a non-refreshedgetPermissions
relation. Added calls tosetRelations
to the revoke methods.Code example to replicate issue
Code
Current Output
Fixed Output
Made a couple of other minor tweaks that do not affect functionality.