-
Notifications
You must be signed in to change notification settings - Fork 289
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
fixes #6488 - enable autosearch completion on Katello model filters #4385
Conversation
[test] |
On Thu, Jul 3, 2014 at 7:28 AM, Stephen Benjamin notifications@github.com
|
Ok, thanks! That's perfect. I've moved it all to use the Foreman AutoCompleteSearch controller. The code's ready for review when you have time. |
@stbenjam Were you planning to add any tests for some of the controller actions you added ? |
'katello/dashboard' | ||
'katello/sync_management', | ||
'katello/sync_plans', | ||
'katello/systems' |
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.
appreciate the alphabetic ordering :). Makes things easier to read ..
I was just chatting about this with @ehelms . I see a lot of controllers with this kinda code
I was wondering if it would be possible for you to create 1 controller, but create many routes and point their routes to this controller? |
@parthaa Could do, I assumed the best practice would've been to have one named controller per one named model, I've rarely seen it done otherwise. But I could use a single controller for all the models. |
Somehow creating 5 empty controllers only just for that one text search box in the permissions filters page seems like an over kill for me.. May we could group all the auto complete search stuff pointing to that one controller. @ehelms , @jlsherrill what do you guys think ? |
I agree, it does seem unnecessary. I've got something like this in routes.rb now, still working on ironing out the details, but it does reduce this all to 1 controller. Is that the right direction?
|
could you do something like:
and then just in the controller
To get the model class from there. Not sure if that's too hacky for some :) It is a lot shorter, and just works for new models. If you wanted to limit it only to certain models, you could simply have a name to lookup conversion in the controller:
|
Oh yeah forgot about the ones where the route doesn't match the model name. So my example is nearly the same as yours, the logic just goes to the controller. I like it better in the controller (i prefer routes with as little logic as possible), but others may disagree. |
+1 to @jlsherrill 's idea . I like the lookup much better .. Constantize too hacky. Lookup and raise a 404 if it cant find the model. |
You can then write 1 test for this autocomplete search controller and be done :) |
@parthaa @jlsherrill Thanks guys! There's some sorcery needed to get permissions working, still working on that, I'll let you know when it's ready to review again :-) |
def authorized | ||
if converted_controllers.include?(request.params['controller']) | ||
super | ||
if self.respond_to? :permission_controller | ||
User.current.allowed_to?(params.slice(:action, :id).merge(:controller => permission_controller)) |
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.
The idea here is so that permissions can be evaluated against an arbitrary target defined by the controller -- e.g. content_hosts#auto_complete_search, not auto_complete_search#auto_complete_search.
@partha Ok, have a look! :-) |
ACK from me.... @jlsherrill - do you want go over ? |
The code itself looks very good and concise! +1. One thing i noted was that when using auto complete with katello items it seemed to ignore my selected org and show me items in all orgs. Foreman objects like 'Host/Managed' did not seem to do this. |
@jlsherrill Good find. This is fixable by adding a default scope to the model. Something like:
However, this breaks the API controllers. I would prefer to address this as a separate issue, ideally by making Katello use the same taxonomy configuration as Foreman -- we seem to have done our own thing, which causes problems when we try to integrate into Foreman things like this. Although, I was trying it out today, and it just doesn't work right (even if you reach the point where Rails starts), there seems to be a lot of issues with taxonomies in general (many stemming from this nested stuff). Has anyone tried this before with Katello? |
@stbenjam I think for now, baking checking of Organzation.current into the autocomplete will be the best approach as all other choices appear to involve re-factoring a section of other areas. Could you also rebase/fix tests? |
@ehelms Done, but that only partially works. I can only do the top most layer, e.g on Activation Keys, "name =" is properly confined to the current org if there is one. However, on a Content View, querying "activation_key = " is not and you'll see them all. |
@stbenjam sorry for the delay in getting back to you - I think that could be OK for now, as long as we open an issue to track respecting organization's on associations. |
@ehelms Not really a good way to fix it, so I removed the scoped searches on associations. There's already an issue to enable this: http://projects.theforeman.org/issues/4638, which we can do when we fix the problem with searching in associations. |
And current failure is due to Koji disk space. |
[test] |
ACK for me |
ACK from me |
fixes #6488 - enable autosearch completion on Katello model filters
First shot at this, I've got some questions:
Should the AutoCompleteSearch go through the API controllers instead? I've had to create normal controllers for the models to handle the requests to keep the Foreman style of URL's. Although with fixes #5753: Engines can now override autocomplete path used in FiltersHelper theforeman/foreman#1452 we can route it wherever.
app/controllers/katello/auto_complete_search.rb - this isn't significantly different from Foreman's, could we use theirs instead? The only difference is 'filter' feature, but I don't see it used anywhere...? Also shouldn't it be a concern?
What are all these auto_complete methods everywhere? Intended for the angular views it seems? Shouldn't we try to use the same style as Foreman for searching?