Hey,
we use the following code as a script-runner post function:
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.opensymphony.user.Group import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.config.SubTaskManager import org.ofbiz.core.entity.GenericValue import com.opensymphony.user.User import com.atlassian.core.user.UserUtils import com.atlassian.jira.user.util.UserManager import com.opensymphony.workflow.WorkflowContext import com.atlassian.jira.security.util.GroupSelectorUtils import com.atlassian.jira.util.ImportUtils ComponentManager componentManager = ComponentManager.getInstance() CustomFieldManager customFieldManager = componentManager.getCustomFieldManager() def issueFactory = componentManager.getIssueFactory() def issueManager = componentManager.getIssueManager() def indexManager = componentManager.getIndexManager() def groupCf = customFieldManager.getCustomFieldObjectByName("Kompetenzcluster") // name of group CF def UserList = [] String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller() User currentUserObj = UserUtils.getUser(currentUser) GroupSelectorUtils util = (GroupSelectorUtils) ComponentManager.getInstance().getContainer().getComponentInstanceOfType(GroupSelectorUtils.class) //Group group = issue.getCustomFieldValue(groupCf) as Group issue.getCustomFieldValue(groupCf).each {Object group -> if (group) { Group groupObj = util.getGroups((String) group) groupObj.getUsers().each {String user -> if(!UserList.contains(user) && user != currentUser) { MutableIssue newIssue = issueFactory.getIssue() newIssue.summary = "$user: " + issue.summary newIssue.issueTypeId = '71' newIssue.project = issue.project newIssue.reporter = UserUtils.getUser(user) newIssue.assignee = UserUtils.getUser(user) newIssue.assigneeId = user newIssue.priority = issue.priority Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object> GenericValue newIssueGv = issueManager.createIssue(currentUserObj, newIssueParams) boolean wasIndexing = ImportUtils.isIndexIssues(); ImportUtils.setIndexIssues(true); indexManager.reIndex(newIssueGv); SubTaskManager subTaskManager = componentManager.getSubTaskManager() subTaskManager.createSubTaskIssueLink(issue, newIssue, componentManager.getJiraAuthenticationContext().getUser()) indexManager.reIndex(newIssueGv); indexManager.reIndex(issue); ImportUtils.setIndexIssues(wasIndexing); UserList.add(user) } } } }
Now, we wanted to add a permission check. So before a subtask will be created, the script should check, whether the author of the ticket has the CREATE permission in this project (project shortcut OCRA). can you help us with this problem?
thank you very much in advance!
regards,
michael
Community moderators have prevented the ability to post new answers.
Given the code you have already, this line should return true or false (untested):
import com.atlassian.jira.security.Permissions import com.atlassian.jira.user.UserUtils ... def permissionManager = ComponentManager.instance.getPermissionManager() def hasPerms = permissionManager.hasPermission(Permissions.CREATE_ISSUE, issue.project, UserUtils.getUser(currentUser))
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.