Skip to content

Commit

Permalink
702052 - db fields length limit review
Browse files Browse the repository at this point in the history
  • Loading branch information
lzap committed Nov 2, 2011
1 parent e8514e7 commit 082afe1
Show file tree
Hide file tree
Showing 17 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/app/models/activation_key.rb
Expand Up @@ -28,7 +28,7 @@ class ActivationKey < ActiveRecord::Base
scoped_search :on => :description, :complete_value => true, :rename => :'key.description'
scoped_search :in => :environment, :on => :name, :complete_value => true, :rename => :'environment.name'

validates :name, :presence => true, :katello_name_format => true
validates :name, :presence => true, :katello_name_format => true, :length => { :maximum => 255 }
validates_uniqueness_of :name, :scope => :organization_id
validates :description, :katello_description_format => true
validates :environment, :presence => true
Expand Down
3 changes: 2 additions & 1 deletion src/app/models/changeset.rb
Expand Up @@ -32,9 +32,10 @@ class Changeset < ActiveRecord::Base
:allow_blank => false,
:message => "A changeset must have one of the following states: #{STATES.join(', ')}."

validates :name, :presence => true, :allow_blank => false
validates :name, :presence => true, :allow_blank => false, :length => { :maximum => 255 }
validates_uniqueness_of :name, :scope => :environment_id, :message => N_("Must be unique within an environment")
validates :environment, :presence=>true
validates :description, :katello_description_format => true
validates_with NotInLockerValidator
has_and_belongs_to_many :products, :uniq => true
has_many :packages, :class_name=>"ChangesetPackage", :inverse_of=>:changeset
Expand Down
1 change: 1 addition & 0 deletions src/app/models/changeset_dependency.rb
Expand Up @@ -17,6 +17,7 @@ class ChangesetDependency < ActiveRecord::Base
belongs_to :changeset, :inverse_of=>:dependencies
belongs_to :product

validates :display_name, :length => { :maximum => 255 }

# returns list of virtual permission tags for the current user
def self.list_tags
Expand Down
1 change: 1 addition & 0 deletions src/app/models/changeset_erratum.rb
Expand Up @@ -43,6 +43,7 @@ class ChangesetErratum < ActiveRecord::Base

belongs_to :changeset, :inverse_of=>:errata
belongs_to :product
validates :display_name, :length => { :maximum => 255 }
validates_with ChangesetErratumValidator

# returns list of virtual permission tags for the current user
Expand Down
1 change: 1 addition & 0 deletions src/app/models/changeset_package.rb
Expand Up @@ -42,6 +42,7 @@ class ChangesetPackage < ActiveRecord::Base

belongs_to :changeset, :inverse_of=>:packages
belongs_to :product
validates :display_name, :length => { :maximum => 255 }
validates_with ChangesetPackageValidator

# returns list of virtual permission tags for the current user
Expand Down
1 change: 1 addition & 0 deletions src/app/models/changeset_repo.rb
Expand Up @@ -33,6 +33,7 @@ class ChangesetRepo < ActiveRecord::Base

belongs_to :changeset, :inverse_of=>:repos
belongs_to :product
validates :display_name, :length => { :maximum => 255 }
validates_with ChangesetRepoValidator

end
1 change: 1 addition & 0 deletions src/app/models/help_tip.rb
Expand Up @@ -12,4 +12,5 @@

class HelpTip < ActiveRecord::Base
belongs_to :user
validates :key, :length => { :maximum => 255 }
end
3 changes: 3 additions & 0 deletions src/app/models/notice.rb
Expand Up @@ -20,7 +20,10 @@ class Notice < ActiveRecord::Base

validates_inclusion_of :level, :in => TYPES + TYPES.collect{|type| type.to_s}
validates_presence_of :text
validates_length_of :text, :maximum => 1024
validates_length_of :user_notices, :minimum => 1
validates_length_of :level, :maximum => 255
validates_length_of :request_type, :maximum => 255

before_validation :set_default_notice_level
before_save :add_to_all_users
Expand Down
1 change: 1 addition & 0 deletions src/app/models/permission.rb
Expand Up @@ -20,6 +20,7 @@ class Permission < ActiveRecord::Base
before_save :cleanup_tags_verbs

validates :name, :presence => true, :katello_name_format => true
validates :description, :katello_description_format => true
validates_uniqueness_of :name, :scope => [:organization_id, :role_id], :message => N_("must be unique within an organization scope")


Expand Down
1 change: 1 addition & 0 deletions src/app/models/provider.rb
Expand Up @@ -71,6 +71,7 @@ def constraint_redhat_update
end

def valid_url
errors.add(:repository_url, _("is too long")) if self.repository_url.length > 255
errors.add(:repository_url, _("is invalid")) unless kurl_valid?(self.repository_url)
end

Expand Down
1 change: 1 addition & 0 deletions src/app/models/resource_type.rb
Expand Up @@ -45,6 +45,7 @@ def message

class ResourceType < ActiveRecord::Base
belongs_to :permission
validates :name, :length => { :maximum => 255 }

def display_name
ResourceType::TYPES[name][:name]
Expand Down
2 changes: 2 additions & 0 deletions src/app/models/search_favorite.rb
Expand Up @@ -15,6 +15,8 @@ class SearchFavorite < ActiveRecord::Base

belongs_to :user
validate :max_favorites
validates :params, :length => { :maximum => 255 }
validates :path, :length => { :maximum => 255 }

def max_favorites
if new_record?
Expand Down
2 changes: 2 additions & 0 deletions src/app/models/search_history.rb
Expand Up @@ -12,4 +12,6 @@
#
class SearchHistory < ActiveRecord::Base
belongs_to :user
validates :params, :length => { :maximum => 255 }
validates :path, :length => { :maximum => 255 }
end
1 change: 1 addition & 0 deletions src/app/models/system.rb
Expand Up @@ -36,6 +36,7 @@ class System < ActiveRecord::Base
validates :environment, :presence => true, :non_locker_environment => true
validates :name, :presence => true, :no_trailing_space => true, :uniqueness => true
validates :description, :katello_description_format => true
validates_length_of :location, :maximum => 255
before_create :fill_defaults

scope :by_env, lambda { |env| where('environment_id = ?', env) unless env.nil?}
Expand Down
3 changes: 3 additions & 0 deletions src/app/models/system_template.rb
Expand Up @@ -35,7 +35,10 @@ class SystemTemplate < ActiveRecord::Base

validates_presence_of :name
validates_uniqueness_of :name, :scope => :environment_id
validates_length_of :name, :maximum => 255
validates_with ParentTemplateValidator
validates_length_of :description, :maximum => 255
validates_length_of :parameters_json, :maximum => 255

belongs_to :parent, :class_name => "SystemTemplate"
has_and_belongs_to_many :products, :uniq => true
Expand Down
2 changes: 1 addition & 1 deletion src/app/models/user.rb
Expand Up @@ -30,7 +30,7 @@ class User < ActiveRecord::Base
has_many :search_histories, :dependent => :destroy


validates :username, :uniqueness => true, :presence => true, :username => true
validates :username, :uniqueness => true, :presence => true, :username => true, :length => { :maximum => 255 }
validate :own_role_included_in_roles

# check if the role does not already exist for new username
Expand Down
1 change: 1 addition & 0 deletions src/app/models/verb.rb
Expand Up @@ -12,6 +12,7 @@

class Verb < ActiveRecord::Base
has_and_belongs_to_many :permission
validates_length_of :verb, :maximum => 255

# alias for verb attribute
def name
Expand Down

0 comments on commit 082afe1

Please sign in to comment.