Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Edwards-Jones <jedwardsjones@gitlab.com>2018-04-23 13:56:44 +0300
committerJames Edwards-Jones <jedwardsjones@gitlab.com>2018-04-23 15:53:32 +0300
commitd3a8a07423dccf1709b6432e017ae4679143dbce (patch)
tree0555fa8871e274eee93d38cd7bbbd79a5718142d /lib/gitlab/auth
parentf8d54913bb6f846d1204704d3a6e457956461b35 (diff)
Unify Saml::IdentityLinker and OAuth::IdentityLinker
Diffstat (limited to 'lib/gitlab/auth')
-rw-r--r--lib/gitlab/auth/o_auth/identity_linker.rb19
-rw-r--r--lib/gitlab/auth/omniauth_identity_linker_base.rb34
-rw-r--r--lib/gitlab/auth/saml/identity_linker.rb19
3 files changed, 28 insertions, 44 deletions
diff --git a/lib/gitlab/auth/o_auth/identity_linker.rb b/lib/gitlab/auth/o_auth/identity_linker.rb
index 704a7e1b3c2..de92d7a214d 100644
--- a/lib/gitlab/auth/o_auth/identity_linker.rb
+++ b/lib/gitlab/auth/o_auth/identity_linker.rb
@@ -2,25 +2,6 @@ module Gitlab
module Auth
module OAuth
class IdentityLinker < OmniauthIdentityLinkerBase
- def create_or_update
- if identity.new_record?
- @created = identity.save
- end
- end
-
- def error_message
- identity.validate
-
- identity.errors.full_messages.join(', ')
- end
-
- private
-
- def identity
- @identity ||= current_user.identities
- .with_extern_uid(oauth['provider'], oauth['uid'])
- .first_or_initialize(extern_uid: oauth['uid'])
- end
end
end
end
diff --git a/lib/gitlab/auth/omniauth_identity_linker_base.rb b/lib/gitlab/auth/omniauth_identity_linker_base.rb
index 4ed28d6a8be..ae365fcdfaa 100644
--- a/lib/gitlab/auth/omniauth_identity_linker_base.rb
+++ b/lib/gitlab/auth/omniauth_identity_linker_base.rb
@@ -6,19 +6,41 @@ module Gitlab
def initialize(current_user, oauth)
@current_user = current_user
@oauth = oauth
- @created = false
+ @changed = false
end
- def created?
- @created
+ def link
+ save if identity.new_record?
+ end
+
+ def changed?
+ @changed
end
def error_message
- ''
+ identity.validate
+
+ identity.errors.full_messages.join(', ')
+ end
+
+ private
+
+ def save
+ @changed = identity.save
+ end
+
+ def identity
+ @identity ||= current_user.identities
+ .with_extern_uid(provider, uid)
+ .first_or_initialize(extern_uid: uid)
+ end
+
+ def provider
+ oauth['provider']
end
- def create_or_update
- raise NotImplementedError
+ def uid
+ oauth['uid']
end
end
end
diff --git a/lib/gitlab/auth/saml/identity_linker.rb b/lib/gitlab/auth/saml/identity_linker.rb
index d5f97f01df3..7e4b191d512 100644
--- a/lib/gitlab/auth/saml/identity_linker.rb
+++ b/lib/gitlab/auth/saml/identity_linker.rb
@@ -2,25 +2,6 @@ module Gitlab
module Auth
module Saml
class IdentityLinker < OmniauthIdentityLinkerBase
- def create_or_update
- if find_saml_identity.nil?
- create_saml_identity
-
- @created = true
- else
- @created = false
- end
- end
-
- protected
-
- def find_saml_identity
- current_user.identities.with_extern_uid(:saml, oauth['uid']).take
- end
-
- def create_saml_identity
- current_user.identities.create(extern_uid: oauth['uid'], provider: :saml)
- end
end
end
end