Skip to content

Commit

Permalink
feat(APIv2): RHINENG-11984 allow filtering systems by profile_ref_ids
Browse files Browse the repository at this point in the history
  • Loading branch information
skateman authored and romanblanco committed Aug 16, 2024
1 parent 40be269 commit 1092f62
Show file tree
Hide file tree
Showing 3 changed files with 4,429 additions and 4,455 deletions.
7 changes: 7 additions & 0 deletions app/models/v2/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ def self.first_group_name(table = arel_table)
{ conditions: "inventory.hosts.id IN (#{ids.to_sql})" }
end

searchable_by :profile_ref_ids, %i[neq notin] do |_key, _op, val|
values = val.split.map(&:strip)
ids = ::V2::PolicySystem.joins(policy: :profile).where.not(profile: { ref_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
42 changes: 42 additions & 0 deletions spec/fixtures/files/searchable/systems_controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,45 @@
:except_parents:
- :policies
- :reports

- :name: "non-equality search by profile_ref_ids"
:entities:
:found:
- :factory: :system
:account: ${account}
:policy_id: ${policy_9.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_7.id}
:os_minor_version: 1
:query: (profile_ref_ids != "${policy_7.ref_id}")
:except_parents:
- :policies
- :reports

- :name: "not-in search by profile_ref_ids"
:entities:
:found:
- :factory: :system
:account: ${account}
:policy_id: ${policy_9.id}
:os_minor_version: 1
:not_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
:query: (profile_ref_ids !^ "${policy_7.ref_id} ${policy_8.ref_id}")
:except_parents:
- :policies
- :reports
Loading

0 comments on commit 1092f62

Please sign in to comment.