2018-07-25 05:30:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-28 09:17:42 -04:00
|
|
|
class UserSyncedAttributesMetadata < ApplicationRecord
|
2017-08-29 04:57:41 -04:00
|
|
|
belongs_to :user
|
|
|
|
|
|
|
|
validates :user, presence: true
|
|
|
|
|
|
|
|
SYNCABLE_ATTRIBUTES = %i[name email location].freeze
|
|
|
|
|
|
|
|
def read_only?(attribute)
|
2017-12-13 12:02:49 -05:00
|
|
|
sync_profile_from_provider? && synced?(attribute)
|
2017-08-29 04:57:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def read_only_attributes
|
2017-12-13 12:02:49 -05:00
|
|
|
return [] unless sync_profile_from_provider?
|
2017-08-29 04:57:41 -04:00
|
|
|
|
|
|
|
SYNCABLE_ATTRIBUTES.select { |key| synced?(key) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def synced?(attribute)
|
|
|
|
read_attribute("#{attribute}_synced")
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_attribute_synced(attribute, value)
|
|
|
|
write_attribute("#{attribute}_synced", value)
|
|
|
|
end
|
2017-12-13 12:02:49 -05:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def sync_profile_from_provider?
|
2018-02-23 07:10:39 -05:00
|
|
|
Gitlab::Auth::OAuth::Provider.sync_profile_from_provider?(provider)
|
2017-12-13 12:02:49 -05:00
|
|
|
end
|
2017-08-29 04:57:41 -04:00
|
|
|
end
|