width:400px;
}
}
+
+#user_projects_limit{
+ width: 60px;
+}
end
def new
- @admin_user = User.new
+ @admin_user = User.new(:projects_limit => 10)
respond_to do |format|
format.html # new.html.erb
:uniqueness => true,
:length => { :within => 3..12 }
+ validate :check_limit
+
before_save :format_code
after_destroy :destroy_gitosis_project
after_save :update_gitosis_project
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
: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
def is_admin?
admin
end
+
+ def can_create_project?
+ projects_limit >= my_own_projects.count
+ end
end
# == Schema Information
#
# updated_at :datetime
# name :string(255)
# admin :boolean default(FALSE), not null
-# allowed_create_repo :boolean default(TRUE), not null
+# projects_limit :integer
#
= 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
%p
%b Admin:
= @admin_user.admin
+ %p
+ %b Projects limit:
+ = @admin_user.projects_limit
.clear
= link_to 'Edit', edit_admin_user_path(@admin_user)
-= 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
:password_confirmation => "5iveL!fe"
)
+admin.projects_limit = 10000
admin.admin = true
admin.save!
:password_confirmation => "5iveL!fe"
)
+admin.projects_limit = 10000
admin.admin = true
admin.save!
--- /dev/null
+class AddProjectsLimitToUser < ActiveRecord::Migration
+ def change
+ add_column :users, :projects_limit, :integer, :default => 10
+ end
+end
--- /dev/null
+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
#
# 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"
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
# updated_at :datetime
# name :string(255)
# admin :boolean default(FALSE), not null
-# allowed_create_repo :boolean default(TRUE), not null
+# projects_limit :integer
#