Script Runner Rename User Script only changes internal directory groups?

Hello, 

I was working on adapting the existing Rename User script for JIRA 6.3  I got it working, to some extent, but something odd came up in doing some changes that explains a bug that we've had to workaround in the past:

 

gvs = gd.findByAnd("Membership", [childName: sourceUser, directoryId: 1, membershipType: "GROUP_USER"])
msg = "Update ${gvs.size()} Membership records"
log.debug(msg)
msgs << msg
if (!preview) {

    List<GenericValue> targetGvs = gd.findByAnd("Membership", [childName: targetUser, directoryId: 1, membershipType: "GROUP_USER"])
    List<Object> targetGroups = targetGvs*.get("parentName")

    gvs.each {GenericValue gv ->
        if (doMerge && targetGroups.contains (gv.get("parentName"))) {
            gv.remove()
        }
        else {
            gv.set("childName", targetUser)
            gv.set("lowerChildName", targetUser)
            gv.store()
        }
    }
}

It's the segment that reassigns the groups in the script.  It seems to only reassign the membership rows that have directoryId 1, and I'm not 100% sure why?  I've finished adapting the script for JIRA 6.3 (with a few bugs, still, but it's functional, code is here) and I removed the directory mention, I'm just unsure whether i've broken something in the process?

Maybe it's to avoid bugs when merging users in different directories?

Thanks, 

Eric

1 answer

Hi Eric!

I see that your script contains the variable "directoryId: 1" on multiple lines. Have you tried removing this or changing to the external directory's ID?

Also, please check your directories settings to see if  JIRA has "Read/Write" permission or "Read-only with local groups".

--
Cheers!

Joao

Hi Joao, I'm not trying to troubleshoot a bug here. I'm not having any significant problems with my script. I was just asking why the script was written that way in the first place, as I didn't write it, it's a segment from the rename user script that Jamie Echlin wrote. Eric

The example code you got is a bit old and it is using deprecated classes. That was the probably the way of achieving this in Jira 4/5, but I'm sure there is a better way to do it with the new managers and services provided in the newest Jira API versions

Hi Alejo, Again, that's completely beside the question that I'm asking here. I'm aware that the classes are deprecated. It wasn't written by me and hasn't been updated since jira5 (at least). I'm simply asking if there is a specific reason why only the internal directory is changed in the script, is it to avoid a bug/issue of which I'm still unaware? I've actually done some adjustments in the live code that I'm using in order to avoid the deprecated classes and methods, this is the original code from the plugin that I'm posting here as a reference. Eric

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,001 views 12 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot