Class: Gitlab::Saml::User

Inherits:
OAuth::User show all
Defined in:
lib/gitlab/saml/user.rb

Instance Attribute Summary

Attributes inherited from OAuth::User

#auth_hash

Instance Method Summary collapse

Methods inherited from OAuth::User

#initialize, #new?, #persisted?, #valid?

Constructor Details

This class inherits a constructor from Gitlab::OAuth::User

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)

50
51
52
53
# File 'lib/gitlab/saml/user.rb', line 50

def changed?
  return true unless gl_user
  gl_user.changed? || gl_user.identities.any?(&:changed?)
end

#find_by_emailObject


42
43
44
45
46
47
48
# File 'lib/gitlab/saml/user.rb', line 42

def find_by_email
  if auth_hash.has_email?
    user = ::User.find_by(email: auth_hash.email.downcase)
    user.identities.new(extern_uid: auth_hash.uid, provider: auth_hash.provider) if user
    user
  end
end

#gl_userObject


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gitlab/saml/user.rb', line 14

def gl_user
  @user ||= find_by_uid_and_provider

  if auto_link_ldap_user?
    @user ||= find_or_create_ldap_user
  end

  if auto_link_saml_user?
    @user ||= find_by_email
  end

  if 
    @user ||= build_new_user
  end

  if external_users_enabled? && @user
    # Check if there is overlap between the user's groups and the external groups
    # setting then set user as external or internal.
    if (auth_hash.groups & Gitlab::Saml::Config.external_groups).empty?
      @user.external = false
    else
      @user.external = true
    end
  end

  @user
end

#saveObject


10
11
12
# File 'lib/gitlab/saml/user.rb', line 10

def save
  super('SAML')
end