Skip to content

Commit

Permalink
Merge pull request #22917 from jrafanie/removing_a_tag_will_only_remo…
Browse files Browse the repository at this point in the history
…ve_it_from_entitlement_filters_in_the_same_region

Remove tags from entitlement filters from the deleted tag's region
  • Loading branch information
Fryguy authored Feb 27, 2024
2 parents b646694 + 04b4de4 commit 407bf80
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def self.controlled_by_mapping
private

def remove_from_managed_filters
Entitlement.remove_tag_from_all_managed_filters(name)
Entitlement.with_region(self.class.id_to_region(id)) { Entitlement.remove_tag_from_all_managed_filters(name) }
end

def name_path
Expand Down
19 changes: 19 additions & 0 deletions spec/models/tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,24 @@
MiqGroup.all.each { |group| expect(group.get_managed_filters).to match_array(expected_filters) }
expect(Tag.all).to be_empty
end

it "removing a tag will only remove it from entitlement filters in the tag's region" do
tag
other_region = ApplicationRecord.my_region_number + 1
other_region_tag = FactoryBot.create(:tag, :name => "/managed/my_name/test", :id => ApplicationRecord.id_in_region(1, other_region))
other_region_miq_group = FactoryBot.create(:miq_group, :entitlement => Entitlement.create!, :id => ApplicationRecord.id_in_region(1, other_region))
other_region_miq_group.entitlement.set_managed_filters(filters)
other_region_miq_group.save

other_region_tag.destroy

# tag and filters from other region are deleted and updated
Tag.in_region(other_region) { expect(Tag.all).to be_empty }
MiqGroup.in_region(other_region) { MiqGroup.all.each { |group| expect(group.get_managed_filters).to be_empty } }

# current region tag/filters are not changed
expect(Tag.pluck(:id)).to eq([tag.id])
MiqGroup.all.each { |group| expect(group.get_managed_filters).to match_array(filters) }
end
end
end

0 comments on commit 407bf80

Please sign in to comment.