Fixed issue #506 - OTRS Migration fails for user <-> role import.

This commit is contained in:
Thorsten Eckel 2016-12-06 13:19:56 +01:00
parent 1ae3aaadb5
commit f517efaf16
2 changed files with 14 additions and 14 deletions

View file

@ -122,23 +122,23 @@ module Import
local_roles.uniq local_roles.uniq
end end
def groups_from_otrs_groups(user) def groups_from_otrs_groups(role_object)
groups = Import::OTRS::Requester.load('Group') groups = Import::OTRS::Requester.load('Group')
groups_from_groups(user, groups) groups_from_groups(role_object, groups)
end end
def groups_from_groups(user, groups) def groups_from_groups(role_object, groups)
result = [] result = []
groups.each { |group| groups.each { |group|
result += groups_from_otrs_group(user, group) result += groups_from_otrs_group(role_object, group)
} }
result result
end end
def groups_from_otrs_group(user, group) def groups_from_otrs_group(role_object, group)
result = [] result = []
return result if user['GroupIDs'].empty? return result if role_object['GroupIDs'].empty?
permissions = user['GroupIDs'][ group['ID'] ] permissions = role_object['GroupIDs'][ group['ID'] ]
return result if !permissions return result if !permissions
@ -158,7 +158,7 @@ module Import
roles = Import::OTRS::Requester.load('Role') roles = Import::OTRS::Requester.load('Role')
roles.each { |role| roles.each { |role|
next if !user['RoleIDs'].include?(role['ID']) next if !user['RoleIDs'].include?(role['ID'])
result += groups_from_groups(user, role['GroupIDs']) result += groups_from_otrs_groups(role['GroupIDs'])
} }
result result
end end

View file

@ -41,7 +41,7 @@ RSpec.describe Import::OTRS::User do
'GroupID' => '2', '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 = [ group_list = [
{ {
@ -50,13 +50,13 @@ RSpec.describe Import::OTRS::User do
}, },
{ {
'ID' => '3', '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) }] role_list = [{ 'ID' => '3', 'GroupIDs' => { '2' => ['rw'], '3' => ['rw'] } }]
expect(Import::OTRS::Requester).to receive(:load).with('Role').and_return(role_list) allow(Import::OTRS::Requester).to receive(:load).with('Role').and_return(role_list)
end end
let(:import_object) { ::User } let(:import_object) { ::User }
@ -72,7 +72,7 @@ RSpec.describe Import::OTRS::User do
updated_by_id: 1, updated_by_id: 1,
active: true, active: true,
source: 'OTRS Import', source: 'OTRS Import',
role_ids: [2], role_ids: [2, 1],
group_ids: ['1'], group_ids: ['1'],
password: '{sha2}9faaba2ab242a99bbb6992e9424386375f6757c17e6484ae570f39d9cad9f28ea', password: '{sha2}9faaba2ab242a99bbb6992e9424386375f6757c17e6484ae570f39d9cad9f28ea',
updated_at: '2014-04-28 10:53:18', updated_at: '2014-04-28 10:53:18',