debian-mirror-gitlab/app/models/user_synced_attributes_metadata.rb

56 lines
1.3 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2019-07-07 11:18:12 +05:30
class UserSyncedAttributesMetadata < ApplicationRecord
2018-03-17 18:26:18 +05:30
belongs_to :user
validates :user, presence: true
SYNCABLE_ATTRIBUTES = %i[name email location].freeze
def read_only?(attribute)
sync_profile_from_provider? && synced?(attribute)
end
def read_only_attributes
return [] unless sync_profile_from_provider?
2023-05-27 22:25:52 +05:30
SYNCABLE_ATTRIBUTES.select { |key| synced?(key) }
2018-03-17 18:26:18 +05:30
end
def synced?(attribute)
read_attribute("#{attribute}_synced")
end
def set_attribute_synced(attribute, value)
write_attribute("#{attribute}_synced", value)
end
2023-04-23 21:23:45 +05:30
class << self
2023-05-27 22:25:52 +05:30
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]
2023-04-23 21:23:45 +05:30
end
end
2018-03-17 18:26:18 +05:30
private
def sync_profile_from_provider?
2018-03-27 19:54:05 +05:30
Gitlab::Auth::OAuth::Provider.sync_profile_from_provider?(provider)
2018-03-17 18:26:18 +05:30
end
2023-05-27 22:25:52 +05:30
class << self
def ldap_provider?(provider)
Gitlab::Auth::OAuth::Provider.ldap_provider?(provider)
end
def ldap_sync_name?(provider)
return false unless provider
config = Gitlab::Auth::Ldap::Config.new(provider)
config.enabled? && config.sync_name
end
end
2018-03-17 18:26:18 +05:30
end