-
Notifications
You must be signed in to change notification settings - Fork 25
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 #360 - Fix puppetclass keyword search #364
Fixes #360 - Fix puppetclass keyword search #364
Conversation
3634ba5
to
e898842
Compare
@stejskalleos Search does work and the UI issue is fixed but the autocomplete still does not work and fails with |
I opened a follow-up issue for the auto completion #365 |
@@ -17,6 +17,7 @@ class << self | |||
# will need through relation to work properly | |||
scoped_search relation: :environment, on: :name, complete_value: true, rename: :environment, only_explicit: true | |||
scoped_search relation: :puppetclasses, on: :name, complete_value: true, rename: :class, only_explicit: true, operators: ['= ', '~ '] |
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.
Do we want to keep the class
search parameter or it's time to remove it?
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.
Personally, I would remove it but then we should also remove it for hosts. This then partly implements fixes for #363
|
||
def search_by_puppetclass(_key, operator, value) | ||
conditions = sanitize_sql_for_conditions(["puppetclasses.name #{operator} ?", value_to_sql(operator, value)]) | ||
hostgroup_ids = ::Hostgroup.unscoped.with_taxonomy_scope.joins(puppet: :puppetclasses).where(conditions).map(&:subtree_ids) |
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 hostgroup model is by default scoped under taxonomies, you can do just ::Hostgroup.joins(puppet: :puppetclasses).where(conditions).map(&:subtree_ids)
hostgroup_ids = ::Hostgroup.unscoped.with_taxonomy_scope.joins(puppet: :puppetclasses).where(conditions).map(&:subtree_ids) | ||
conds = [] | ||
conds << "hostgroups.id IN (#{hostgroup_ids.join(',')})" if hostgroup_ids.present? | ||
{ conditions: conds.join(' OR ').presence || 'hostgroups.id < 0' } |
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.
Nit: Empty line between conds <<
and returning value
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.
Well, then let's do even more nitpicking and adjust also the formatting and naming scheme in lines 31ff?
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.
@stejskalleos If I look at this, I wonder why hostgroup search for puppetclass
looks different from the one for config_groups
.
@@ -17,6 +17,7 @@ class << self | |||
# will need through relation to work properly | |||
scoped_search relation: :environment, on: :name, complete_value: true, rename: :environment, only_explicit: true | |||
scoped_search relation: :puppetclasses, on: :name, complete_value: true, rename: :class, only_explicit: true, operators: ['= ', '~ '] | |||
scoped_search relation: :puppetclasses, on: :name, complete_value: true, rename: :puppetclass, only_explicit: true, operators: ['= ', '~ '], ext_method: :search_by_puppetclass |
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.
Nit: Line is pretty long, not much readable IMHO
@stejskalleos Beware that the PR currently contains a fixup commit. |
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.
Failing tests are related to the changes
88f9978
to
ff72761
Compare
ff72761
to
0645712
Compare
@stejskalleos Please re-review. |
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.
🍏 LGTM, works as expected
Thanks @nadjaheitmann ! |
Actually, it implements the puppetclass keyword that should have replaced the class keyword in Foreman 3.2.
I will create a follow-up PR that fixes #363 and remove the class search completely.