Skip to content

Commit

Permalink
Fixes #7038: No error when hostgroup name exceeds 245 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
orrabin committed Aug 20, 2014
1 parent 8fabe66 commit b3e9a64
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/models/hostgroup.rb
Expand Up @@ -13,6 +13,7 @@ class Hostgroup < ActiveRecord::Base
has_many :users, :through => :user_hostgroups
validates :name, :format => { :with => /\A(\S+\s?)+\Z/, :message => N_("can't contain trailing white spaces.")}
validates :root_pass, :allow_blank => true, :length => {:minimum => 8, :message => _('should be 8 characters or more')}
validate :title_and_lookup_key_length
has_many :group_parameters, :dependent => :destroy, :foreign_key => :reference_id
accepts_nested_attributes_for :group_parameters, :allow_destroy => true
has_many_hosts
Expand Down Expand Up @@ -171,4 +172,11 @@ def used_taxonomy_ids(type)
Host::Base.where(:hostgroup_id => self.path_ids).pluck(type).compact.uniq
end

def title_and_lookup_key_length
max_length_for_name = self.send(:obj_type).length + 1
max_length_for_name += parent.title.length unless parent.nil?

errors.add(:name, _("Maximum for this name is #{255 - max_length_for_name} characters")) if 255 - (name.length + max_length_for_name) < 0
end

end

0 comments on commit b3e9a64

Please sign in to comment.