diff --git a/app/models/classification.rb b/app/models/classification.rb index f30cb4449535..ef3f811ef1ed 100644 --- a/app/models/classification.rb +++ b/app/models/classification.rb @@ -10,13 +10,14 @@ class Classification < ApplicationRecord before_destroy :delete_tags_and_entries validates :description, :presence => true, :length => {:maximum => 255} - validates :description, :uniqueness => {:scope => [:parent_id]}, :if => proc { |c| - cond = ["parent_id = ? AND description = ?", c.parent_id, c.description] - unless c.new_record? - cond.first << " AND id != ?" - cond << c.id - end - c.class.in_region(region_id).exists?(cond) + validates :description, :uniqueness => { :scope => %i(parent_id tag_id) }, :if => proc { |c| + relation = c.class.in_region(region_id).where( + :tag_id => c.tag_id, + :parent_id => c.parent_id, + :description => c.description, + ) + relation = relation.where.not(:id => c.id) unless c.new_record? + relation.exists? } NAME_MAX_LENGTH = 50 diff --git a/app/models/container_label_tag_mapping.rb b/app/models/container_label_tag_mapping.rb index 6408ba2c425c..00c47e26a70a 100644 --- a/app/models/container_label_tag_mapping.rb +++ b/app/models/container_label_tag_mapping.rb @@ -23,7 +23,7 @@ class ContainerLabelTagMapping < ApplicationRecord require_nested :Mapper - TAG_PREFIXES = ['/managed/amazon:', '/managed/kubernetes:'].freeze + TAG_PREFIXES = %w(amazon azure kubernetes).map { |name| "/managed/#{name}:" }.freeze validate :validate_tag_prefix # Return ContainerLabelTagMapping::Mapper instance that holds all current mappings, diff --git a/app/models/container_label_tag_mapping/mapper.rb b/app/models/container_label_tag_mapping/mapper.rb index d8eb21f629b1..15b79979d1e6 100644 --- a/app/models/container_label_tag_mapping/mapper.rb +++ b/app/models/container_label_tag_mapping/mapper.rb @@ -60,6 +60,7 @@ def self.references_to_tags(tag_references) private def map_label(type, label) + type = 'VmAzure' if type == 'Vm' && label[:source] == 'azure' # Apply both specific-type and any-type, independently. (map_name_type_value(label[:name], type, label[:value]) + map_name_type_value(label[:name], nil, label[:value]))