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
User permission fixes #23331
User permission fixes #23331
Conversation
user.permission = UserPermission::FACILITATOR | ||
test 'revoke_all_permissions drops permission cache' do | ||
user = create :facilitator | ||
user.permission?(UserPermission::LEVELBUILDER) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the point of this call? We don't check the return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This first call to permission?
populates the permission cache, so we can later check that it's cleared.
I lifted this approach from the caching test that I copied over:
code-dot-org/dashboard/test/models/user_test.rb
Lines 1938 to 1946 in 279f685
test 'permission? caches all permissions' do | |
user = create :facilitator | |
user.permission?(UserPermission::LEVELBUILDER) | |
no_database | |
assert user.permission?(UserPermission::FACILITATOR) | |
refute user.permission?(UserPermission::LEVELBUILDER) | |
end |
I didn't come up with a way to assert that the cache has been filled without the no_database
call the previous test uses. Maybe, in turn, this needs a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. I'd either add a comment, or instead override reload_permissions
to also refresh that @permissions
cache and call that.
Some updates to the
UserPermissionGrantee
implementation suggested by @aoby while reviewing #23329.revoke_all_permissions
should clear the user's permissions cache.levelbuilder?