Hi,
In a workflow post function I'm using Scriptrunner "Set security level to ...". Works fine under the conditions that the user has the right to set security level and the project has the right security scheme. Problem being it ignores the function without warnings to the user if the conditions are not met
I've tried to find a way to validate that with a Script Validator. So that you can't do the transition if this condition is not met.
I'm not a great coder (!) and normally I find a snippet on the net and try to make it work for my needs. I haven't been able to find anything for this.
Anyone out there with an idea?
Hi,
this is a method that could be used for checking if a security level id is valid for an issue.
Boolean isSecurityLevelValid(Issue issue, Long securityLevelId, Logger log = null) { def issueSecuritySchemeManager = ComponentAccessor.getComponent(IssueSecuritySchemeManager) def issueSecurityLevelManager = ComponentAccessor.issueSecurityLevelManager def srcProject = issue.projectObject def issueSecurityScheme = issueSecuritySchemeManager.getSchemeFor(srcProject) if (issueSecurityScheme) { def validLevels = issueSecurityLevelManager.getIssueSecurityLevels(issueSecurityScheme.id) log?.debug "..validLevels-IDs: ${validLevels*.id?.dump()}" return validLevels*.id.contains(securityLevelId) } else { log?.debug "..Doesn't find any IssueSecurityScheme for project ${srcProject.key}" return false } }
Henning
Thank you,
I guess I'm going to have to have some imports on top of that?!
This code assumes that an Issue already exists? But if I'm going to use it in a validator in the create statement - that's probably not true?!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, you need some imports.
The projectObject of the issue is already defined for the create validator and the only thing used. So it should work.
Try this as a scripted validator after adapting SECURITY_LEVEL_ID to the correct id.
import com.atlassian.jira.component.ComponentAccessor import org.apache.log4j.Logger import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.security.IssueSecuritySchemeManager import com.opensymphony.workflow.InvalidInputException Long SECURITY_LEVEL_ID = 12345 if (!isSecurityLevelValid(issue, SECURITY_LEVEL_ID, log)) { invalidInputException = new InvalidInputException("Security level would not be valid.") } Boolean isSecurityLevelValid(Issue issue, Long securityLevelId, Logger log = null) { def issueSecuritySchemeManager = ComponentAccessor.getComponent(IssueSecuritySchemeManager) def issueSecurityLevelManager = ComponentAccessor.issueSecurityLevelManager def srcProject = issue.projectObject def issueSecurityScheme = issueSecuritySchemeManager.getSchemeFor(srcProject) if (issueSecurityScheme) { def validLevels = issueSecurityLevelManager.getIssueSecurityLevels(issueSecurityScheme.id) log?.debug "..validLevels-IDs: ${validLevels*.id?.dump()}" return validLevels*.id.contains(securityLevelId) } else { log?.debug "..Doesn't find any IssueSecurityScheme for project ${srcProject.key}" return false } }
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you!
It works
I put it in a simple scripted validator - so i just discarded your initial if-sentence so it returns true/false.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Henrik:
Could you please provide the code that you are using so that we have something to base our development on?
Cheers!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi DYelamos,
Thank you for responding. But I'm afraid I don't understand your question. What i'm trying to do is finding some code that validates if a security scheme/level is available. I need to run it in the validator part of create issue, I think I can use Script Validator for this.
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.