Skip to content

Commit

Permalink
Fixes #37798 - Fix AngularJS handling of AK CVEs
Browse files Browse the repository at this point in the history
  also add warning banner for multi-env AKs
  • Loading branch information
jeremylenz committed Sep 17, 2024
1 parent 24cd3a9 commit 359cd1f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
16 changes: 12 additions & 4 deletions app/controllers/katello/api/v2/activation_keys_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,16 @@ def create
param_group :activation_key
param :id, :number, :desc => N_("ID of the activation key"), :required => true
def update
@activation_key.update!(content_view_environments: @content_view_environments) if @content_view_environments.present?
if @content_view_environments.present?
if @content_view_environments.length == 1
@activation_key.assign_single_environment(
content_view: @content_view_environments.first.content_view,
lifecycle_environment: @content_view_environments.first.lifecycle_environment
)
else
@activation_key.update!(content_view_environments: @content_view_environments)
end
end
sync_task(::Actions::Katello::ActivationKey::Update, @activation_key, activation_key_params)
respond_for_show(:resource => @activation_key)
end
Expand Down Expand Up @@ -276,9 +285,8 @@ def subscription_index
end

def find_cve_for_single
environment_id = params[:environment_id]
environment_id ||= params.dig(:environment, :id)
content_view_id = params[:content_view_id]
environment_id = params.dig(:environment, :id) || params[:environment_id]
content_view_id = params.dig(:content_view, :id) || params[:content_view_id]
if environment_id.blank? || content_view_id.blank?
fail HttpErrors::BadRequest, _("Environment ID and content view ID must be provided together")
end
Expand Down
9 changes: 8 additions & 1 deletion app/models/katello/activation_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def single_lifecycle_environment
end

# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def assign_single_environment(
content_view_id: nil, lifecycle_environment_id: nil, environment_id: nil,
content_view: nil, lifecycle_environment: nil, environment: nil
Expand All @@ -159,8 +160,14 @@ def assign_single_environment(
end
fail _("Unable to create ContentViewEnvironment. Check the logs for more information.") if content_view_environment.nil?

self.content_view_environments = [content_view_environment]
if self.content_view_environments.include?(content_view_environment)
Rails.logger.info("Activation key '#{name}' already has the content view environment '#{content_view_environment.content_view_name}' and environment '#{content_view_environment.environment&.name}'.")
else
self.content_view_environments = [content_view_environment]
end
end
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity

def usage_count
subscription_facet_activation_keys.count
Expand Down
5 changes: 5 additions & 0 deletions app/views/katello/api/v2/activation_keys/base.json.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ extends 'katello/api/v2/common/timestamps'

attributes :id, :name, :description, :unlimited_hosts, :auto_attach

node :multi_content_view_environment do |ak|
ak.multi_content_view_environment?
end

# single cv/lce for backward compatibility
node :content_view_id do |ak|
ak.single_content_view&.id
end
Expand Down
4 changes: 4 additions & 0 deletions app/views/katello/api/v2/content_facet/base.json.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ child :content_view_environments => :content_view_environments do
end
end

node :multi_content_view_environment do |content_facet|
content_facet.multi_content_view_environment?
end

# single cv/lce for backward compatibility
node :content_view do |content_facet|
content_view = content_facet.single_content_view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
</span>
</div>

<div bst-alert="warning" ng-if="activationKey.multi_content_view_environment">
<span translate>
This activation key has multiple content view environments, which are not yet displayed in the web UI. Changing the content view or lifecycle environment here will overwrite the activation key's multiple environments. To avoid this, update the activation key via Hammer.</a>
</span>
</div>

<div data-extend-template="layouts/two-column-details.html">
<div data-block="left-column">
<h4 translate>Basic Information</h4>
Expand Down

0 comments on commit 359cd1f

Please sign in to comment.