Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Checking if security level can be set (Scriptrunner) Edited

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?

2 answers

1 accepted

1 vote
Answer accepted

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?!

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

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.

 

Hello Henrik:

Could you please provide the code that you are using so that we have something to base our development on?

Cheers!

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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

177 views 2 1
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you