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

fixes #6488 - enable autosearch completion on Katello model filters #4385

Merged
merged 1 commit into from
Sep 11, 2014
Merged

fixes #6488 - enable autosearch completion on Katello model filters #4385

merged 1 commit into from
Sep 11, 2014

Conversation

stbenjam
Copy link
Contributor

@stbenjam stbenjam commented Jul 3, 2014

First shot at this, I've got some questions:

  1. 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.

  2. 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?

  3. 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?

@stbenjam
Copy link
Contributor Author

stbenjam commented Jul 3, 2014

[test]

@ehelms
Copy link
Member

ehelms commented Jul 3, 2014

On Thu, Jul 3, 2014 at 7:28 AM, Stephen Benjamin notifications@github.com
wrote:

First shot at this, I've got some questions:

  1. 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
    fixes #5753: Engines can now override autocomplete path used in FiltersHelper theforeman/foreman#1452 we can route it
    wherever.

I tend to prefer as much as possible being anchored on the API. That being
said, if this has no use for an API user, then that pushes the argument
towards UI only controllers.

  1. 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?

If you can, feel free to consolidate on a single method to handle
autocomplete (i.e. make use of the Foreman one). Ours was written many
years ago before the idea of concerns was being used in the Rails world.
The filter feature extends from the fact that Katello made use of
Elasticsearch to do autocomplete originally (and still does if you go and
use Content Search for example). If possible, a single autocomplete
controller would be nice.

  1. 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?

There is a much larger issue around what to use for searching. Scoped
search / AR vs Elasticsearch. I wouldn't try to solve that here. For the
permissions autocomplete, using the Foreman method seems sane for
consistency.


You can merge this Pull Request by running

git pull https://github.com/stbenjam/katello autocomplete

Or view, comment on, or merge it at:

#4385
Commit Summary

File Changes

Patch Links:


Reply to this email directly or view it on GitHub
#4385.

@stbenjam stbenjam changed the title fixes #6435 enable autosearch completion on Katello model filters (WIP, don't merge yet) fixes #6488 enable autosearch completion on Katello model filters (WIP, don't merge yet) Jul 3, 2014
@stbenjam stbenjam changed the title fixes #6488 enable autosearch completion on Katello model filters (WIP, don't merge yet) fixes #6488 - enable autosearch completion on Katello model filters Jul 4, 2014
@stbenjam
Copy link
Contributor Author

stbenjam commented Jul 4, 2014

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.

@parthaa
Copy link
Contributor

parthaa commented Jul 8, 2014

@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'
Copy link
Contributor

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 ..

@parthaa
Copy link
Contributor

parthaa commented Jul 8, 2014

I was just chatting about this with @ehelms . I see a lot of controllers with this kinda code

module Katello
   class ActivationKeysController < Katello::ApplicationController
     include Foreman::Controller::AutoCompleteSearch

   end
 end

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?

@stbenjam
Copy link
Contributor Author

stbenjam commented Jul 8, 2014

@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.

@parthaa
Copy link
Contributor

parthaa commented Jul 8, 2014

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 ?

@stbenjam
Copy link
Contributor Author

stbenjam commented Jul 8, 2014

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?

  %w(activation_keys content_views gpg_keys content_hosts
     environments host_collections sync_plans).each do |path|

    model = case path
      when 'content_hosts'
        'System'
      when 'environments'
        'KTEnvironment'
      else
        path.singularize.camelize
    end

    match "#{path}/auto_complete_search",
      :controller => :auto_complete_search,
      :action     => :auto_complete_search,
      :model      => model
  end

@jlsherrill
Copy link
Member

could you do something like:

match '/:model/auto_complete_search', :action => :auto_complete_search, :controller => :auto_complete_search, :via => :get

and then just in the controller

"Katello::#{param[:model].singularize.camelcase}".constantize"

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:

{
'activation_keys' => ActivationKey,
'content_views' => ContentView
}

@jlsherrill
Copy link
Member

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.

@parthaa
Copy link
Contributor

parthaa commented Jul 8, 2014

+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.

@parthaa
Copy link
Contributor

parthaa commented Jul 8, 2014

You can then write 1 test for this autocomplete search controller and be done :)

@stbenjam
Copy link
Contributor Author

stbenjam commented Jul 9, 2014

@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))
Copy link
Contributor Author

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.

@stbenjam
Copy link
Contributor Author

@partha Ok, have a look! :-)

@parthaa
Copy link
Contributor

parthaa commented Jul 11, 2014

ACK from me.... @jlsherrill - do you want go over ?

@jlsherrill
Copy link
Member

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.

@stbenjam
Copy link
Contributor Author

@jlsherrill Good find. This is fixable by adding a default scope to the model. Something like:

default scope { readable.where(:organization_id => Organization.current.id) }

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?

@ehelms
Copy link
Member

ehelms commented Aug 6, 2014

@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?

@stbenjam
Copy link
Contributor Author

stbenjam commented Aug 6, 2014

@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.

@ehelms
Copy link
Member

ehelms commented Aug 15, 2014

@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.

@stbenjam
Copy link
Contributor Author

stbenjam commented Sep 5, 2014

@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.

@stbenjam
Copy link
Contributor Author

stbenjam commented Sep 5, 2014

And current failure is due to Koji disk space.

@ehelms
Copy link
Member

ehelms commented Sep 5, 2014

[test]

@ehelms
Copy link
Member

ehelms commented Sep 8, 2014

ACK for me

@jlsherrill
Copy link
Member

ACK from me

@stbenjam
Copy link
Contributor Author

@ehelms Needed a rebase due to #4635 (made my changes to lib/katello/tasks/test.rake unneccessary). Do you want to re-ACK?

stbenjam added a commit that referenced this pull request Sep 11, 2014
fixes #6488 - enable autosearch completion on Katello model filters
@stbenjam stbenjam merged commit 09d306e into Katello:master Sep 11, 2014
@stbenjam stbenjam deleted the autocomplete branch September 18, 2014 19:11
This pull request was closed.
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.

4 participants