Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,370,157
Community Members
 
Community Events
168
Community Groups

With out user names is possible to Approve CAB

Edited

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.sal.api.ApplicationProperties
import com.atlassian.sal.api.UrlMode
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import groovy.transform.BaseScript
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.event.type.EventDispatchOption

import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

@BaseScript CustomEndpointDelegate delegate

cabMemberApprove(httpMethod: "GET") { MultivaluedMap queryParams ->

def response = ""
synchronized(this){
Long issueId = queryParams.getFirst("issueId") as Long
def customFieldManager = ComponentAccessor.customFieldManager

StringBuilder bodyB = new StringBuilder()

ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() as ApplicationUser
def issueManager = ComponentAccessor.getIssueManager()
Issue issue = issueManager.getIssueObject(issueId)

CustomField pendingWithCf = customFieldManager.getCustomFieldObjectsByName("Change Pending With")[0]
Collection<ApplicationUser> pendingWith = issue.getCustomFieldValue(pendingWithCf) as Collection<ApplicationUser>
if(!pendingWith) {
pendingWith = new ArrayList<ApplicationUser>()
}

CustomField changeApprovedByCF = customFieldManager.getCustomFieldObjectsByName("Change Approved By")[0]
Collection<ApplicationUser> changeApprovedBy = issue.getCustomFieldValue(changeApprovedByCF) as Collection<ApplicationUser>
if(!changeApprovedBy) {
changeApprovedBy = new ArrayList<ApplicationUser>()
}

if(pendingWith.contains(user) && !changeApprovedBy.contains(user)) {
changeApprovedBy.add(user)
pendingWith.remove(user)
issue.setCustomFieldValue(pendingWithCf, pendingWith)
issue.setCustomFieldValue(changeApprovedByCF, changeApprovedBy)
bodyB.append("${issue.key} : Approved")
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
} else {
bodyB.append("${issue.key} : Already Approved")
}

def flag = [
type : 'info',
title: 'CAB',
close: 'auto',
body : bodyB.toString()
]

UserMessageUtil.flag(flag)

def applicationProperties = ScriptRunnerImpl.getOsgiService(ApplicationProperties)
def baseUrl = applicationProperties.getBaseUrl(UrlMode.ABSOLUTE)
response = Response.temporaryRedirect(URI.create("${baseUrl}/browse/${issue.key}")).build()
}
return response
}

 

 

//////////////////////////////////////////////////////

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.groups.GroupManager
import com.atlassian.crowd.embedded.api.Group

GroupManager grpManager = ComponentAccessor.groupManager
def users = grpManager.getUsersInGroup("CAB")

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def usersCf = customFieldManager.getCustomFieldObjectsByName("CAB")[0]
issue.setCustomFieldValue(usersCf, users)

//def pendingWithCf = customFieldManager.getCustomFieldObjectsByName("Change Pending With")[0]
//issue.setCustomFieldValue(pendingWithCf, users)

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events