gitlab-org--gitlab-foss/app/models/user_synced_attributes_meta...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

34 lines
727 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class UserSyncedAttributesMetadata < ApplicationRecord
2017-08-29 08:57:41 +00:00
belongs_to :user
validates :user, presence: true
SYNCABLE_ATTRIBUTES = %i[name email location].freeze
def read_only?(attribute)
sync_profile_from_provider? && synced?(attribute)
2017-08-29 08:57:41 +00:00
end
def read_only_attributes
return [] unless sync_profile_from_provider?
2017-08-29 08:57:41 +00: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
private
def sync_profile_from_provider?
Gitlab::Auth::OAuth::Provider.sync_profile_from_provider?(provider)
end
2017-08-29 08:57:41 +00:00
end