I would like to set the field components read only except for component leads using behaviours. Any ideas on how to achieve this ?
if you don't have components field on a screen (meaning you can't change them while making a transition or editing issue) then put this in initializer:
import com.atlassian.jira.component.ComponentAccessor
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
getFieldByName("your field name").setReadOnly(true)
if (currentUser.name in underlyingIssue.components*.lead) {
getFieldByName("your field name").setReadOnly(false)
}
if it's on the screen, put this into component's code :
import com.atlassian.jira.component.ComponentAccessor
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def yourField = getFieldByName("your field name")
if (currentUser.name in getFieldById(getFieldChanged()).value*.lead) {
yourField.setReadOnly(false)
} else {
yourField.setReadOnly(true)
}
edit:
I thought it's about making field editable only for component leaders from this particular issue. guess for whole project something like this in component's field script should work:
import com.atlassian.jira.component.ComponentAccessor
def projectComponentManager = ComponentAccessor.projectComponentManager
def leads = projectComponentManager.findAllForProject(issueContext.projectId)*.lead
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
getFieldById(getFieldChanged()).setReadOnly(true)
if (currentUser.name in leads) {
getFieldById(getFieldChanged()).setReadOnly(false)
}
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.