Reputation: 345
I am currently running into the below issue when using JIRA:
I created a new issue type (say Client-Request) and Project Role (say Client), is there any way to limit only users in project role 'Client' can create issue 'Client-Request'?
I have tried the below method: In the workflow designer, I tried to add Validators (Permission Validator) to step Create, hoping the validator can filter on Project Role, but JIRA seems does not have that feature.
Is there any way to workaround this problem? or any plugins might be helpful?
Upvotes: 3
Views: 519
Reputation: 15
You can try adding a Groovy Validator in Create transition to check whether user is member of 'Client' Role.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
def issue = underlyingIssue
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def projectRoleManager = ComponentAccessor.getComponentOfType(ProjectRoleManager)
def role = projectRoleManager.getProjectRole("Client")
return projectRoleManager.isUserInProjectRole(currentUser, role, issue.getProjectObject())
Another Approach I can think of is to add a Javascript in Create Screen. Check user membership of 'Client' Role through AJAX call. Then Enable/Disable 'Client Request' Issue type in Create Screen.
I have the below JS for checking Group membership of a user. Please modify it for Role membership.
function getCurrentUserName()
{
var user;
AJS.$.ajax({
url: contextPath + "/rest/gadget/1.0/currentUser",
type: 'get',
dataType: 'json',
async: false,
success: function(data) {
user = data.username;
}
});
return user;
}
function getGroups(user)
{
var groups;
AJS.$.ajax({
url: contextPath + "/rest/api/2/user?username="+user+"&expand=groups",
type: 'get',
dataType: 'json',
async: false,
success: function(data) {
groups = data.groups.items;
}
});
return groups;
}
function isUserInGroup(user, group){
var groups = getGroups(user);
for (var i = 0; i < groups.length; i++){
if (groups[i].name == group){
return true;
}
}
return false;
}
You might have to use: "/rest/api/2/project/{projectIdOrKey}/role"
Please refer https://docs.atlassian.com/DAC/rest/jira/6.1.html
Upvotes: 0
Reputation: 4856
Hmm this is an interesting issue. I think that this is currently not possible since you could have only one permission and issue-type scheme connected to any project.
Try asking your question over at https://answers.atlassian.com/.
Upvotes: 0