summaryrefslogtreecommitdiff
path: root/app/models/user_synced_attributes_metadata.rb
diff options
context:
space:
mode:
authorAlexander Keramidas <dev.alexkeramidas@gmail.com>2017-08-29 11:57:41 +0300
committerAlexander Keramidas <dev.alexkeramidas@gmail.com>2017-09-06 16:38:52 +0300
commit4df54f260751a832ebf0b8c18524020d6604994b (patch)
tree2337fd9cc3fe1a1c82d9cc980dcce22465e493ce /app/models/user_synced_attributes_metadata.rb
parent021fb512e3c3f4b317307358dee8eecf448599b0 (diff)
downloadgitlab-ce-4df54f260751a832ebf0b8c18524020d6604994b.tar.gz
Profile updates from providers
Diffstat (limited to 'app/models/user_synced_attributes_metadata.rb')
-rw-r--r--app/models/user_synced_attributes_metadata.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/app/models/user_synced_attributes_metadata.rb b/app/models/user_synced_attributes_metadata.rb
new file mode 100644
index 00000000000..9f374304164
--- /dev/null
+++ b/app/models/user_synced_attributes_metadata.rb
@@ -0,0 +1,25 @@
+class UserSyncedAttributesMetadata < ActiveRecord::Base
+ belongs_to :user
+
+ validates :user, presence: true
+
+ SYNCABLE_ATTRIBUTES = %i[name email location].freeze
+
+ def read_only?(attribute)
+ Gitlab.config.omniauth.sync_profile_from_provider && synced?(attribute)
+ end
+
+ def read_only_attributes
+ return [] unless Gitlab.config.omniauth.sync_profile_from_provider
+
+ 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
+end