@@ -1606,14 +1606,19 @@ def whitelist_users(new_users, users_list, whitelist, mode = :exclude)
16061606 def import_users ( new_users , options = { } )
16071607 role_list = roles
16081608 users_list = users
1609- new_users = new_users . map { |x | ( ( x . is_a? ( Hash ) && x [ :user ] && x [ :user ] . to_hash . merge ( role : x [ :role ] ) ) || x . to_hash ) . tap { |u | u [ :login ] . downcase! } }
16101609
16111610 GoodData . logger . warn ( "Importing users to project (#{ pid } )" )
1611+ new_users = new_users . map { |x | ( ( x . is_a? ( Hash ) && x [ :user ] && x [ :user ] . to_hash . merge ( role : x [ :role ] ) ) || x . to_hash ) . tap { |u | u [ :login ] . downcase! } }
1612+ # First check that if groups are provided we have them set up
1613+ user_groups_cache , change_groups = check_groups ( new_users . map ( &:to_hash ) . flat_map { |u | u [ :user_group ] || [ ] } . uniq , options [ :user_groups_cache ] , options )
16121614
1613- whitelisted_new_users , whitelisted_users = whitelist_users ( new_users . map ( &:to_hash ) , users_list , options [ :whitelists ] )
1615+ unless change_groups . empty?
1616+ new_users . each do |user |
1617+ user [ :user_group ] . map! { |e | change_groups [ e ] . nil? ? e : change_groups [ e ] }
1618+ end
1619+ end
16141620
1615- # First check that if groups are provided we have them set up
1616- user_groups_cache = check_groups ( new_users . map ( &:to_hash ) . flat_map { |u | u [ :user_group ] || [ ] } . uniq , options [ :user_groups_cache ] , options )
1621+ whitelisted_new_users , whitelisted_users = whitelist_users ( new_users . map ( &:to_hash ) , users_list , options [ :whitelists ] )
16171622
16181623 # conform the role on list of new users so we can diff them with the users coming from the project
16191624 diffable_new_with_default_role = whitelisted_new_users . map do |u |
@@ -1760,7 +1765,20 @@ def remove_users(list)
17601765 def check_groups ( specified_groups , user_groups_cache = nil , options = { } )
17611766 current_user_groups = user_groups if user_groups_cache . nil? || user_groups_cache . empty?
17621767 groups = current_user_groups . map ( &:name )
1763- missing_groups = specified_groups - groups
1768+ missing_groups = [ ]
1769+ change_groups = { }
1770+ specified_groups . each do |group |
1771+ found_group = groups . find { |name | name . casecmp ( group ) . zero? }
1772+ if found_group . nil?
1773+ missing_groups << group
1774+ else
1775+ # Change groups when they have similar group name with difference of case sensitivity
1776+ if found_group != group
1777+ change_groups [ group ] = found_group
1778+ GoodData . logger . warn ( "Group with name #{ group } is existed in project with name #{ found_group } ." )
1779+ end
1780+ end
1781+ end
17641782 if options [ :create_non_existing_user_groups ]
17651783 missing_groups . each do |g |
17661784 GoodData . logger . info ( "Creating group #{ g } " )
@@ -1773,7 +1791,7 @@ def check_groups(specified_groups, user_groups_cache = nil, options = {})
17731791 "#{ groups . join ( ',' ) } and you asked for #{ missing_groups . join ( ',' ) } "
17741792 end
17751793 end
1776- current_user_groups
1794+ [ current_user_groups , change_groups ]
17771795 end
17781796
17791797 # Update user
0 commit comments