Class: UserSyncedAttributesMetadata

Inherits:
MainClusterwide::ApplicationRecord show all
Defined in:
app/models/user_synced_attributes_metadata.rb

Constant Summary collapse

SYNCABLE_ATTRIBUTES =
%i[name email location].freeze

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.ldap_provider?(provider) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'app/models/user_synced_attributes_metadata.rb', line 44

def ldap_provider?(provider)
  Gitlab::Auth::OAuth::Provider.ldap_provider?(provider)
end

.ldap_sync_name?(provider) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
# File 'app/models/user_synced_attributes_metadata.rb', line 48

def ldap_sync_name?(provider)
  return false unless provider

  config = Gitlab::Auth::Ldap::Config.new(provider)
  config.enabled? && config.sync_name
end

.syncable_attributes(provider = nil) ⇒ Object



29
30
31
32
33
34
# File 'app/models/user_synced_attributes_metadata.rb', line 29

def syncable_attributes(provider = nil)
  return SYNCABLE_ATTRIBUTES unless provider && ldap_provider?(provider)
  return SYNCABLE_ATTRIBUTES if ldap_sync_name?(provider)

  SYNCABLE_ATTRIBUTES - %i[name]
end

Instance Method Details

#read_only?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'app/models/user_synced_attributes_metadata.rb', line 10

def read_only?(attribute)
  sync_profile_from_provider? && synced?(attribute)
end

#read_only_attributesObject



14
15
16
17
18
# File 'app/models/user_synced_attributes_metadata.rb', line 14

def read_only_attributes
  return [] unless sync_profile_from_provider?

  SYNCABLE_ATTRIBUTES.select { |key| synced?(key) }
end

#set_attribute_synced(attribute, value) ⇒ Object



24
25
26
# File 'app/models/user_synced_attributes_metadata.rb', line 24

def set_attribute_synced(attribute, value)
  write_attribute("#{attribute}_synced", value)
end

#synced?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'app/models/user_synced_attributes_metadata.rb', line 20

def synced?(attribute)
  read_attribute("#{attribute}_synced")
end