I am trying to detect, is user member of group. I have tried already several classes with no success.
Basically,what i need, is to check which group belongs logged time entry: there is my idea
# fragment from code wManager = ComponentManager.getInstance().getWorklogManager() worklogList = wManager.getByIssue(issue); for worklogEntry in worklogList: workLogAuthor = worklogEntry.getAuthor() workLogTimeEntry = worklogEntry.getTimeSpent() groupTest = "Administrators" ### there I need to check, and do actions with if else, no more ideas how.
Any tips & tracks will help to figure out this.
Running JIRA 4.4.4
Community moderators have prevented the ability to post new answers.
Thank you for your time and answer. I have already figured out by browsing some plugins source and migrating logics to Jython:
for worklogEntry in worklogList: workLogAuthor = worklogEntry.getAuthor() workLogTimeEntry = worklogEntry.getTimeSpent() spentSeconds = spentSeconds + workLogTimeEntry authorGroups = userManager.getGroupsForUser(workLogAuthor) for authorGroup in authorGroups: partOfGroup = authorGroup.getName() if (partOfGroup == "A"): ... elif (partOfGroup == "B"): ... elif (partOfGroup == "C"): ... elif (partOfGroup == "D"): .. elif (partOfGroup == "E"): ... elif (partOfGroup == "F"): ... elif (partOfGroup == "G"): ...
for example:
import com.atlassian.jira.security.groups.GroupManager import com.atlassian.jira.security.JiraAuthenticationContext projectManagerGroup = ComponentManager.getComponentInstanceOfType(com.atlassian.jira.security.groups.GroupManager) def inGroup(user,group): try: return projectManagerGroup.isUserInGroup(user,group) except: return None currentUser = authenticationContext.getLoggedInUser().getName() if inGroup(currentUser,'groupName'): //do sth
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Wieshka,
I know how to do it in JAVA, shouldn't be hard to rewrite it for jython ;-)
private final WorklogManager worklogManager; private final UserManager userManager; public void doSometing(Issue issue) { List<Worklog> worklogs = worklogManager.getByIssue(issue); for (Worklog worklog : worklogs) { String author = worklog.getAuthor(); if (userManager.isUserInGroup(author, "Administrators")) { userManager.isAdmin(author); //if your going for admins // do something } } }
if you need the groupnames for a particular user you will need to user the GroupManager
private final GroupManager groupManager; .... Collection<String> groupNames = groupManager.getGroupNamesForUser(username);
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.