Merge branch 'add-defaults-create-group-team' of https://github.com/dmedvinsky/gitlabhq into dmedvinsky-add-defaults-create-group-team

Conflicts:
	config/gitlab.yml.example
This commit is contained in:
Dmitriy Zaporozhets 2013-05-27 15:17:06 +03:00
commit ec1055076c
9 changed files with 63 additions and 8 deletions

View file

@ -29,7 +29,7 @@ class Admin::UsersController < Admin::ApplicationController
def new
@admin_user = User.new({ projects_limit: Gitlab.config.gitlab.default_projects_limit }, as: :admin)
@admin_user = User.new.with_defaults
end
def edit

View file

@ -16,8 +16,7 @@ class RegistrationsController < Devise::RegistrationsController
def build_resource(hash=nil)
super
self.resource.projects_limit = Gitlab.config.gitlab.default_projects_limit
self.resource
self.resource.with_defaults
end
private

View file

@ -196,6 +196,14 @@ class User < ActiveRecord::Base
username
end
def with_defaults
tap do |u|
u.projects_limit = Gitlab.config.gitlab.default_projects_limit
u.can_create_group = Gitlab.config.gitlab.default_can_create_group
u.can_create_team = Gitlab.config.gitlab.default_can_create_team
end
end
def notification
@notification ||= Notification.new(self)
end

View file

@ -32,12 +32,14 @@ production: &base
# Email address of your support contact (default: same as email_from)
support_email: support@localhost
## Project settings
## User settings
default_projects_limit: 10
# default_can_create_group: false # default: true
# default_can_create_team: false # default: true
# username_changing_enabled: false # default: true - User can change her username/namespace
## Users management
# signup_enabled: true # default: false - Account passwords are not sent via the email if signup is enabled.
# username_changing_enabled: false # default: true - User can change her username/namespace
## Default project features settings
default_projects_features:

View file

@ -49,6 +49,8 @@ Settings['issues_tracker'] ||= {}
#
Settings['gitlab'] ||= Settingslogic.new({})
Settings.gitlab['default_projects_limit'] ||= 10
Settings.gitlab['default_can_create_group'] = true if Settings.gitlab['default_can_create_group'].nil?
Settings.gitlab['default_can_create_team'] = true if Settings.gitlab['default_can_create_team'].nil?
Settings.gitlab['host'] ||= 'localhost'
Settings.gitlab['https'] = false if Settings.gitlab['https'].nil?
Settings.gitlab['port'] ||= Settings.gitlab.https ? 443 : 80
@ -111,3 +113,12 @@ Settings.satellites['path'] = File.expand_path(Settings.satellites['path'] || "t
# Extra customization
#
Settings['extra'] ||= Settingslogic.new({})
#
# Testing settings
#
if Rails.env.test?
Settings.gitlab['default_projects_limit'] = 42
Settings.gitlab['default_can_create_group'] = false
Settings.gitlab['default_can_create_team'] = false
end

View file

@ -39,8 +39,7 @@ module Gitlab
email: email,
password: password,
password_confirmation: password,
projects_limit: Gitlab.config.gitlab.default_projects_limit,
}, as: :admin)
}, as: :admin).with_defaults
@user.save!
if Gitlab.config.omniauth['block_auto_created_users'] && !ldap

View file

@ -33,6 +33,14 @@ describe "Admin::Users" do
expect { click_button "Create user" }.to change {User.count}.by(1)
end
it "should apply defaults to user" do
click_button "Create user"
user = User.last
user.projects_limit.should == Gitlab.config.gitlab.default_projects_limit
user.can_create_group.should == Gitlab.config.gitlab.default_can_create_group
user.can_create_team.should == Gitlab.config.gitlab.default_can_create_team
end
it "should create user with valid data" do
click_button "Create user"
user = User.last

View file

@ -91,5 +91,15 @@ describe Gitlab::Auth do
user.extern_uid.should == @info.uid
user.provider.should == 'twitter'
end
it "should apply defaults to user" do
@auth = mock(info: @info, provider: 'ldap')
user = gl_auth.create_from_omniauth(@auth, true)
user.should be_valid
user.projects_limit.should == Gitlab.config.gitlab.default_projects_limit
user.can_create_group.should == Gitlab.config.gitlab.default_can_create_group
user.can_create_team.should == Gitlab.config.gitlab.default_can_create_team
end
end
end

View file

@ -178,4 +178,22 @@ describe User do
it { user.can_create_project?.should be_true }
it { user.first_name.should == 'John' }
end
describe 'without defaults' do
let(:user) { User.new }
it "should not apply defaults to user" do
user.projects_limit.should == 10
user.can_create_group.should == true
user.can_create_team.should == true
end
end
describe 'with defaults' do
let(:user) { User.new.with_defaults }
it "should apply defaults to user" do
user.projects_limit.should == 42
user.can_create_group.should == false
user.can_create_team.should == false
end
end
end