CanCan and MetaWhere #194

Closed
HuckyDucky opened this Issue Nov 14, 2010 · 15 comments

Comments

Projects
None yet
3 participants

In Ability.rb:

can :read, Brand, :responsibilities => { :user_id => user.id, :role => { :name.not_eq => "No Access" } }

This works fine when calling accessible_by, but bails when used by a nested load_and_authorize_resource with.

Owner

ryanb commented Nov 14, 2010

This is because CanCan also uses Ruby to determine permissions, therefore it needs to convert the :name.not_eq to a Ruby comparison. I'll try to research and see if there's an easy way to do this.

hazah commented Feb 28, 2011

Looking through MetaWhere's source code, it seems that the most strait forward solution would be to ad a to_block type of method to each of the condition classes in the library, then extract that block and use it as regular block parameter of the can method.

Thoughts?

Ivgeni.

Owner

ryanb commented Feb 28, 2011

I think a simple matches? method on a MetaWhere condition would suffice. This would return true/false if the given object matches the given conditions. That could then be used in the active record adapter. No need to mess with blocks.

hazah commented Mar 1, 2011

True. The logic would be just about the same with either choice. I'm still honing in my ruby skills into being able to patch things like this up. I'm trying to get something like this working for my own project. I'll let you know if I'm having success once I have something.

Do you have a time-line in mind for this? I ask because whatever solution I will come up with shouldn't be trusted really. More seasoned eyes than mine should definitely be involved.

Ivgeni.

Owner

ryanb commented Mar 1, 2011

If the matches? behavior is added to MetaWhere I could get this into CanCan without too much trouble.

If you plan to add this to MetaWhere, I highly recommend adding tests for this as well. This way you ensure the code works.

hazah commented Mar 1, 2011

I do believe this belongs within the individual condition classes. This is where I will take the development and testing. Will be in touch about success/failure.

Ivgeni

hazah commented Mar 8, 2011

After a brief back and forth with ernie of MetaWhere, I haven't really gotten anywhere. It's probably that I'm not expressing the point of the problem well enough.

Here's the ticket link http://metautonomous.lighthouseapp.com/projects/53011/tickets/32-feature-request-transform-hash-into-a-block

Since I opened it it had been marked "invalid"

Owner

ryanb commented Mar 8, 2011

Yeah, seems he doesn't want it in core so this will need to be implemented in CanCan. It won't be as clean but shouldn't be too bad. I'm going to add a branch and make a starting point. I'll respond when that's done so others can fork that and fill in the implementation.

Owner

ryanb commented Mar 8, 2011

Ok, there is now a "meta_where" branch with some initial support for "gt" and "lt" conditions. Anyone can fork this and fill out the rest of the conditions. You should only need to edit the active_record_adapter and spec. To run the specs do this.

MODEL_ADAPTER=active_record bundle
MODEL_ADAPTER=active_record rake
Owner

ryanb commented Mar 9, 2011

@hazah, did you plan to work on this feature? If not let me know and I will since I plan to do a 1.6 release soon and want to get this in.

Owner

ryanb commented Mar 9, 2011

I'm going to go ahead and work on this since I don't think it will take too long and I'd like to get 1.6 out. Sorry if you were planning to work on it.

Owner

ryanb commented Mar 9, 2011

I'm done adding the various comparisons you can use with MetaWhere and it's merged into master. It will be in a 1.6 release soon.

It still doesn't support Or, And and Not operators but I'm calling this good for now because I don't think that feature is used as much as the comparisons. I will work on getting those in at another time. If someone else wants to dive in and try adding that feature feel free.

hazah commented Mar 9, 2011

@ryanb I would like to take a look at Or, And and Not. Though I am uncertain whether I'm qualified to do it, I want to try. So I'll fork it and let you know of my success or lack thereof.

hazah commented Mar 9, 2011

@ryanb After some thorough reading of the code I came to the conclusion that I just don't have the Ruby skills to add anything to it. At least not yet. So at this time I won't be contributing any code.

Owner

ryanb commented Mar 10, 2011

@hazah, thanks for taking a look. I browsed through the MetaWhere code and have a difficult time deciphering exactly how Or, And, and Not work. That is why I haven't integrated it in yet.

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment