Issue with accessible_by and ActiveRecord SQL JOIN behavior#1002
Issue with accessible_by and ActiveRecord SQL JOIN behavior#1002jackryon wants to merge 8 commits intoryanb:masterfrom
Conversation
… a call to includes. this yields a left outer join instead of an inner join. combined abilities now work for accessible_by call on a given model with complex hash conditions.
|
Thanks for your submission! The ryanb/cancan repository has been inactive since Sep 06, 2013. CanCan has many open issues, including missing support for Rails 4. To keep CanCan alive, an active fork exists at cancancommunity/cancancan. The new gem is cancancan. More info is available at #994. It would be really appreciated if you resubmit your pull request or issue to CanCanCan. We hope to see you on the other side! |
|
Thanks for your submission! The ryanb/cancan repository has been inactive since Sep 06, 2013. CanCan has many open issues, including missing support for Rails 4. To keep CanCan alive, an active fork exists at cancancommunity/cancancan. The new gem is cancancan. More info is available at #994. If your pull request or issue is still applicable, it would be really appreciated if you resubmit it to CanCanCan. We hope to see you on the other side! |
I have a bit of roundabout logic for permitting a user to access a given image tagged "private" in my application.
The rules are:
The 2 "can" statements from ability.rb that are relevant here are:
When calling accessible_by on a @user.images.accessible_by(current_ability), the call to @model_class.where(conditions).joins(joins) from cancan/lib/cancan/model_adapters/active_record_adapter.rb line 105 created SQL like this (note that there are some "type in" calls to accommodate polymorphic relationships, as well as other scopes being applies [acts_as_paranoid for one]):
This query doesn't work, however. We need to use an outer left join to return the images for which there are no "join" models, or we only get the models from the second can rule, and not the first. I'm 99% sure that this works in its place:
Because this only gets called in the context of accessible_by, I don't think there would be any other unintended side effects.