Script Runner Rename User Script only changes internal directory groups?

Ubisoft April 24, 2015

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

0 votes
João Palharini
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 24, 2015

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

Ubisoft April 24, 2015

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

Alejo Villarrubia [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 1, 2015

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

Ubisoft May 1, 2015

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 Sign up to answer