Skip to content

Commit

Permalink
Fix deletion of Default Container Image Rate
Browse files Browse the repository at this point in the history
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1486658

Fix deletion of Default Container Image Rate in Cloud Intel -> Chargeback
-> Rates so that the Rate can't be deleted and error message is displayed.
  • Loading branch information
Hilda Stastna committed Jan 10, 2018
1 parent 36a0514 commit d547bed
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/controllers/chargeback_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def cb_rates_delete
self.x_node = "xx-#{cb_rate.rate_type}"
end
end
process_cb_rates(rates, 'destroy') unless rates.empty?
process_cb_rates(rates, 'destroy') if !rates.empty? && cb_rates_default(rates)
if flash_errors?
javascript_flash
else
Expand All @@ -226,6 +226,18 @@ def cb_rates_delete
end
end

# Check for Default Rates which shouldn't be deleted
def cb_rates_default(rates)
rates.each do |rate_id|
cb_rate = ChargebackRate.find(rate_id)
if cb_rate.default? || cb_rate.description == 'Default Container Image Rate'
add_flash(_("Default Chargeback Rate cannot be removed."), :error)
return false
end
end
true
end

# AJAX driven routine to check for changes in ANY field on the form
def cb_assign_field_changed
return unless load_edit("cbassign_edit__#{x_node}", "replace_cell__chargeback")
Expand Down

0 comments on commit d547bed

Please sign in to comment.