Commit 24cd7a5c authored by James Edwards-Jones's avatar James Edwards-Jones

Auth::User classes refactor adds should_save?

parent a69977e7
...@@ -32,15 +32,11 @@ module Gitlab ...@@ -32,15 +32,11 @@ module Gitlab
self.class.find_by_uid_and_provider(auth_hash.uid, auth_hash.provider) self.class.find_by_uid_and_provider(auth_hash.uid, auth_hash.provider)
end end
def changed? override :should_save?
def should_save?
gl_user.changed? || gl_user.identities.any?(&:changed?) gl_user.changed? || gl_user.identities.any?(&:changed?)
end end
override :omniauth_should_save?
def omniauth_should_save?
changed? && super
end
def block_after_signup? def block_after_signup?
ldap_config.block_auto_created_users ldap_config.block_auto_created_users
end end
......
...@@ -71,14 +71,14 @@ module Gitlab ...@@ -71,14 +71,14 @@ module Gitlab
end end
def find_and_update! def find_and_update!
save if omniauth_should_save? save if should_save?
gl_user gl_user
end end
protected protected
def omniauth_should_save? def should_save?
true true
end end
......
...@@ -36,17 +36,13 @@ module Gitlab ...@@ -36,17 +36,13 @@ module Gitlab
user user
end end
def changed? override :should_save?
def should_save?
return true unless gl_user return true unless gl_user
gl_user.changed? || gl_user.identities.any?(&:changed?) gl_user.changed? || gl_user.identities.any?(&:changed?)
end end
override :omniauth_should_save?
def omniauth_should_save?
changed? && super
end
protected protected
def saml_config def saml_config
......
...@@ -27,20 +27,20 @@ describe Gitlab::Auth::LDAP::User do ...@@ -27,20 +27,20 @@ describe Gitlab::Auth::LDAP::User do
OmniAuth::AuthHash.new(uid: 'uid=John Smith,ou=People,dc=example,dc=com', provider: 'ldapmain', info: info_upper_case) OmniAuth::AuthHash.new(uid: 'uid=John Smith,ou=People,dc=example,dc=com', provider: 'ldapmain', info: info_upper_case)
end end
describe '#changed?' do describe '#should_save?' do
it "marks existing ldap user as changed" do it "marks existing ldap user as changed" do
create(:omniauth_user, extern_uid: 'uid=John Smith,ou=People,dc=example,dc=com', provider: 'ldapmain') create(:omniauth_user, extern_uid: 'uid=John Smith,ou=People,dc=example,dc=com', provider: 'ldapmain')
expect(ldap_user.changed?).to be_truthy expect(ldap_user.should_save?).to be_truthy
end end
it "marks existing non-ldap user if the email matches as changed" do it "marks existing non-ldap user if the email matches as changed" do
create(:user, email: 'john@example.com') create(:user, email: 'john@example.com')
expect(ldap_user.changed?).to be_truthy expect(ldap_user.should_save?).to be_truthy
end end
it "does not mark existing ldap user as changed" do it "does not mark existing ldap user as changed" do
create(:omniauth_user, email: 'john@example.com', extern_uid: 'uid=john smith,ou=people,dc=example,dc=com', provider: 'ldapmain') create(:omniauth_user, email: 'john@example.com', extern_uid: 'uid=john smith,ou=people,dc=example,dc=com', provider: 'ldapmain')
expect(ldap_user.changed?).to be_falsey expect(ldap_user.should_save?).to be_falsey
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