setting security level using script runner.

Hi,

I have added a post script function to specific action in workflow and added below script. However I getting below error any idea what I am doing wrong here? Thanks for your help!

Basically, my requirement is to make sure that the said security level "Test Sec Level" is available for current user. If yes then set the security level. This happens during issue creation.

def secLevelString = "Test Sec Level"
log.debug ("Launchig Create script")
ComponentManager componentManager = ComponentManager.getInstance()
IssueSecurityLevelManager securityLevelManager = componentManager.getComponentInstanceOfType(com.atlassian.jira.issue.security.IssueSecurityLevelManager)

IssueSecuritySchemeManager issueSecuritySchemeManager = ManagerFactory.getIssueSecuritySchemeManager()
IssueSecurityLevelManager issueSecurityLevelManager = ManagerFactory.getIssueSecurityLevelManager()

GenericValue srcProjectGV = issue.getProject()
def issueSecurityScheme = issueSecuritySchemeManager.getSchemes(srcProjectGV).size() == 0 ? null : issueSecuritySchemeManager.getSchemes(srcProjectGV)[0]

def currentUser = componentManager.getJiraAuthenticationContext().getUser()
def secLevelGv = issueSecurityLevelManager.getUsersSecurityLevels(issue.getGenericValue(), currentUser ).find ({
it.get("name") == secLevelString
});

if (secLevelGv) {
log.debug ("Set ${issue.getKey()} to $secLevelString")
issue.setSecurityLevel (secLevelGv)
issue.store()

}
else {
log.error ("Could not find security level for $secLevelString")
}

Error

