Browse Source

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

Thorsten Eckel 8 years ago
parent
commit
f517efaf16
2 changed files with 14 additions and 14 deletions
  1. 8 8
      lib/import/otrs/user.rb
  2. 6 6
      spec/import/otrs/user_spec.rb

+ 8 - 8
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

+ 6 - 6
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',