Skip to content

Commit

Permalink
Merge pull request #19574 from himdel/bz1770300
Browse files Browse the repository at this point in the history
Dialog#destroy should ignore resource actions linking nonexisting entities

(cherry picked from commit 79a77cd)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1783382
  • Loading branch information
h-kataria authored and simaishi committed Dec 16, 2019
1 parent c884353 commit 613cfaa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/models/dialog.rb
Expand Up @@ -191,8 +191,12 @@ def dialog_field_hash
end

def reject_if_has_resource_actions
if resource_actions.length > 0
connected_components = resource_actions.collect { |ra| ra.resource_type.constantize.find(ra.resource_id) }
connected_components = resource_actions.collect do |ra|
# not find - we need nil when not found
ra.resource_type.constantize.find_by(:id => ra.resource_id)
end.compact

if connected_components.length > 0
errors.add(:base, _("Dialog cannot be deleted because it is connected to other components: %{components}") % {:components => connected_components.map { |cc| cc.class.name + ":" + cc.id.to_s + " - " + cc.try(:name) }})
throw :abort
end
Expand Down
10 changes: 10 additions & 0 deletions spec/models/dialog_spec.rb
Expand Up @@ -120,6 +120,16 @@
expect(err_msg).to eq("Dialog cannot be deleted because it is connected to other components: [\"Dialog:#{dialog.id} - #{dialog.name}\"]")
expect(Dialog.count).to eq(1)
end

it "does destroy dialog with only obsolete resource_action association" do
custom_button = FactoryBot.create(:custom_button, :applies_to_class => 'Vm')
FactoryBot.create(:resource_action, :action => nil, :dialog => dialog, :resource_type => 'CustomButton', :resource_id => custom_button.id)

custom_button.delete # deliberately not destroy, otherwise the ResourceAction gets removed too

expect(dialog.destroy).to be_truthy
expect(Dialog.count).to eq(0)
end
end

describe "dialog structures" do
Expand Down

0 comments on commit 613cfaa

Please sign in to comment.