diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 19:05:49 +0300 |
commit | 43a25d93ebdabea52f99b05e15b06250cd8f07d7 (patch) | |
tree | dceebdc68925362117480a5d672bcff122fb625b /app/models/user_synced_attributes_metadata.rb | |
parent | 20c84b99005abd1c82101dfeff264ac50d2df211 (diff) |
Add latest changes from gitlab-org/gitlab@16-0-stable-eev16.0.0-rc42
Diffstat (limited to 'app/models/user_synced_attributes_metadata.rb')
-rw-r--r-- | app/models/user_synced_attributes_metadata.rb | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/app/models/user_synced_attributes_metadata.rb b/app/models/user_synced_attributes_metadata.rb index 4cd0e3fb828..6b23bce6406 100644 --- a/app/models/user_synced_attributes_metadata.rb +++ b/app/models/user_synced_attributes_metadata.rb @@ -14,7 +14,7 @@ class UserSyncedAttributesMetadata < ApplicationRecord def read_only_attributes return [] unless sync_profile_from_provider? - self.class.syncable_attributes.select { |key| synced?(key) } + SYNCABLE_ATTRIBUTES.select { |key| synced?(key) } end def synced?(attribute) @@ -26,12 +26,11 @@ class UserSyncedAttributesMetadata < ApplicationRecord end class << self - def syncable_attributes - if Gitlab.config.ldap.enabled && !Gitlab.config.ldap.sync_name - SYNCABLE_ATTRIBUTES - %i[name] - else - SYNCABLE_ATTRIBUTES - end + 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 end @@ -40,4 +39,17 @@ class UserSyncedAttributesMetadata < ApplicationRecord def sync_profile_from_provider? Gitlab::Auth::OAuth::Provider.sync_profile_from_provider?(provider) end + + 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 end |