summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValera Sizov <vsv2711@gmail.com>2011-10-09 11:15:01 -0700
committerValera Sizov <vsv2711@gmail.com>2011-10-09 11:15:01 -0700
commit8bb5e5b04aefbaba4042abf76f085f35f9f91157 (patch)
treefe1cb1e267375e0c24029bd3f22cc82447f11464
parent0cc6c7a33b132ca256936e30121e0284b99f1449 (diff)
downloadgitlab-ce-8bb5e5b04aefbaba4042abf76f085f35f9f91157.tar.gz
Issue #83 - Project limit
-rw-r--r--app/assets/stylesheets/projects.css.scss4
-rw-r--r--app/controllers/admin/users_controller.rb2
-rw-r--r--app/models/project.rb8
-rw-r--r--app/models/user.rb8
-rw-r--r--app/views/admin/users/_form.html.haml4
-rw-r--r--app/views/admin/users/show.html.haml3
-rw-r--r--app/views/projects/index.html.haml3
-rw-r--r--db/fixtures/development/001_admin.rb1
-rw-r--r--db/fixtures/production/001_admin.rb1
-rw-r--r--db/migrate/20111009110913_add_projects_limit_to_user.rb5
-rw-r--r--db/migrate/20111009111204_remove_allow_create_repo_from_user.rb9
-rw-r--r--db/schema.rb4
-rw-r--r--spec/models/user_spec.rb2
13 files changed, 45 insertions, 9 deletions
diff --git a/app/assets/stylesheets/projects.css.scss b/app/assets/stylesheets/projects.css.scss
index fcefac1664c..d3c4c48a24b 100644
--- a/app/assets/stylesheets/projects.css.scss
+++ b/app/assets/stylesheets/projects.css.scss
@@ -521,3 +521,7 @@ tbody tr:nth-child(2n) td, tbody tr.even td {
width:400px;
}
}
+
+#user_projects_limit{
+ width: 60px;
+}
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index 5190dd06a8d..e9ad1e55983 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -21,7 +21,7 @@ class Admin::UsersController < ApplicationController
end
def new
- @admin_user = User.new
+ @admin_user = User.new(:projects_limit => 10)
respond_to do |format|
format.html # new.html.erb
diff --git a/app/models/project.rb b/app/models/project.rb
index 48c288eb015..182c7844368 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -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
diff --git a/app/models/user.rb b/app/models/user.rb
index 1efaf31445e..104843a801e 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -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
#
diff --git a/app/views/admin/users/_form.html.haml b/app/views/admin/users/_form.html.haml
index a5e4d8ab4b3..17be416fa1d 100644
--- a/app/views/admin/users/_form.html.haml
+++ b/app/views/admin/users/_form.html.haml
@@ -30,8 +30,8 @@
= f.check_box :admin
= f.label :admin
.field.prepend-top
- = f.check_box :allowed_create_repo, :disabled => true
- = f.label :allowed_create_repo
+ = f.text_field :projects_limit, :class => "small_input"
+ = f.label :projects_limit
.clear
%br
.actions
diff --git a/app/views/admin/users/show.html.haml b/app/views/admin/users/show.html.haml
index f41fc51b8d0..b1d110bec27 100644
--- a/app/views/admin/users/show.html.haml
+++ b/app/views/admin/users/show.html.haml
@@ -10,6 +10,9 @@
%p
%b Admin:
= @admin_user.admin
+ %p
+ %b Projects limit:
+ = @admin_user.projects_limit
.clear
= link_to 'Edit', edit_admin_user_path(@admin_user)
diff --git a/app/views/projects/index.html.haml b/app/views/projects/index.html.haml
index 51717288e73..a33b4f57a82 100644
--- a/app/views/projects/index.html.haml
+++ b/app/views/projects/index.html.haml
@@ -1,4 +1,5 @@
-= link_to 'New Project', new_project_path, :class => "lbutton vm"
+- if current_user.can_create_project?
+ = link_to 'New Project', new_project_path, :class => "lbutton vm"
%table.round-borders#projects-list
%tr
diff --git a/db/fixtures/development/001_admin.rb b/db/fixtures/development/001_admin.rb
index 5020eccbca4..9c5a6da09e0 100644
--- a/db/fixtures/development/001_admin.rb
+++ b/db/fixtures/development/001_admin.rb
@@ -6,5 +6,6 @@ admin = User.create(
:password_confirmation => "5iveL!fe"
)
+admin.projects_limit = 10000
admin.admin = true
admin.save!
diff --git a/db/fixtures/production/001_admin.rb b/db/fixtures/production/001_admin.rb
index a50a693632b..94d1abe87ce 100644
--- a/db/fixtures/production/001_admin.rb
+++ b/db/fixtures/production/001_admin.rb
@@ -5,5 +5,6 @@ admin = User.create(
:password_confirmation => "5iveL!fe"
)
+admin.projects_limit = 10000
admin.admin = true
admin.save!
diff --git a/db/migrate/20111009110913_add_projects_limit_to_user.rb b/db/migrate/20111009110913_add_projects_limit_to_user.rb
new file mode 100644
index 00000000000..8eb8382b515
--- /dev/null
+++ b/db/migrate/20111009110913_add_projects_limit_to_user.rb
@@ -0,0 +1,5 @@
+class AddProjectsLimitToUser < ActiveRecord::Migration
+ def change
+ add_column :users, :projects_limit, :integer, :default => 10
+ end
+end
diff --git a/db/migrate/20111009111204_remove_allow_create_repo_from_user.rb b/db/migrate/20111009111204_remove_allow_create_repo_from_user.rb
new file mode 100644
index 00000000000..61452006397
--- /dev/null
+++ b/db/migrate/20111009111204_remove_allow_create_repo_from_user.rb
@@ -0,0 +1,9 @@
+class RemoveAllowCreateRepoFromUser < ActiveRecord::Migration
+ def up
+ remove_column :users, :allowed_create_repo
+ end
+
+ def down
+ add_column :users, :allowed_create_repo, :boolean, :default => true, :null => false
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index ad4b28875bc..ed5816ca329 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20111009101738) do
+ActiveRecord::Schema.define(:version => 20111009111204) do
create_table "issues", :force => true do |t|
t.string "title"
@@ -70,7 +70,7 @@ ActiveRecord::Schema.define(:version => 20111009101738) do
t.datetime "updated_at"
t.string "name"
t.boolean "admin", :default => false, :null => false
- t.boolean "allowed_create_repo", :default => true, :null => false
+ t.integer "projects_limit"
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 7a9e1fa6bc9..77abe2ca935 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -38,6 +38,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
#