Hello Team,
I am trying to restrict Issue Type= Internal Defect for one group, so that people under this group will only have access to Internal Defect Issue type. Therefore i am using below code Initializer :
{code}
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def allIssueTypes = ComponentAccessor.constantsManager.allIssueTypeObjects
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueTypeField = getFieldById(ISSUE_TYPE)
def remoteUsersRoles = projectRoleManager.getProjectRoles(user, issueContext.projectObject)*.name
def availableIssueTypes = []
if ("atau-g-jira_bmm" in remoteUsersRoles) {
availableIssueTypes.addAll(allIssueTypes.findAll { it.name in ["Internal Defect"] })
}
if ("jira-users" in remoteUsersRoles) {
availableIssueTypes.addAll(allIssueTypes.findAll { it.name in ["Build Revision - MK6", "Risk", "Field Defect", "Build Revision - Gen7/GDK/Gen8 EGM"] })
}
issueTypeField.setFieldOptions(availableIssueTypes)
{code}
Even after this code, user under group *atau-g-jira_bmm* is still able to see/select all issues types. I am not sure what went wrong. Can you please suggest the solution.
Regards,
Manoj
If I understand correctly, it looks like you are interested in limiting issue type access based on the jira group membership (jira-users vs atau-g-jira_bmm).
However, your code is actually looking at the project role membership.
You can see that by sending your list of remoteUsersRoles to the log.
If you want to get the current user's general group membership (regardless of role on the current project), you can have a look at this other post: https://community.atlassian.com/t5/Marketplace-Apps-questions/jira-scriptrunner-user-belongs-to-group/qaq-p/640102
Hi,
This script is which roles the current user belongs to. So you cannot test groups against "remoteUsersRoles", but you should use roles rather.
Also, I added some imports that fixed some execution errors :
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.issuetype.IssueTypeImpl
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE
@BaseScript FieldBehaviours fieldBehaviours
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def allIssueTypes = ComponentAccessor.constantsManager.allIssueTypeObjects
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueTypeField = getFieldById(ISSUE_TYPE)
def remoteUsersRoles = projectRoleManager.getProjectRoles(user, issueContext.projectObject)*.name
log.error("remoteUsersRoles : " + remoteUsersRoles)
def availableIssueTypes = []
if ("Administrators" in remoteUsersRoles) {
availableIssueTypes.addAll(allIssueTypes.findAll { it.name in ["Internal Defect"] })
}
if ("Developers" in remoteUsersRoles) {
availableIssueTypes.addAll(allIssueTypes.findAll { it.name in ["Build Revision - MK6", "Risk", "Field Defect", "Build Revision - Gen7/GDK/Gen8 EGM"] })
}
issueTypeField.setFieldOptions(availableIssueTypes)
Now the script is still not working on my instance :
[c.o.j.groovy.user.FormField] Unsupported type class com.atlassian.jira.issue.issuetype.IssueTypeImpl in setFieldOptions()
And I was not able to resolve it. So if you do, please let me know. Otherwise maybe raise a support ticket to adaptavist.
Antoine
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.
Hi Antoine_Berry, I tried this, I tried limiting the available issue types based on project key, and it doesnt't fully work. For eg there is an issue type called "Project" which can be opened by people only in project role Administrator / Team Leaders, but the script doesn't allow anyone or any role to open "Project" issue type.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Zita Bagi ,
It will be hard to help if you do not share your code. Also consider opening a new question so it has more visiblity and everyone can help. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In the meantime I found this and it worked for me with behaviours:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Nice, I accepted her answer on this question so it has more visiblity. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.