2014-08-11 16:07:34,367 http-bio-8082-exec-5 ERROR ambarter 967x1291x1 7ovfsk 10.90.11.49 /secure/WorkflowUIDispatcher.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.security.IssueSecurityLevelManagerImpl.getUsersSecurityLevels() is applicable for argument types: (com.atlassian.jira.ofbiz.IssueGenericValue, com.atlassian.jira.user.DelegatingApplicationUser) values: [[summary:test, votes:0, fixfor:null, resolution:null, ...], ...]
Possible solutions: getUsersSecurityLevels(com.atlassian.jira.issue.Issue, com.atlassian.crowd.embedded.api.User), getUsersSecurityLevels(com.atlassian.jira.project.Project, com.atlassian.crowd.embedded.api.User), getUsersSecurityLevels(org.ofbiz.core.entity.GenericValue, com.atlassian.crowd.embedded.api.User), getAllUsersSecurityLevels(com.atlassian.crowd.embedded.api.User)
2014-08-11 16:07:34,367 http-bio-8082-exec-5 ERROR ambarter 967x1291x1 7ovfsk 10.90.11.49 /secure/WorkflowUIDispatcher.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Script post-function failed on THD-71: D:\ATLASSIAN\TRIAL5\JIRA\atlassian-jira\WEB-INF\classes\fssa\custom\test.groovy
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.security.IssueSecurityLevelManagerImpl.getUsersSecurityLevels() is applicable for argument types: (com.atlassian.jira.ofbiz.IssueGenericValue, com.atlassian.jira.user.DelegatingApplicationUser) values: [[summary:test, votes:0, fixfor:null, resolution:null, ...], ...]
Possible solutions: getUsersSecurityLevels(com.atlassian.jira.issue.Issue, com.atlassian.crowd.embedded.api.User), getUsersSecurityLevels(com.atlassian.jira.project.Project, com.atlassian.crowd.embedded.api.User), getUsersSecurityLevels(org.ofbiz.core.entity.GenericValue, com.atlassian.crowd.embedded.api.User), getAllUsersSecurityLevels(com.atlassian.crowd.embedded.api.User)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:103)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
at com.onresolve.jira.groovy.GroovyRunner.runFile(GroovyRunner.java:102)
at com.onresolve.jira.groovy.GroovyRunner.run(GroovyRunner.java:62)
at com.onresolve.jira.groovy.GroovyFunctionPlugin.execute(GroovyFunctionPlugin.java:38)
at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:1050)
at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1446)
at com.opensymphony.workflow.AbstractWorkflow.doAction(AbstractWorkflow.java:564)
at com.atlassian.jira.workflow.OSWorkflowManager.doWorkflowActionInsideTxn(OSWorkflowManager.java:957)
at com.atlassian.jira.workflow.OSWorkflowManager.doWorkflowAction(OSWorkflowManager.java:912)
at com.atlassian.jira.bc.issue.DefaultIssueService.transition(DefaultIssueService.java:450)
at com.atlassian.jira.web.action.workflow.SimpleWorkflowAction.doExecute(SimpleWorkflowAction.java:32) <+1> (ActionSupport.java:165)
at com.atlassian.jira.action.JiraActionSupport.execute(JiraActionSupport.java:87) <+7> (DefaultInterceptorChain.java:39) (NestedInterceptorChain.java:31) (ChainedInterceptor.java:16) (DefaultInterceptorChain.java:35) (GenericDispatcher.java:225) (GenericDispatcher.java:189) (JiraWebworkActionDispatcher.java:152)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) <+2> (ApplicationFilterChain.java:305) (ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) <+14> (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (ChainedFilterStepRunner.java:87) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (XContentTypeOptionsNoSniffFilter.java:22) (AbstractHttpFilter.java:31) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (HeaderSanitisingFilter.java:44) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (IteratingFilterChain.java:46) (DelegatingPluginFilter.java:66)
at com.atlassian.jira.tzdetect.IncludeResourcesFilter.doFilter(IncludeResourcesFilter.java:39) <+3> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
at com.atlassian.jira.baseurl.IncludeResourcesFilter.doFilter(IncludeResourcesFilter.java:38) <+8> (AbstractHttpFilter.java:31) (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66) (ContextFilter.java:25) (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
at com.atlassian.mywork.client.filter.ServingRequestsFilter.doFilter(ServingRequestsFilter.java:37) <+3> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
at com.atlassian.prettyurls.filter.PrettyUrlsDispatcherFilter.doFilter(PrettyUrlsDispatcherFilter.java:60) <+3> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
at com.atlassian.prettyurls.filter.PrettyUrlsSiteMeshFilter.doFilter(PrettyUrlsSiteMeshFilter.java:92) <+3> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
at com.atlassian.prettyurls.filter.PrettyUrlsMatcherFilter.doFilter(PrettyUrlsMatcherFilter.java:56) <+3> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
at com.atlassian.labs.botkiller.BotKillerFilter.doFilter(BotKillerFilter.java:36) <+23> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (ServletFilterModuleContainerFilter.java:77) (ServletFilterModuleContainerFilter.java:63) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (AccessLogFilter.java:103) (AccessLogFilter.java:87) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (XsrfTokenAdditionRequestFilter.java:54) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (SiteMeshFilter.java:181) (SiteMeshFilter.java:85) (SitemeshPageFilter.java:124) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (ChainedFilterStepRunner.java:87) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (IteratingFilterChain.java:46) (DelegatingPluginFilter.java:66)
at com.atlassian.prettyurls.filter.PrettyUrlsCombinedMatchDispatcherFilter.doFilter(PrettyUrlsCombinedMatchDispatcherFilter.java:61) <+22> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (ServletFilterModuleContainerFilter.java:77) (ServletFilterModuleContainerFilter.java:63) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (SecurityFilter.java:234) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (TrustedApplicationsFilter.java:100) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (BaseLoginFilter.java:169) (JiraLoginFilter.java:70) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (IteratingFilterChain.java:46) (DelegatingPluginFilter.java:66) (OAuthFilter.java:61) (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
at com.atlassian.prettyurls.filter.PrettyUrlsCombinedMatchDispatcherFilter.doFilter(PrettyUrlsCombinedMatchDispatcherFilter.java:61) <+13> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (ServletFilterModuleContainerFilter.java:77) (ServletFilterModuleContainerFilter.java:63) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (ProfilingFilter.java:99) (JIRAProfilingFilter.java:19) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (AbstractJohnsonFilter.java:71) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210)
at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) <+10> (UrlRewriteFilter.java:394) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (GzipFilter.java:74) (GzipFilter.java:51) (JiraGzipFilter.java:55) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (IteratingFilterChain.java:46) (DelegatingPluginFilter.java:66)
at com.atlassian.prettyurls.filter.PrettyUrlsCombinedMatchDispatcherFilter.doFilter(PrettyUrlsCombinedMatchDispatcherFilter.java:61) <+40> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (ServletFilterModuleContainerFilter.java:77) (ServletFilterModuleContainerFilter.java:63) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (ChainedFilterStepRunner.java:87) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (AbstractCachingFilter.java:33) (AbstractHttpFilter.java:31) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (AbstractEncodingFilter.java:41) (AbstractHttpFilter.java:31) (PathMatchingEncodingFilter.java:49) (AbstractHttpFilter.java:31) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (JiraStartupChecklistFilter.java:78) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (MultipartBoundaryCheckFilter.java:41) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (ChainedFilterStepRunner.java:87) (JiraFirstFilter.java:57) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (StandardWrapperValve.java:222) (StandardContextValve.java:123) (AuthenticatorBase.java:502) (StandardHostValve.java:171) (ErrorReportValve.java:100) (StandardEngineValve.java:118) (AccessLogValve.java:953) (CoyoteAdapter.java:408) (AbstractHttp11Processor.java:1041) (AbstractProtocol.java:603) (JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.security.IssueSecurityLevelManagerImpl.getUsersSecurityLevels() is applicable for argument types: (com.atlassian.jira.ofbiz.IssueGenericValue, com.atlassian.jira.user.DelegatingApplicationUser) values: [[summary:test, votes:0, fixfor:null, resolution:null, ...], ...]
Possible solutions: getUsersSecurityLevels(com.atlassian.jira.issue.Issue, com.atlassian.crowd.embedded.api.User), getUsersSecurityLevels(com.atlassian.jira.project.Project, com.atlassian.crowd.embedded.api.User), getUsersSecurityLevels(org.ofbiz.core.entity.GenericValue, com.atlassian.crowd.embedded.api.User), getAllUsersSecurityLevels(com.atlassian.crowd.embedded.api.User)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:318)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:111)
... 186 more
Caused by: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.security.IssueSecurityLevelManagerImpl.getUsersSecurityLevels() is applicable for argument types: (com.atlassian.jira.ofbiz.IssueGenericValue, com.atlassian.jira.user.DelegatingApplicationUser) values: [[summary:test, votes:0, fixfor:null, resolution:null, ...], ...]

thanks!

Rama

2 answers

You are using the mix of methods when try to get security levels. Please try to replace

issueSecurityLevelManager.getUsersSecurityLevels(issue.getGenericValue(), currentUser )

to

issueSecurityLevelManager.getUsersSecurityLevels(issue, currentUser.getDirectoryUser())

Hope that helps.

Thanks Alexey! That did help! I am not seeing the error anymore. However, it always returns null for secLevelGv (even though the sec level is available to user ) and hence always executing the else part. I made sure that the user has that security level avaialable. And I am able to select it from the drop down manually.

Appreciate your help!

Rama

0 vote

There is a built-in script for setting the security level, which lets you just specify the security level and the condition for when it should do so, it should make it easier: https://jamieechlin.atlassian.net/wiki/display/GRV/Built-In+Scripts#Built-InScripts-SetIssueSecurity

It has some smarts about making sure the security level is applicable to the project etc.

Thanks for your answer Jamie! But I think I should use "Custom Script Post-Fucntion" in my case as my target security level depend on another value selected on the issue. Above script is working for me, but it sets the Security Level even if it is not available for that user.

But that's what the conditions are for. If you need to set to two possible security levels, you can just the function twice with mutually exclusive conditions.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

78 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you