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 #360 - Fix puppetclass keyword search #364

Merged
merged 3 commits into from
Aug 15, 2023

Conversation

nadjaheitmann
Copy link
Collaborator

@nadjaheitmann nadjaheitmann commented Aug 1, 2023

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.

@stejskalleos stejskalleos self-assigned this Aug 1, 2023
@nadjaheitmann
Copy link
Collaborator Author

nadjaheitmann commented Aug 1, 2023

@stejskalleos Search does work and the UI issue is fixed but the autocomplete still does not work and fails with NoMethodError (undefined method 'klass' for nil:NilClass): . If you type in the hosts or hostgroup search this reflects as Error: Request failed with status code 500 but if you hit the search button the search itself will complete.

@nadjaheitmann
Copy link
Collaborator Author

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: ['= ', '~ ']
Copy link
Contributor

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?

Copy link
Collaborator Author

@nadjaheitmann nadjaheitmann Aug 3, 2023

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

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

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

Copy link
Collaborator Author

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?

Copy link
Collaborator Author

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

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

@nadjaheitmann
Copy link
Collaborator Author

@stejskalleos Beware that the PR currently contains a fixup commit.

Copy link
Contributor

@stejskalleos stejskalleos left a 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

@nadjaheitmann nadjaheitmann force-pushed the 360_hostgroup_search_fail branch 2 times, most recently from 88f9978 to ff72761 Compare August 10, 2023 12:55
@nadjaheitmann
Copy link
Collaborator Author

Failing tests are related to the changes

@stejskalleos Please re-review.

Copy link
Contributor

@stejskalleos stejskalleos left a 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

@stejskalleos stejskalleos merged commit b3a18fb into theforeman:master Aug 15, 2023
3 of 4 checks passed
@stejskalleos
Copy link
Contributor

Thanks @nadjaheitmann !

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.

Remove deprecated search parameter class...
2 participants