RolifyCommunity / rolify

Role management library with resource scoping
https://rolifycommunity.github.io/rolify/
MIT License
3.16k stars 404 forks source link

Model.with_roles is undefined #481

Closed Zhao-Andy closed 5 years ago

Zhao-Andy commented 6 years ago

Doesn't seem like there's an actual method .with_roles, even though the ReadMe has it. Is this a deprecated method?

AncyentMariner commented 6 years ago

@Zhao-Andy I'm having the same issue. I'm using version 5.1.0

dkniffin commented 6 years ago

Yep, I'm also seeing this. cc @wldcordeiro

Zhao-Andy commented 6 years ago

@AncyentMariner @dkniffin Seems like the actual method is Model.with_any_role or Model.with_all_roles, depending on your use case. I ended up using with_any_role for mine.

There is a singular version Model.with_role, which works for checking for one role. For example: User.with_role(:admin)

I found a more accurate documentation in the Usage wiki.

dkniffin commented 6 years ago

Nice. To finish up this issue then, we'd just need to update the Readme. Maybe just linking to the usage docs would be sufficient.

sergey-alekseev commented 5 years ago

This is actually confusing, let me clarify.

README.md mentions

Forum.with_roles([:admin, :user], current_user)
# => [ list of Forum instances that have role "admin" or "user" bound to them and belong to current_user roles ]

Forum is a resource model and contains resourcify. (3.2 Configure your resource models)
The resourcify call automatically includes the Resource module which contains with_roles as an alias to with_role.

The aforementioned Usage Wiki is a good finding because it contains two separate sections – Finders methods (1) and Resource methods (2).

EppO commented 5 years ago

Indeed, you can call .with_role (or with_roles which is an alias) on a model that includes Resource module. I confess README can be improved to make it clearer

mczal commented 4 years ago

Indeed, you can call .with_role (or with_roles which is an alias) on a model that includes Resource module. I confess README can be improved to make it clearer

@EppO Hey its absolutely can't be an aliases, because the generated query is completely wrong from the general conventions. .with_role should be receiving a single role as parameter .with_roles should be receiving a plural role as parameter and the generated query have to adjust those different kind of logic.