Commits

Sorin Sbarnea committed 5f7fa57 Draft

Fixed rename/merge which was failing if the same username existed in more than one directory. This is a normal use case.

  • Participants
  • Parent commits 22d1153

Comments (0)

Files changed (1)

File src/main/resources/com/onresolve/jira/groovy/canned/admin/RenameUser443.groovy

             // Rename the user record itself
             if ((BuildUtils.getCurrentBuildNumber() as Long) < 614) {
                 List gvs = gd.findByAnd("OSUser", [name: sourceUser])
-                assert gvs.size() == 1
                 if (! preview) {
-                    GenericValue usergv = gvs.first() as GenericValue
-                    if (doMerge) {
-                        // todo: delete their associated property records
-                        usergv.remove()
-                    }
-                    else {
-                        usergv.set("name", targetUser)
-                        usergv.store()
+		    gvs.each { GenericValue usergv ->
+                        if (doMerge) {
+                            // todo: delete their associated property records
+                            usergv.remove()
+                        }
+                        else {
+                            usergv.set("name", targetUser)
+                            usergv.store()
+                        }
                     }
                 }
 
             else {
                 // todo: only look in jira internal directory
                 List gvs = gd.findByAnd("User", [userName: sourceUser])
-                assert gvs.size() == 1
+                gvs.each {GenericValue usergv ->
                 if (! preview) {
-                    GenericValue usergv = gvs.first() as GenericValue
                     if (doMerge) {
                         usergv.remove()
                     }
                         usergv.store()
                     }
                 }
+                }
 
                 // group memberships
                 gvs = gd.findByAnd("Membership", [childName: sourceUser, directoryId: 1, membershipType: "GROUP_USER"])
             if (!preview) {
                 gvs.each {GenericValue gv ->
                     List matchFields = ["pid", "projectroleid"]
+                    /*
                     if (doMerge && targetGvs.find {
                         gv.getFields(matchFields) == it.getFields(matchFields)
                     }) {
                         gv.remove()
                     }
                     else {
+                    */
+                    // we do always want to merge
                         gv.set("roletypeparameter", targetUser)
                         gv.store()
-                    }
+                    //}
                 }
                 cachingProjectRoleAndActorStore.clearCaches()
             }