Currently I am organizing users into Groups to define permission levels. I have then defined the required "permissions" needed on the issue itself. Ultimately I need to define a list of Approvers based on the intersect of these 2 groups. The script below will combine the users in both groups. Need help modifying to build that intersect.
To narrow it down even further, of the people that are in both groups, is it possible to limit it to only those associated with the project the issue is in?
The below retrieves the group names from the issue fields (cf_10420 & cf_10504), gathers users listed in both of those groups, and then defines those people as approvers.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def issue = event.issue
def groupManager = ComponentAccessor.groupManager
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def groupPicker1 = customFieldManager.getCustomFieldObject("customfield_10420")
def groupPicker2 = customFieldManager.getCustomFieldObject("customfield_10504")
def approvers = customFieldManager.getCustomFieldObject("customfield_10005")
if (groupPicker1 || groupPicker2) { // execute this only if field 10420 is not empty or 10504 is not empty
def usersinGroup1 = groupManager.getUsersInGroup(issue.getCustomFieldValue(groupPicker1)) // get users from the first group
def usersinGroup2 = groupManager.getUsersInGroup(issue.getCustomFieldValue(groupPicker2)) // get users from the second group
Set usersFromBothGroups = usersinGroup1 + usersinGroup2
def changeHolder = new DefaultIssueChangeHolder()
approvers.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(approvers), usersFromBothGroups),changeHolder) // update field 10005 to those users
if (usersFromBothGroups.contains(issue.reporter)) {return true} // if the reporter is in the group, return true and execute the fast-track
else {false} // otherwise, do not fast-track the issue
}