trabajo-afectivo/db/migrate/20170529132120_ldap_multi_group_mapping.rb

25 lines
680 B
Ruby
Raw Normal View History

class LdapMultiGroupMapping < ActiveRecord::Migration
def up
# return if it's a new setup
return if !Setting.find_by(name: 'system_init_done')
# load existing LDAP config
ldap_config = Setting.get('ldap_config')
# exit early if no config is present
return if ldap_config.blank?
return if ldap_config['group_role_map'].blank?
# loop over group role mapping and check
# if we need to migrate to new array structure
ldap_config['group_role_map'].each do |source, dest|
next if dest.is_a?(Array)
ldap_config['group_role_map'][source] = [dest]
end
# store updated
Setting.set('ldap_config', ldap_config)
end
end