From b9e573db5707a8921699a3035d73d5b621cbcdcd Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Wed, 26 Apr 2017 14:13:04 -0500 Subject: [PATCH] Skip validation when creating internal (ghost, service desk) users --- app/models/user.rb | 4 +++- changelogs/unreleased/dm-fix-ghost-user-validation.yml | 4 ++++ spec/models/user_spec.rb | 10 ++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/dm-fix-ghost-user-validation.yml diff --git a/app/models/user.rb b/app/models/user.rb index 774d4caa806..bd9c9f99663 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1068,11 +1068,13 @@ class User < ActiveRecord::Base User.find_by_email(s) end - scope.create( + user = scope.build( username: username, email: email, &creation_block ) + user.save(validate: false) + user ensure Gitlab::ExclusiveLease.cancel(lease_key, uuid) end diff --git a/changelogs/unreleased/dm-fix-ghost-user-validation.yml b/changelogs/unreleased/dm-fix-ghost-user-validation.yml new file mode 100644 index 00000000000..4214786cb5a --- /dev/null +++ b/changelogs/unreleased/dm-fix-ghost-user-validation.yml @@ -0,0 +1,4 @@ +--- +title: Skip validation when creating internal (ghost, service desk) users +merge_request: +author: diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 0a2860f2505..0bcebc27598 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1556,6 +1556,16 @@ describe User, models: true do expect(ghost.email).to eq('ghost1@example.com') end end + + context 'when a domain whitelist is in place' do + before do + stub_application_setting(domain_whitelist: ['gitlab.com']) + end + + it 'creates a ghost user' do + expect(User.ghost).to be_persisted + end + end end describe '#update_two_factor_requirement' do