Commit 22279bc55870435c61d5e8208cc3117ef2268052
1 parent
3e115faa
Exists in
master
and in
4 other branches
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.
Showing
9 changed files
with
62 additions
and
7 deletions
Show diff stats
app/controllers/admin/users_controller.rb
... | ... | @@ -29,7 +29,7 @@ class Admin::UsersController < Admin::ApplicationController |
29 | 29 | |
30 | 30 | |
31 | 31 | def new |
32 | - @admin_user = User.new({ projects_limit: Gitlab.config.gitlab.default_projects_limit }, as: :admin) | |
32 | + @admin_user = User.new.with_defaults | |
33 | 33 | end |
34 | 34 | |
35 | 35 | def edit | ... | ... |
app/controllers/registrations_controller.rb
... | ... | @@ -16,8 +16,7 @@ class RegistrationsController < Devise::RegistrationsController |
16 | 16 | |
17 | 17 | def build_resource(hash=nil) |
18 | 18 | super |
19 | - self.resource.projects_limit = Gitlab.config.gitlab.default_projects_limit | |
20 | - self.resource | |
19 | + self.resource.with_defaults | |
21 | 20 | end |
22 | 21 | |
23 | 22 | private | ... | ... |
app/models/user.rb
... | ... | @@ -196,6 +196,14 @@ class User < ActiveRecord::Base |
196 | 196 | username |
197 | 197 | end |
198 | 198 | |
199 | + def with_defaults | |
200 | + tap do |u| | |
201 | + u.projects_limit = Gitlab.config.gitlab.default_projects_limit | |
202 | + u.can_create_group = Gitlab.config.gitlab.default_can_create_group | |
203 | + u.can_create_team = Gitlab.config.gitlab.default_can_create_team | |
204 | + end | |
205 | + end | |
206 | + | |
199 | 207 | def notification |
200 | 208 | @notification ||= Notification.new(self) |
201 | 209 | end | ... | ... |
config/gitlab.yml.example
... | ... | @@ -34,7 +34,9 @@ production: &base |
34 | 34 | |
35 | 35 | ## Project settings |
36 | 36 | default_projects_limit: 10 |
37 | - # signup_enabled: true # default: false - Account passwords are not sent via the email if signup is enabled. | |
37 | + # default_can_create_group: false # default: true | |
38 | + # default_can_create_team: false # default: true | |
39 | + # signup_enabled: true # default: false - Account passwords are not sent via the email if signup is enabled. | |
38 | 40 | # username_changing_enabled: false # default: true - User can change her username/namespace |
39 | 41 | |
40 | 42 | ## Default project features settings | ... | ... |
config/initializers/1_settings.rb
... | ... | @@ -48,7 +48,9 @@ Settings['issues_tracker'] ||= {} |
48 | 48 | # GitLab |
49 | 49 | # |
50 | 50 | Settings['gitlab'] ||= Settingslogic.new({}) |
51 | -Settings.gitlab['default_projects_limit'] ||= 10 | |
51 | +Settings.gitlab['default_projects_limit'] ||= 10 | |
52 | +Settings.gitlab['default_can_create_group'] = true if Settings.gitlab['default_can_create_group'].nil? | |
53 | +Settings.gitlab['default_can_create_team'] = true if Settings.gitlab['default_can_create_team'].nil? | |
52 | 54 | Settings.gitlab['host'] ||= 'localhost' |
53 | 55 | Settings.gitlab['https'] = false if Settings.gitlab['https'].nil? |
54 | 56 | Settings.gitlab['port'] ||= Settings.gitlab.https ? 443 : 80 |
... | ... | @@ -111,3 +113,12 @@ Settings.satellites['path'] = File.expand_path(Settings.satellites['path'] || "t |
111 | 113 | # Extra customization |
112 | 114 | # |
113 | 115 | Settings['extra'] ||= Settingslogic.new({}) |
116 | + | |
117 | +# | |
118 | +# Testing settings | |
119 | +# | |
120 | +if Rails.env.test? | |
121 | + Settings.gitlab['default_projects_limit'] = 42 | |
122 | + Settings.gitlab['default_can_create_group'] = false | |
123 | + Settings.gitlab['default_can_create_team'] = false | |
124 | +end | ... | ... |
lib/gitlab/auth.rb
... | ... | @@ -39,8 +39,7 @@ module Gitlab |
39 | 39 | email: email, |
40 | 40 | password: password, |
41 | 41 | password_confirmation: password, |
42 | - projects_limit: Gitlab.config.gitlab.default_projects_limit, | |
43 | - }, as: :admin) | |
42 | + }, as: :admin).with_defaults | |
44 | 43 | @user.save! |
45 | 44 | |
46 | 45 | if Gitlab.config.omniauth['block_auto_created_users'] && !ldap | ... | ... |
spec/features/admin/admin_users_spec.rb
... | ... | @@ -33,6 +33,14 @@ describe "Admin::Users" do |
33 | 33 | expect { click_button "Create user" }.to change {User.count}.by(1) |
34 | 34 | end |
35 | 35 | |
36 | + it "should apply defaults to user" do | |
37 | + click_button "Create user" | |
38 | + user = User.last | |
39 | + user.projects_limit.should == Gitlab.config.gitlab.default_projects_limit | |
40 | + user.can_create_group.should == Gitlab.config.gitlab.default_can_create_group | |
41 | + user.can_create_team.should == Gitlab.config.gitlab.default_can_create_team | |
42 | + end | |
43 | + | |
36 | 44 | it "should create user with valid data" do |
37 | 45 | click_button "Create user" |
38 | 46 | user = User.last | ... | ... |
spec/lib/auth_spec.rb
... | ... | @@ -91,5 +91,15 @@ describe Gitlab::Auth do |
91 | 91 | user.extern_uid.should == @info.uid |
92 | 92 | user.provider.should == 'twitter' |
93 | 93 | end |
94 | + | |
95 | + it "should apply defaults to user" do | |
96 | + @auth = mock(info: @info, provider: 'ldap') | |
97 | + user = gl_auth.create_from_omniauth(@auth, true) | |
98 | + | |
99 | + user.should be_valid | |
100 | + user.projects_limit.should == Gitlab.config.gitlab.default_projects_limit | |
101 | + user.can_create_group.should == Gitlab.config.gitlab.default_can_create_group | |
102 | + user.can_create_team.should == Gitlab.config.gitlab.default_can_create_team | |
103 | + end | |
94 | 104 | end |
95 | 105 | end | ... | ... |
spec/models/user_spec.rb
... | ... | @@ -178,4 +178,22 @@ describe User do |
178 | 178 | it { user.can_create_project?.should be_true } |
179 | 179 | it { user.first_name.should == 'John' } |
180 | 180 | end |
181 | + | |
182 | + describe 'without defaults' do | |
183 | + let(:user) { User.new } | |
184 | + it "should not apply defaults to user" do | |
185 | + user.projects_limit.should == 10 | |
186 | + user.can_create_group.should == true | |
187 | + user.can_create_team.should == true | |
188 | + end | |
189 | + end | |
190 | + | |
191 | + describe 'with defaults' do | |
192 | + let(:user) { User.new.with_defaults } | |
193 | + it "should apply defaults to user" do | |
194 | + user.projects_limit.should == 42 | |
195 | + user.can_create_group.should == false | |
196 | + user.can_create_team.should == false | |
197 | + end | |
198 | + end | |
181 | 199 | end | ... | ... |