I need to automatically set the security level of an issue based on the users group ,
i am writing a groovy post function for this using script runner
i have 2 security levels with ids 10000 and 10001
below is the groovy script
import com.atlassian.jira.ComponentManager import com.atlassian.jira.ManagerFactory import com.atlassian.jira.issue.security.IssueSecurityLevelManager import com.atlassian.jira.issue.security.IssueSecuritySchemeManager import com.opensymphony.user.User import com.atlassian.jira.issue.IssueImpl import org.apache.log4j.Category import com.atlassian.jira.issue.MutableIssue; import org.ofbiz.core.entity.GenericValue import com.atlassian.jira.ComponentManager; import com.atlassian.jira.bc.project.component.ProjectComponent; import com.atlassian.jira.bc.project.component.ProjectComponentManager; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.IssueFactory; ComponentManager componentManager = ComponentManager.getInstance() ; IssueFactory issueFactory = componentManager.getIssueFactory(); MutableIssue issue = issueFactory.getIssue(); User currentUser = componentManager.getJiraAuthenticationContext().getUser() if(currentUser.inGroup("jira-administrators")) { issue.setSecurityLevelId(10001) } else if(currentUser.inGroup("jira-developers")) { issue.setSecurityLevelId(10000) } issue.store()
i am getting an error :Passed List had more than one value.
please can someone guide me where i am going wrong ?
thanx in advance
Community moderators have prevented the ability to post new answers.
Are those security levels valid?
Does it work when you set the security level in the web UI?
Add some logging so you can see exactly where the failure is.
Hi Jamie ,
I am able to set the security level through UI , I actually took help from your blog . When i run the exact script which you have provided there i get this error in log Could not find security level for Private . I guess i am missing something important in my script .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I added some logging in my script and found that the issue object i get is null , i commented few lines and the script works fine .
log = Category.getInstance("com.onresolve.jira.groovy.PostFunction") log.debug("PostFunction function running") ComponentManager componentManager = ComponentManager.getInstance() ; //IssueFactory issueFactory = componentManager.getIssueFactory(); //log.error("user admin $issueFactory") //MutableIssue issue = issueFactory.getIssue(); //log.error("user admin $issue") User currentUser = componentManager.getJiraAuthenticationContext().getUser() if(currentUser.inGroup("jira-administrators")) { log.debug("user admin") issue.setSecurityLevelId(10001) } else if(currentUser.inGroup("jira-developers")) { log.debug("user developer") issue.setSecurityLevelId(10000) }
Thanx :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great, well done. Yes, issue is passed in the binding to your script so you don't need to get it or declare it.
issueFactory.getIssue gets an empty issue - use this to create a new issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
IssueSecuritySchemeManager issueSecuritySchemeManager = ManagerFactory.getIssueSecuritySchemeManager(); IssueSecurityLevelManager issueSecurityLevelManager = ManagerFactory.getIssueSecurityLevelManager(); srcProjectGV = issue.getProject(); issueSecurityScheme = issueSecuritySchemeManager.getSchemes(srcProjectGV) secLevelGv = issueSecurityLevelManager.getSecurityLevelsByName("Internal"); issue.setSecurityLevelId(secLevelGv.id); // Do not use $ or [] here it should NOT be issue.setSecurityLevelId($secLevelGv.id) or issue.setSecurityLevelId([secLevelGv.id]) issue.store();
And you are done...!!!!
I can set issue security as a script from workflow post fuction in Jira 5.2.x
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It doesn't work with Jira 5.x.
What must i change?
Regards,
Tim
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi!
I know its a little bit late but...:
import com.atlassian.jira.ComponentManager import com.atlassian.crowd.embedded.api.* import org.ofbiz.core.entity.GenericValue import com.atlassian.jira.bc.project.component.ProjectComponent import com.atlassian.jira.bc.project.component.ProjectComponentManager import com.atlassian.jira.security.groups.GroupManager ComponentManager componentManager = ComponentManager.getInstance() User currentUser = componentManager.getJiraAuthenticationContext().getUser() GroupManager groupManager = componentManager.getComponentInstanceOfType(GroupManager.class) if(groupManager.isUserInGroup(currentUser.name, "jira-administrators")) { issue.setSecurityLevelId(10001) } else if(groupManager.isUserInGroup(currentUser.name, "jira-developers")) { issue.setSecurityLevelId(10000) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Does this work on Jira 7.5? I want to use this code as a Script Listener.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
it is giving an error
Caused by: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: java.lang.String.first() is applicable for argument types: () values: []
Possible solutions: print(java.io.PrintWriter), print(java.lang.Object), find(), find(java.lang.String), find(java.lang.CharSequence), find(java.util.regex.Pattern)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:318)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:111)
... 198 more
Caused by: groovy.lang.MissingMethodException: No signature of method: java.lang.String.first() is applicable for argument types: () values: []
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
at Script2.run(Script2.groovy:74)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:315)
... 199 more
I even tried hard coding the value as and then pass it to set but no luck
secLevelGv = ("10152"); issue.setSecurityLevel(secLevelGv.first());
or
issue.setSecurityLevel([secLevelGv])
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The problem is in the error message... check the list list is not empty and then do:
issue.setSecurityLevel(secLevelGv.first());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, It is breaking in Jira 5.2.11
ERROR:
Caused by: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.setSecurityLevel() is applicable for argument types: (java.lang.Integer) values: [10152]
Possible solutions: setSecurityLevel(org.ofbiz.core.entity.GenericValue), getSecurityLevel(), setSecurityLevelId(java.lang.Long), getSecurityLevelId()
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:318)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:111)
... 198 more
Caused by: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.setSecurityLevel() is applicable for argument types: (java.lang.Integer) values: [10152]
Possible solutions: setSecurityLevel(org.ofbiz.core.entity.GenericValue), getSecurityLevel(), setSecurityLevelId(java.lang.Long), getSecurityLevelId()
Could you please help with it?
I tried
issue.setSecurityLevel(10152);
issue.setSecurityLevelID(10152);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Then I tried
secLevelGv = issueSecurityLevelManager.getSecurityLevelsByName("Internal"); issue.setSecurityLevel([secLevelGv]);
Now the error is
Caused by: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.setSecurityLevel() is applicable for argument types: (java.util.ArrayList) values: [[[[id:10152, scheme:10040, description:Only for Jira Admins, ...]]]]
Possible solutions: setSecurityLevel(org.ofbiz.core.entity.GenericValue), getSecurityLevel(), setSecurityLevelId(java.lang.Long), getSecurityLevelId()
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:318)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:111)
... 198 more
Caused by: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.setSecurityLevel() is applicable for argument types: (java.util.ArrayList) values: [[[[id:10152, scheme:10040, description:Only for Jira Admins, ...]]]]
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at Script37.run(Script37.groovy:66)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:315)
... 199 more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.