Skip to content

Commit

Permalink
feat(APIv2): RHINENG-11982 search SSGs by profile_ref_id and os_minor
Browse files Browse the repository at this point in the history
  • Loading branch information
skateman committed Aug 21, 2024
1 parent 50ee9cf commit de1fb85
Show file tree
Hide file tree
Showing 3 changed files with 4,669 additions and 4,376 deletions.
14 changes: 14 additions & 0 deletions app/models/v2/security_guide.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ class SecurityGuide < ApplicationRecord
searchable_by :ref_id, %i[eq ne in notin]
searchable_by :os_major_version, %i[eq ne]

searchable_by :profile_ref_id, %i[eq] do |_key, _op, val|
ids = ::V2::Profile.where(ref_id: val).select(:security_guide_id)

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

searchable_by :os_minor_version, %i[eq in] do |_key, _op, val|
values = val.split.map(&:strip)
ids = ::V2::Profile.joins(:os_minor_versions).where(os_minor_versions: { os_minor_version: values })
.select(:security_guide_id)

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

sortable_by :title
sortable_by :version, version_to_array(arel_table[:version])
sortable_by :os_major_version
Expand Down
53 changes: 53 additions & 0 deletions spec/fixtures/files/searchable/security_guides_controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,56 @@
- :factory: :v2_security_guide
:os_major_version: 7
:query: (os_major_version != 7)

- :name: "equality search by profile_ref_id"
:entities:
:found:
- :factory: :v2_security_guide
:profile_refs:
foo: []
bar: []
:not_found:
- :factory: :v2_security_guide
:profile_refs:
baz: []
:query: (profile_ref_id = xccdf_org.ssgproject.content_profile_foo)

- :name: "equality search by os_minor_version"
:entities:
:found:
- :factory: :v2_security_guide
:profile_refs:
foo: [1, 2]
bar: [2, 3]
:not_found:
- :factory: :v2_security_guide
:profile_refs:
baz: [1, 3, 4]
:query: (os_minor_version = 2)
- :name: "in search by os_minor_version"
:entities:
:found:
- :factory: :v2_security_guide
:profile_refs:
foo: [1, 2]
bar: [3, 4]
:not_found:
- :factory: :v2_security_guide
:profile_refs:
baz: [1, 4]
:query: (os_minor_version ^ "2 3")

- :name: "combined search by profile_ref_id and os_minor_version"
:entities:
:found:
- :factory: :v2_security_guide
:profile_refs:
foo: [1]
- :factory: :v2_security_guide
:profile_refs:
foo: [2]
:not_found:
- :factory: :v2_security_guide
:profile_refs:
bar: [1, 2]
:query: (profile_ref_id = xccdf_org.ssgproject.content_profile_foo and os_minor_version ^ "1 2")
Loading

0 comments on commit de1fb85

Please sign in to comment.