Skip to content

Commit

Permalink
feat(APIv2): RHINENG-2133 implement rules endpoint nested under profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
RoamingNoMaD committed Sep 20, 2023
1 parent 8e1f565 commit 38d7cde
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/models/v2/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class Rule < ApplicationRecord
)

belongs_to :security_guide
has_many :profile_rules, dependent: :delete_all
has_many :profiles, through: :profile_rules, source: :profile, class_name: 'V2::Profile'

sortable_by :title
sortable_by :severity, SORTED_SEVERITIES
Expand Down
5 changes: 5 additions & 0 deletions app/serializers/v2/rule_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ module V2
# JSON API serialization for an OpenSCAP Rule
class RuleSerializer < ApplicationSerializer
attributes :ref_id, :title, :rationale, :description, :severity, :precedence
attribute :remediation_issue_id

def include_remediation_issue_id?
true if object.params[:parents].include?(Profile)
end
end
end
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ def draw_routes(prefix)
unless Rails.env.production?
scope 'v2', module: 'v2', as: 'v2' do
resources :security_guides, only: [:index, :show] do
resources :profiles, only: [:index, :show], parents: [:security_guide]
resources :value_definitions, only: [:index, :show], parents: [:security_guide]
resources :rules, only: [:index, :show], parents: [:security_guide]
resources :profiles, only: [:index, :show], parents: [:security_guide] do
resources :rules, only: [:index, :show], parents: [:security_guide, :profiles]
end
end
end
end
Expand Down

0 comments on commit 38d7cde

Please sign in to comment.