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
| @@ -21,7 +21,7 @@ class Admin::UsersController < ApplicationController | @@ -21,7 +21,7 @@ class Admin::UsersController < ApplicationController | ||
| 21 | end | 21 | end |
| 22 | 22 | ||
| 23 | def new | 23 | def new |
| 24 | - @admin_user = User.new | 24 | + @admin_user = User.new(:projects_limit => 10) |
| 25 | 25 | ||
| 26 | respond_to do |format| | 26 | respond_to do |format| |
| 27 | format.html # new.html.erb | 27 | format.html # new.html.erb |
app/models/project.rb
| @@ -25,6 +25,8 @@ class Project < ActiveRecord::Base | @@ -25,6 +25,8 @@ class Project < ActiveRecord::Base | ||
| 25 | :uniqueness => true, | 25 | :uniqueness => true, |
| 26 | :length => { :within => 3..12 } | 26 | :length => { :within => 3..12 } |
| 27 | 27 | ||
| 28 | + validate :check_limit | ||
| 29 | + | ||
| 28 | before_save :format_code | 30 | before_save :format_code |
| 29 | after_destroy :destroy_gitosis_project | 31 | after_destroy :destroy_gitosis_project |
| 30 | after_save :update_gitosis_project | 32 | after_save :update_gitosis_project |
| @@ -126,6 +128,12 @@ class Project < ActiveRecord::Base | @@ -126,6 +128,12 @@ class Project < ActiveRecord::Base | ||
| 126 | path ? (tree / path) : tree | 128 | path ? (tree / path) : tree |
| 127 | end | 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 | def valid_repo? | 137 | def valid_repo? |
| 130 | repo | 138 | repo |
| 131 | rescue | 139 | rescue |
app/models/user.rb
| @@ -5,7 +5,7 @@ class User < ActiveRecord::Base | @@ -5,7 +5,7 @@ class User < ActiveRecord::Base | ||
| 5 | :recoverable, :rememberable, :trackable, :validatable | 5 | :recoverable, :rememberable, :trackable, :validatable |
| 6 | 6 | ||
| 7 | # Setup accessible (or protected) attributes for your model | 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 | has_many :users_projects, :dependent => :destroy | 10 | has_many :users_projects, :dependent => :destroy |
| 11 | has_many :projects, :through => :users_projects | 11 | has_many :projects, :through => :users_projects |
| @@ -29,6 +29,10 @@ class User < ActiveRecord::Base | @@ -29,6 +29,10 @@ class User < ActiveRecord::Base | ||
| 29 | def is_admin? | 29 | def is_admin? |
| 30 | admin | 30 | admin |
| 31 | end | 31 | end |
| 32 | + | ||
| 33 | + def can_create_project? | ||
| 34 | + projects_limit >= my_own_projects.count | ||
| 35 | + end | ||
| 32 | end | 36 | end |
| 33 | # == Schema Information | 37 | # == Schema Information |
| 34 | # | 38 | # |
| @@ -49,6 +53,6 @@ end | @@ -49,6 +53,6 @@ end | ||
| 49 | # updated_at :datetime | 53 | # updated_at :datetime |
| 50 | # name :string(255) | 54 | # name :string(255) |
| 51 | # admin :boolean default(FALSE), not null | 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,8 +30,8 @@ | ||
| 30 | = f.check_box :admin | 30 | = f.check_box :admin |
| 31 | = f.label :admin | 31 | = f.label :admin |
| 32 | .field.prepend-top | 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 | .clear | 35 | .clear |
| 36 | %br | 36 | %br |
| 37 | .actions | 37 | .actions |
app/views/admin/users/show.html.haml
| @@ -10,6 +10,9 @@ | @@ -10,6 +10,9 @@ | ||
| 10 | %p | 10 | %p |
| 11 | %b Admin: | 11 | %b Admin: |
| 12 | = @admin_user.admin | 12 | = @admin_user.admin |
| 13 | + %p | ||
| 14 | + %b Projects limit: | ||
| 15 | + = @admin_user.projects_limit | ||
| 13 | 16 | ||
| 14 | .clear | 17 | .clear |
| 15 | = link_to 'Edit', edit_admin_user_path(@admin_user) | 18 | = link_to 'Edit', edit_admin_user_path(@admin_user) |
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,7 +11,7 @@ | ||
| 11 | # | 11 | # |
| 12 | # It's strongly recommended to check this file into your version control system. | 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 | create_table "issues", :force => true do |t| | 16 | create_table "issues", :force => true do |t| |
| 17 | t.string "title" | 17 | t.string "title" |
| @@ -70,7 +70,7 @@ ActiveRecord::Schema.define(:version => 20111009101738) do | @@ -70,7 +70,7 @@ ActiveRecord::Schema.define(:version => 20111009101738) do | ||
| 70 | t.datetime "updated_at" | 70 | t.datetime "updated_at" |
| 71 | t.string "name" | 71 | t.string "name" |
| 72 | t.boolean "admin", :default => false, :null => false | 72 | t.boolean "admin", :default => false, :null => false |
| 73 | - t.boolean "allowed_create_repo", :default => true, :null => false | 73 | + t.integer "projects_limit" |
| 74 | end | 74 | end |
| 75 | 75 | ||
| 76 | add_index "users", ["email"], :name => "index_users_on_email", :unique => true | 76 | add_index "users", ["email"], :name => "index_users_on_email", :unique => true |
spec/models/user_spec.rb
| @@ -38,6 +38,6 @@ end | @@ -38,6 +38,6 @@ end | ||
| 38 | # updated_at :datetime | 38 | # updated_at :datetime |
| 39 | # name :string(255) | 39 | # name :string(255) |
| 40 | # admin :boolean default(FALSE), not null | 40 | # admin :boolean default(FALSE), not null |
| 41 | -# allowed_create_repo :boolean default(TRUE), not null | 41 | +# projects_limit :integer |
| 42 | # | 42 | # |
| 43 | 43 |