Hi,
We have a script runner in place, something which I have inherited, which already adds users as watchers, but is also including a few old disabled users who are members of a group, from when jira was initially setup using Jira Internal Directory, before it was integrated with Azure AD. The simple fix would be for me to remove the user from the group, but I cannot remove user from the groups, and encounter an error
"You cannot remove a group from this user as it is not visible to you."
Therefore, I would like to modify the script to only add those watchers where the account is enabled or ignore disabled accounts if they exist in the group. ("techsupport")
The code is below, I can make sense of what its doing, but not being a coder, a little help on how to achieve this would be very appreciated.
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
IssueManager issueManager = ComponentAccessor.getIssueManager();
def watcherManager = ComponentAccessor.getWatcherManager()
def userManager = ComponentAccessor.getUserManager()
Issue issue = event.issue;
if (ComponentAccessor.getGroupManager().getUsersInGroup("support").contains(issue.reporter)) {
ComponentAccessor.getGroupManager().getUsersInGroup("techsupport").each {
def user = userManager.getUserByName(it.getName())
if (user) watcherManager.startWatching(user, issue)
}
}
Thanks in advance
If you want to include only active user, you can pass an additional parameter to the getUsersInGroup method to tell it to exclude inactive users.
But here is a simplified and somewhat cleaned-up version of your script:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
def watcherManager = ComponentAccessor.watcherManager
def groupManager = ComponentAccessor.groupManager
def issue = (event as IssueEvent).issue
if (groupManager.isUserInGroup(issue.reporter, "support")) {
groupManager.getUsersInGroup("techsupport", false).each {user->
watcherManager.startWatching(user, issue)
}
}
Thanks for the guidance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.