Commit 22279bc5 authored by Dmitry Medvinsky's avatar Dmitry Medvinsky

Add settings for user permission defaults

“Can create groups” and “Can create teams” had hardcoded defaults to
`true`. Sometimes it is desirable to prohibit these for newly created
users by default.
parent 3e115faa
...@@ -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
......
...@@ -34,7 +34,9 @@ production: &base ...@@ -34,7 +34,9 @@ production: &base
## Project settings ## Project settings
default_projects_limit: 10 default_projects_limit: 10
# signup_enabled: true # default: false - Account passwords are not sent via the email if signup is enabled. # default_can_create_group: false # default: true
# default_can_create_team: false # default: true
# 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 # username_changing_enabled: false # default: true - User can change her username/namespace
## Default project features settings ## Default project features settings
......
...@@ -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