gitlab-org--gitlab-foss/lib/gitlab/auth/omniauth_identity_linker_base.rb
gfyoung e166e5747c Enable some frozen string in lib/gitlab
Enable frozen string for the following files:

* lib/gitlab/auth/**/*.rb
* lib/gitlab/badge/**/*.rb
* lib/gitlab/bare_repository_import/**/*.rb
* lib/gitlab/bitbucket_import/**/*.rb
* lib/gitlab/bitbucket_server_import/**/*.rb
* lib/gitlab/cache/**/*.rb
* lib/gitlab/checks/**/*.rb

Partially addresses #47424.
2018-10-13 02:31:31 -07:00

55 lines
1 KiB
Ruby

# frozen_string_literal: true
module Gitlab
module Auth
class OmniauthIdentityLinkerBase
attr_reader :current_user, :oauth
def initialize(current_user, oauth)
@current_user = current_user
@oauth = oauth
@changed = false
end
def link
save if identity.new_record?
end
def changed?
@changed
end
def failed?
error_message.present?
end
def error_message
identity.validate
identity.errors.full_messages.join(', ')
end
private
def save
@changed = identity.save
end
# rubocop: disable CodeReuse/ActiveRecord
def identity
@identity ||= current_user.identities
.with_extern_uid(provider, uid)
.first_or_initialize(extern_uid: uid)
end
# rubocop: enable CodeReuse/ActiveRecord
def provider
oauth['provider']
end
def uid
oauth['uid']
end
end
end
end