Issue #83 - Project limit
This commit is contained in:
parent
9840102651
commit
67f0c62d07
13 changed files with 45 additions and 9 deletions
|
@ -25,6 +25,8 @@ class Project < ActiveRecord::Base
|
|||
:uniqueness => true,
|
||||
:length => { :within => 3..12 }
|
||||
|
||||
validate :check_limit
|
||||
|
||||
before_save :format_code
|
||||
after_destroy :destroy_gitosis_project
|
||||
after_save :update_gitosis_project
|
||||
|
@ -126,6 +128,12 @@ class Project < ActiveRecord::Base
|
|||
path ? (tree / path) : tree
|
||||
end
|
||||
|
||||
def check_limit
|
||||
unless owner.can_create_project?
|
||||
errors[:base] << ("You can to have #{owner.projects_limit} your own projects")
|
||||
end
|
||||
end
|
||||
|
||||
def valid_repo?
|
||||
repo
|
||||
rescue
|
||||
|
|
|
@ -5,7 +5,7 @@ class User < ActiveRecord::Base
|
|||
:recoverable, :rememberable, :trackable, :validatable
|
||||
|
||||
# Setup accessible (or protected) attributes for your model
|
||||
attr_accessible :email, :password, :password_confirmation, :remember_me, :name
|
||||
attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :projects_limit
|
||||
|
||||
has_many :users_projects, :dependent => :destroy
|
||||
has_many :projects, :through => :users_projects
|
||||
|
@ -29,6 +29,10 @@ class User < ActiveRecord::Base
|
|||
def is_admin?
|
||||
admin
|
||||
end
|
||||
|
||||
def can_create_project?
|
||||
projects_limit >= my_own_projects.count
|
||||
end
|
||||
end
|
||||
# == Schema Information
|
||||
#
|
||||
|
@ -49,6 +53,6 @@ end
|
|||
# updated_at :datetime
|
||||
# name :string(255)
|
||||
# admin :boolean default(FALSE), not null
|
||||
# allowed_create_repo :boolean default(TRUE), not null
|
||||
# projects_limit :integer
|
||||
#
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue