diff --git a/app/models/group.rb b/app/models/group.rb index 864acc69a..e602a3fe8 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -1,4 +1,5 @@ class Group < ActiveRecord::Base + MAX_OWN_PROJECTS = 32000 belongs_to :owner, :class_name => 'User' has_many :own_projects, :as => :owner, :class_name => 'Project' @@ -15,6 +16,7 @@ class Group < ActiveRecord::Base validates :name, :owner, :presence => true validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => { :with => /^[a-z0-9_]+$/ } validate { errors.add(:uname, :taken) if User.where('uname LIKE ?', uname).present? } + validate { errors.add(:own_projects_count, :less_than_or_equal_to, :count => MAX_OWN_PROJECTS) if own_projects.size >= MAX_OWN_PROJECTS } attr_readonly :uname, :own_projects_count diff --git a/app/models/project.rb b/app/models/project.rb index 33593181b..7616d21f1 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -2,7 +2,7 @@ class Project < ActiveRecord::Base VISIBILITIES = ['open', 'hidden'] belongs_to :category, :counter_cache => true - belongs_to :owner, :polymorphic => true, :counter_cache => :own_projects_count + belongs_to :owner, :polymorphic => true, :validate => true, :counter_cache => :own_projects_count has_many :issues, :dependent => :destroy has_many :build_lists, :dependent => :destroy diff --git a/app/models/user.rb b/app/models/user.rb index affe00818..c344de77a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,5 @@ class User < ActiveRecord::Base + MAX_OWN_PROJECTS = 32000 ROLES = ['admin'] devise :database_authenticatable, :registerable, :omniauthable, # :token_authenticatable, :encryptable, :timeoutable @@ -25,6 +26,7 @@ class User < ActiveRecord::Base validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => { :with => /^[a-z0-9_]+$/ } validate { errors.add(:uname, :taken) if Group.where('uname LIKE ?', uname).present? } validates :ssh_key, :uniqueness => true, :allow_blank => true + validate { errors.add(:own_projects_count, :less_than_or_equal_to, :count => MAX_OWN_PROJECTS) if own_projects.size >= MAX_OWN_PROJECTS } validates :role, :inclusion => {:in => ROLES}, :allow_blank => true attr_accessible :email, :password, :password_confirmation, :remember_me, :login, :name, :ssh_key, :uname diff --git a/db/migrate/20111221120208_add_has_wiki_to_projects.rb b/db/migrate/20111221120208_add_has_wiki_to_projects.rb index 19a2f27f1..8e411afd1 100644 --- a/db/migrate/20111221120208_add_has_wiki_to_projects.rb +++ b/db/migrate/20111221120208_add_has_wiki_to_projects.rb @@ -1,6 +1,6 @@ class AddHasWikiToProjects < ActiveRecord::Migration def self.up - add_column :projects, :has_wiki, :boolean + add_column :projects, :has_wiki, :boolean, :default => false end def self.down