20170529132120_ldap_multi_group_mapping.rb 686 B

12345678910111213141516171819202122232425
  1. class LdapMultiGroupMapping < ActiveRecord::Migration[4.2]
  2. def up
  3. # return if it's a new setup
  4. return if !Setting.exists?(name: 'system_init_done')
  5. # load existing LDAP config
  6. ldap_config = Setting.get('ldap_config')
  7. # exit early if no config is present
  8. return if ldap_config.blank?
  9. return if ldap_config['group_role_map'].blank?
  10. # loop over group role mapping and check
  11. # if we need to migrate to new array structure
  12. ldap_config['group_role_map'].each do |source, dest|
  13. next if dest.is_a?(Array)
  14. ldap_config['group_role_map'][source] = [dest]
  15. end
  16. # store updated
  17. Setting.set('ldap_config', ldap_config)
  18. end
  19. end