Commit 634a1527 authored by Douwe Maan's avatar Douwe Maan

Make sure group and project creation is blocked for new users that are external by default

parent 97b80fef
...@@ -164,7 +164,7 @@ class User < ActiveRecord::Base ...@@ -164,7 +164,7 @@ class User < ActiveRecord::Base
before_validation :set_notification_email, if: :email_changed? before_validation :set_notification_email, if: :email_changed?
before_validation :set_public_email, if: :public_email_changed? before_validation :set_public_email, if: :public_email_changed?
before_save :ensure_incoming_email_token before_save :ensure_incoming_email_token
before_save :ensure_user_rights_and_limits, if: :external_changed? before_save :ensure_user_rights_and_limits, if: ->(user) { user.new_record? || user.external_changed? }
before_save :skip_reconfirmation!, if: ->(user) { user.email_changed? && user.read_only_attribute?(:email) } before_save :skip_reconfirmation!, if: ->(user) { user.email_changed? && user.read_only_attribute?(:email) }
before_save :check_for_verified_email, if: ->(user) { user.email_changed? && !user.new_record? } before_save :check_for_verified_email, if: ->(user) { user.email_changed? && !user.new_record? }
after_save :ensure_namespace_correct after_save :ensure_namespace_correct
...@@ -1139,8 +1139,9 @@ class User < ActiveRecord::Base ...@@ -1139,8 +1139,9 @@ class User < ActiveRecord::Base
self.can_create_group = false self.can_create_group = false
self.projects_limit = 0 self.projects_limit = 0
else else
self.can_create_group = gitlab_config.default_can_create_group # Only revert these back to the default if they weren't specifically changed in this update.
self.projects_limit = current_application_settings.default_projects_limit self.can_create_group = gitlab_config.default_can_create_group unless can_create_group_changed?
self.projects_limit = current_application_settings.default_projects_limit unless projects_limit_changed?
end end
end end
......
---
title: Make sure group and project creation is blocked for new users that are external
by default
merge_request:
author:
type: fixed
...@@ -788,14 +788,16 @@ describe User do ...@@ -788,14 +788,16 @@ describe User do
end end
it "creates external user by default" do it "creates external user by default" do
user = build(:user) user = create(:user)
expect(user.external).to be_truthy expect(user.external).to be_truthy
expect(user.can_create_group).to be_falsey
expect(user.projects_limit).to be 0
end end
describe 'with default overrides' do describe 'with default overrides' do
it "creates a non-external user" do it "creates a non-external user" do
user = build(:user, external: false) user = create(:user, external: false)
expect(user.external).to be_falsey expect(user.external).to be_falsey
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