Skip to content

Commit

Permalink
feat(APIv2): RHINENG-11754 filter systems by policy ID
Browse files Browse the repository at this point in the history
  • Loading branch information
skateman committed Aug 2, 2024
1 parent 8d486c1 commit f2f75fa
Show file tree
Hide file tree
Showing 3 changed files with 4,398 additions and 4,407 deletions.
7 changes: 7 additions & 0 deletions app/models/v2/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ def self.first_group_name(table = arel_table)
{ conditions: systems.arel.where_sql.gsub(/^where /i, '') }
end

searchable_by :policies, %i[eq in] do |_key, _op, val|
values = val.split.map(&:strip)
ids = ::V2::PolicySystem.where(policy_id: values).select(:system_id)

{ conditions: "inventory.hosts.id IN (#{ids.to_sql})" }
end

scope :with_groups, lambda { |groups, key = :id|
# Skip the [] representing ungrouped hosts from the array when generating the query
grouped = arel_inventory_groups(groups.flatten, key, arel_table)
Expand Down
41 changes: 41 additions & 0 deletions spec/fixtures/files/searchable/systems_controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,44 @@
:account: ${account}
:policy_id: ${policy.id}
:query: (group_name ^ "one,two")

- :name: "equality search by policies"
:entities:
:found:
- :factory: :system
:account: ${account}
:policy_id: ${policy_7.id}
:os_minor_version: 1
- :factory: :system
:account: ${account}
:policy_id: ${policy_7.id}
:os_minor_version: 1
:not_found:
- :factory: :system
:account: ${account}
:policy_id: ${policy_8.id}
:os_minor_version: 1
:query: (policies = ${policy_7.id})
:except_parents:
- :policies
- :reports
- :name: "in search by policies"
:entities:
:found:
- :factory: :system
:account: ${account}
:policy_id: ${policy_7.id}
:os_minor_version: 1
- :factory: :system
:account: ${account}
:policy_id: ${policy_8.id}
:os_minor_version: 1
:not_found:
- :factory: :system
:account: ${account}
:policy_id: ${policy_9.id}
:os_minor_version: 1
:query: (policies ^ "${policy_7.id} ${policy_8.id}")
:except_parents:
- :policies
- :reports
Loading

0 comments on commit f2f75fa

Please sign in to comment.