[issue #64] Changed own_projects validation.

This commit is contained in:
George Vinogradov 2012-01-27 04:16:07 +04:00
parent ba84d5f216
commit 2d1e36fb1a
4 changed files with 6 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -541,6 +541,10 @@ ru:
build_list: Сборочный лист
activerecord:
errors:
project:
can_have_less_or_equal: Нельзя иметь больше, чем %{count} проектов.
models:
category: Категория
repository: Репозиторий