My client wants to restrict item creation to people of two teams.
Due to the circumstances I can't work with simple permissions.
The client is using scriptrunner for other projects; So my initial thought was to leverage that.
By using a simple scripted validator in the "create" transition I want to check whether the current user is part of group a or group b, if it validates to true, the item can be created.
I am a total groovy script noob, so naturally I've done some digging and came up with the following groovy "script":
import com.atlassian. jira.components.ComponentAccessor
if(ComponentAccessor.getGroupManager().isUserInGroup(currentUser, "group name a")){}
else if(ComponentAccessor.getGroupManager().isUserInGroup(currentUser, "group name b")) {}
Which does not work.
Regardless of it working as intended or not, it also doesn't display the error message I provided in the ssv.
What am I doing wrong? Is there a better solution, do I just need to adjust the script?
Hi @Luke,
you can do that using below steps --> Script Validator --> Simple Script Validator
source: code
Error: your error message
Field: Issue Type
I'm attaching snippet for your reference, here I'm not allowing "Group-A" members to create "Story", you can modify this code according to your requirement
import com.atlassian.jira.component.ComponentAccessor
def groupManager = ComponentAccessor.getGroupManager()
if(groupManager.isUserInGroup(issue.reporter?.name, 'Greoup-A') && !issue.issueType.name == "Story"){
return true
}else{
return false
}
BR,
Leo
Hi Leo
Thanks for your input.
I have adapted my simple scripted validator to your code, exchanging some parts and leaving others out.
After publishing the workflow on the clients test environment, it successfully blocks me from creating an issue, since I'm in neither of the groups. But the error message still isn't getting displayed, it just doesn't create the issue; Just like when you leave a required field empty.
I am starting to think that it might be an issue with the clients setup of jira and scriptrunner itself.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey,
if you are using "Simple Script validator", have you filled below 2 fields?
1. Error Message:(error to display users)
2. Field:(under which field error message should appear)
if you are using "Custom Script validator", use below snippet instead of "return false" statement
import com.opensymphony.workflow.InvalidInputException // importing exception page to handle
throw new InvalidInputException("custom error message") // instead of return false
BR,
Leo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Leo
I am using the "simple scripted validator", and yes I've got the two fields "error message" and "field" set to the respective values.
The validation seems to work, as it does not allow me to create items anymore (since I'm not part of that usergroup), but there's never an error message.
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.