Created
February 26, 2015 20:51
-
-
Save chulkilee/5e9b160a88546721e86f to your computer and use it in GitHub Desktop.
Update old LDAP provider name on gitlab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts Identity.unscoped.group(:provider).count | |
users = User.includes(:identities).all | |
duplicated_providers = %w(ldap ldapmain).sort | |
old_provider = 'ldap' | |
new_provider = 'ldapmain' | |
users.each do |u| | |
next if u.identities.blank? | |
if u.identities.length == 1 | |
id = u.identities.first | |
id.update_columns(provider: new_provider) if id.provider == old_provider | |
else | |
next if u.identities.map(&:extern_uid).uniq.length != 1 | |
if u.identities.map(&:provider).sort == duplicated_providers | |
u.identities.where(provider: old_provider).delete_all | |
end | |
end | |
end | |
puts Identity.unscoped.group(:provider).count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment