Commit 67f0c62d0737ceeeb1babc953fbab41438e8d4f2
1 parent
98401026
Exists in
master
and in
4 other branches
Issue #83 - Project limit
Showing
13 changed files
with
45 additions
and
9 deletions
Show diff stats
app/assets/stylesheets/projects.css.scss
app/controllers/admin/users_controller.rb
app/models/project.rb
| ... | ... | @@ -25,6 +25,8 @@ class Project < ActiveRecord::Base |
| 25 | 25 | :uniqueness => true, |
| 26 | 26 | :length => { :within => 3..12 } |
| 27 | 27 | |
| 28 | + validate :check_limit | |
| 29 | + | |
| 28 | 30 | before_save :format_code |
| 29 | 31 | after_destroy :destroy_gitosis_project |
| 30 | 32 | after_save :update_gitosis_project |
| ... | ... | @@ -126,6 +128,12 @@ class Project < ActiveRecord::Base |
| 126 | 128 | path ? (tree / path) : tree |
| 127 | 129 | end |
| 128 | 130 | |
| 131 | + def check_limit | |
| 132 | + unless owner.can_create_project? | |
| 133 | + errors[:base] << ("You can to have #{owner.projects_limit} your own projects") | |
| 134 | + end | |
| 135 | + end | |
| 136 | + | |
| 129 | 137 | def valid_repo? |
| 130 | 138 | repo |
| 131 | 139 | rescue | ... | ... |
app/models/user.rb
| ... | ... | @@ -5,7 +5,7 @@ class User < ActiveRecord::Base |
| 5 | 5 | :recoverable, :rememberable, :trackable, :validatable |
| 6 | 6 | |
| 7 | 7 | # Setup accessible (or protected) attributes for your model |
| 8 | - attr_accessible :email, :password, :password_confirmation, :remember_me, :name | |
| 8 | + attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :projects_limit | |
| 9 | 9 | |
| 10 | 10 | has_many :users_projects, :dependent => :destroy |
| 11 | 11 | has_many :projects, :through => :users_projects |
| ... | ... | @@ -29,6 +29,10 @@ class User < ActiveRecord::Base |
| 29 | 29 | def is_admin? |
| 30 | 30 | admin |
| 31 | 31 | end |
| 32 | + | |
| 33 | + def can_create_project? | |
| 34 | + projects_limit >= my_own_projects.count | |
| 35 | + end | |
| 32 | 36 | end |
| 33 | 37 | # == Schema Information |
| 34 | 38 | # |
| ... | ... | @@ -49,6 +53,6 @@ end |
| 49 | 53 | # updated_at :datetime |
| 50 | 54 | # name :string(255) |
| 51 | 55 | # admin :boolean default(FALSE), not null |
| 52 | -# allowed_create_repo :boolean default(TRUE), not null | |
| 56 | +# projects_limit :integer | |
| 53 | 57 | # |
| 54 | 58 | ... | ... |
app/views/admin/users/_form.html.haml
| ... | ... | @@ -30,8 +30,8 @@ |
| 30 | 30 | = f.check_box :admin |
| 31 | 31 | = f.label :admin |
| 32 | 32 | .field.prepend-top |
| 33 | - = f.check_box :allowed_create_repo, :disabled => true | |
| 34 | - = f.label :allowed_create_repo | |
| 33 | + = f.text_field :projects_limit, :class => "small_input" | |
| 34 | + = f.label :projects_limit | |
| 35 | 35 | .clear |
| 36 | 36 | %br |
| 37 | 37 | .actions | ... | ... |
app/views/admin/users/show.html.haml
app/views/projects/index.html.haml
db/fixtures/development/001_admin.rb
db/fixtures/production/001_admin.rb
db/migrate/20111009111204_remove_allow_create_repo_from_user.rb
0 → 100644
db/schema.rb
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | # |
| 12 | 12 | # It's strongly recommended to check this file into your version control system. |
| 13 | 13 | |
| 14 | -ActiveRecord::Schema.define(:version => 20111009101738) do | |
| 14 | +ActiveRecord::Schema.define(:version => 20111009111204) do | |
| 15 | 15 | |
| 16 | 16 | create_table "issues", :force => true do |t| |
| 17 | 17 | t.string "title" |
| ... | ... | @@ -70,7 +70,7 @@ ActiveRecord::Schema.define(:version => 20111009101738) do |
| 70 | 70 | t.datetime "updated_at" |
| 71 | 71 | t.string "name" |
| 72 | 72 | t.boolean "admin", :default => false, :null => false |
| 73 | - t.boolean "allowed_create_repo", :default => true, :null => false | |
| 73 | + t.integer "projects_limit" | |
| 74 | 74 | end |
| 75 | 75 | |
| 76 | 76 | add_index "users", ["email"], :name => "index_users_on_email", :unique => true | ... | ... |
spec/models/user_spec.rb