Commit 4caaea82 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'dmedvinsky-add-defaults-create-group-team'

parents 01d8c7d6 ec105507
...@@ -29,7 +29,7 @@ class Admin::UsersController < Admin::ApplicationController ...@@ -29,7 +29,7 @@ class Admin::UsersController < Admin::ApplicationController
def new def new
@admin_user = User.new({ projects_limit: Gitlab.config.gitlab.default_projects_limit }, as: :admin) @admin_user = User.new.with_defaults
end end
def edit def edit
......
...@@ -16,8 +16,7 @@ class RegistrationsController < Devise::RegistrationsController ...@@ -16,8 +16,7 @@ class RegistrationsController < Devise::RegistrationsController
def build_resource(hash=nil) def build_resource(hash=nil)
super super
self.resource.projects_limit = Gitlab.config.gitlab.default_projects_limit self.resource.with_defaults
self.resource
end end
private private
......
...@@ -196,6 +196,14 @@ class User < ActiveRecord::Base ...@@ -196,6 +196,14 @@ class User < ActiveRecord::Base
username username
end 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 def notification
@notification ||= Notification.new(self) @notification ||= Notification.new(self)
end end
......
...@@ -32,12 +32,14 @@ production: &base ...@@ -32,12 +32,14 @@ production: &base
# Email address of your support contact (default: same as email_from) # Email address of your support contact (default: same as email_from)
support_email: support@localhost support_email: support@localhost
## Project settings ## User settings
default_projects_limit: 10 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 ## Users management
# signup_enabled: true # default: false - Account passwords are not sent via the email if signup is enabled. # 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 project features settings
default_projects_features: default_projects_features:
......
...@@ -48,7 +48,9 @@ Settings['issues_tracker'] ||= {} ...@@ -48,7 +48,9 @@ Settings['issues_tracker'] ||= {}
# GitLab # GitLab
# #
Settings['gitlab'] ||= Settingslogic.new({}) Settings['gitlab'] ||= Settingslogic.new({})
Settings.gitlab['default_projects_limit'] ||= 10 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['host'] ||= 'localhost'
Settings.gitlab['https'] = false if Settings.gitlab['https'].nil? Settings.gitlab['https'] = false if Settings.gitlab['https'].nil?
Settings.gitlab['port'] ||= Settings.gitlab.https ? 443 : 80 Settings.gitlab['port'] ||= Settings.gitlab.https ? 443 : 80
...@@ -111,3 +113,12 @@ Settings.satellites['path'] = File.expand_path(Settings.satellites['path'] || "t ...@@ -111,3 +113,12 @@ Settings.satellites['path'] = File.expand_path(Settings.satellites['path'] || "t
# Extra customization # Extra customization
# #
Settings['extra'] ||= Settingslogic.new({}) 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
...@@ -39,8 +39,7 @@ module Gitlab ...@@ -39,8 +39,7 @@ module Gitlab
email: email, email: email,
password: password, password: password,
password_confirmation: password, password_confirmation: password,
projects_limit: Gitlab.config.gitlab.default_projects_limit, }, as: :admin).with_defaults
}, as: :admin)
@user.save! @user.save!
if Gitlab.config.omniauth['block_auto_created_users'] && !ldap if Gitlab.config.omniauth['block_auto_created_users'] && !ldap
......
...@@ -33,6 +33,14 @@ describe "Admin::Users" do ...@@ -33,6 +33,14 @@ describe "Admin::Users" do
expect { click_button "Create user" }.to change {User.count}.by(1) expect { click_button "Create user" }.to change {User.count}.by(1)
end 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 it "should create user with valid data" do
click_button "Create user" click_button "Create user"
user = User.last user = User.last
......
...@@ -91,5 +91,15 @@ describe Gitlab::Auth do ...@@ -91,5 +91,15 @@ describe Gitlab::Auth do
user.extern_uid.should == @info.uid user.extern_uid.should == @info.uid
user.provider.should == 'twitter' user.provider.should == 'twitter'
end 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
end end
...@@ -178,4 +178,22 @@ describe User do ...@@ -178,4 +178,22 @@ describe User do
it { user.can_create_project?.should be_true } it { user.can_create_project?.should be_true }
it { user.first_name.should == 'John' } it { user.first_name.should == 'John' }
end 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 end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment