Skip to content
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

Fix with_role with :any resource #575

Merged
merged 2 commits into from
Feb 8, 2022

Conversation

v-kumar
Copy link
Contributor

@v-kumar v-kumar commented Feb 4, 2022

Pre 6.0.0, this used to work with strict.

  User.with_role(:owner, :any)

With 6.0.0, (due to the PR #543), the above code breaks.

> User.with_role(:owner, :any)
NoMethodError: undefined method `id' for :any:Symbol
from /usr/local/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rolify-6.0.0/lib/rolify/adapters/active_record/role_adapter.rb:17:in `where_strict'

This is because of line

strict = self.strict_rolify and resource and resource != :any

In Ruby, and keyword and && operator have different orders of precedence.

In the below case, (a = true) is evaluated first. Hence, strict from the aboe line is always true in strict mode.

> a = true and false
false
> a
true

@thomas-mcdonald thomas-mcdonald merged commit 0c883f4 into RolifyCommunity:master Feb 8, 2022
@v-kumar
Copy link
Contributor Author

v-kumar commented Feb 8, 2022

Thank you for merging this. Please let me know when you have a new patch release.

@tannakartikey
Copy link

Somehow I am not always getting this error. I have a production deployment on Heroku that does not raise this error. Locally (development and production) and on ElasticBeanstalk it does raise errors though. Not sure what is going on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants