diff --git a/app/models/group.rb b/app/models/group.rb index e602a3fe8..864acc69a 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -1,5 +1,4 @@ class Group < ActiveRecord::Base - MAX_OWN_PROJECTS = 32000 belongs_to :owner, :class_name => 'User' has_many :own_projects, :as => :owner, :class_name => 'Project' @@ -16,7 +15,6 @@ 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 7616d21f1..5aaaa2f2f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,5 +1,6 @@ class Project < ActiveRecord::Base VISIBILITIES = ['open', 'hidden'] + MAX_OWN_PROJECTS = 32000 belongs_to :category, :counter_cache => true belongs_to :owner, :polymorphic => true, :validate => true, :counter_cache => :own_projects_count @@ -17,6 +18,7 @@ class Project < ActiveRecord::Base validates :name, :uniqueness => {:scope => [:owner_id, :owner_type]}, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-\+\.]+$/ } validates :owner, :presence => true + validate { errors[:base] << I18n.t('activerecord.errors.project.can_have_less_or_equal', :count => MAX_OWN_PROJECTS) if owner.projects.size >= MAX_OWN_PROJECTS } # validate {errors.add(:base, I18n.t('flash.project.save_warning_ssh_key')) if owner.ssh_key.blank?} #attr_accessible :category_id, :name, :description, :visibility diff --git a/app/models/user.rb b/app/models/user.rb index c344de77a..affe00818 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,4 @@ class User < ActiveRecord::Base - MAX_OWN_PROJECTS = 32000 ROLES = ['admin'] devise :database_authenticatable, :registerable, :omniauthable, # :token_authenticatable, :encryptable, :timeoutable @@ -26,7 +25,6 @@ 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/config/locales/ru.yml b/config/locales/ru.yml index b2873340b..49f0c3562 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -541,6 +541,10 @@ ru: build_list: Сборочный лист activerecord: + errors: + project: + can_have_less_or_equal: Нельзя иметь больше, чем %{count} проектов. + models: category: Категория repository: Репозиторий