-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpostFunctionUpdateProjectRoleFromUserPickerField.groovy
More file actions
56 lines (48 loc) · 2.63 KB
/
Copy pathpostFunctionUpdateProjectRoleFromUserPickerField.groovy
File metadata and controls
56 lines (48 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* Post function to update project role from user picker field
* Video link: https://youtu.be/0--2IoU6KCA
**/
//import com.atlassian.jira.issue.IssueManager
//import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.bc.projectroles.ProjectRoleService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleActor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.util.SimpleErrorCollection
import com.atlassian.jira.user.ApplicationUser
//IssueManager im = ComponentAccessor.getIssueManager()
//MutableIssue issue = im.getIssueObject("ANDROID-34")
//get the value of Project Manager
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def projectManagerField = customFieldManager.getCustomFieldObjectsByName("Project Manager")
def projectManagerValue = issue.getCustomFieldValue(projectManagerField[0]) as ApplicationUser
//get the value of Project Manager
def projectSponsorField = customFieldManager.getCustomFieldObjectsByName("Project Sponsor")
def projectSponsorValue = issue.getCustomFieldValue(projectSponsorField[0]) as ApplicationUser
def pmActors = []
def psActors = []
pmActors.add(projectManagerValue.getUsername().toString())
psActors.add(projectSponsorValue.getUsername().toString())
def projectManager = ComponentAccessor.getProjectManager()
def projectRoleService = ComponentAccessor.getComponent(ProjectRoleService)
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def errorCollection = new SimpleErrorCollection()
//def project = projectManager.getProjectObjByKey("ANDROID")
def project = issue.getProjectObject()
def projectManagerRole = projectRoleManager.getProjectRole("Project Managers")
def projectSponsorsRole = projectRoleManager.getProjectRole("Project Sponsors")
//Add to Project Managers role
projectRoleService.addActorsToProjectRole(pmActors,
projectManagerRole,
project,
ProjectRoleActor.USER_ROLE_ACTOR_TYPE,
errorCollection)
//Add to Project Sponsors role
projectRoleService.addActorsToProjectRole(psActors,
projectSponsorsRole,
project,
ProjectRoleActor.USER_ROLE_ACTOR_TYPE,
errorCollection)