diff --git a/lib/import/otrs/user.rb b/lib/import/otrs/user.rb index 2ff06d478..f32d05188 100644 --- a/lib/import/otrs/user.rb +++ b/lib/import/otrs/user.rb @@ -122,23 +122,23 @@ module Import local_roles.uniq end - def groups_from_otrs_groups(user) + def groups_from_otrs_groups(role_object) groups = Import::OTRS::Requester.load('Group') - groups_from_groups(user, groups) + groups_from_groups(role_object, groups) end - def groups_from_groups(user, groups) + def groups_from_groups(role_object, groups) result = [] groups.each { |group| - result += groups_from_otrs_group(user, group) + result += groups_from_otrs_group(role_object, group) } result end - def groups_from_otrs_group(user, group) + def groups_from_otrs_group(role_object, group) result = [] - return result if user['GroupIDs'].empty? - permissions = user['GroupIDs'][ group['ID'] ] + return result if role_object['GroupIDs'].empty? + permissions = role_object['GroupIDs'][ group['ID'] ] return result if !permissions @@ -158,7 +158,7 @@ module Import roles = Import::OTRS::Requester.load('Role') roles.each { |role| next if !user['RoleIDs'].include?(role['ID']) - result += groups_from_groups(user, role['GroupIDs']) + result += groups_from_otrs_groups(role['GroupIDs']) } result end diff --git a/spec/import/otrs/user_spec.rb b/spec/import/otrs/user_spec.rb index aa75c3e49..87fa7ee89 100644 --- a/spec/import/otrs/user_spec.rb +++ b/spec/import/otrs/user_spec.rb @@ -41,7 +41,7 @@ RSpec.describe Import::OTRS::User do 'GroupID' => '2', } ] - expect(Import::OTRS::Requester).to receive(:load).with('Queue').and_return(queue_list) + allow(Import::OTRS::Requester).to receive(:load).with('Queue').and_return(queue_list) group_list = [ { @@ -50,13 +50,13 @@ RSpec.describe Import::OTRS::User do }, { 'ID' => '3', - 'Name' => 'another_group', + 'Name' => 'admin', }, ] - expect(Import::OTRS::Requester).to receive(:load).with('Group').and_return(group_list) + allow(Import::OTRS::Requester).to receive(:load).with('Group').and_return(group_list) - role_list = [{ 'ID' => '3', 'GroupIDs' => %w(2 3) }] - expect(Import::OTRS::Requester).to receive(:load).with('Role').and_return(role_list) + role_list = [{ 'ID' => '3', 'GroupIDs' => { '2' => ['rw'], '3' => ['rw'] } }] + allow(Import::OTRS::Requester).to receive(:load).with('Role').and_return(role_list) end let(:import_object) { ::User } @@ -72,7 +72,7 @@ RSpec.describe Import::OTRS::User do updated_by_id: 1, active: true, source: 'OTRS Import', - role_ids: [2], + role_ids: [2, 1], group_ids: ['1'], password: '{sha2}9faaba2ab242a99bbb6992e9424386375f6757c17e6484ae570f39d9cad9f28ea', updated_at: '2014-04-28 10:53:18',