How do you remove the security level on issue programmatically ?

Aktarel January 28, 2018

Hello guys,

I am implementing a java plugin to manage automatic apply of security issue on JIRA Core. I can apply security level on update event with custom security rule. I want to add a custom behaviour which is : 

My issue has a security level applied. 

if no automatic security rules apply anymore

then remove the security level programmatically 

 

I tried :

MutableIssue mi = issueManager.getIssueByCurrentKey(event.getIssue().getKey());
mi.setSecurityLevelId(-1L);
issueManager.updateIssue(adminUser, mi, EventDispatchOption.DO_NOT_DISPATCH,
false);

 

or 

 

mi.setSecurityLevelId(null);

issueManager.updateIssue(adminUser, mi, EventDispatchOption.DO_NOT_DISPATCH,
false);

 

This code does not apply what I expected, I do not know how to proceed, do you have a suggestion ? :)

Thank you in advance

1 answer

1 accepted

0 votes
Answer accepted
Andreas Morgner January 17, 2019

Hi @Aktarel,

I've just found your question. As I was working on a similar function, for me in Jira 7.10.2  this works just fine.

The script creates an exact copy within another project but removes the security scheme. 

MutableIssue mutableIssue = issueManager.getIssueByCurrentKey(newIssue?.key);
mutableIssue.setSecurityLevelId(null);
issueManager.updateIssue(AUTH_USER, mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false);

The already created issue does not have any security level afterwards. 

What did you expect to happen or what is the result of the code above?

Best regards

Aktarel January 18, 2019

Hello Andreas, 

The code you submitted is OK.

I was distracted when testing the second code I sent, it remove the issue security as expect when setted null. 

Best regards

Andreas Morgner January 18, 2019

Hi @Aktarel

great to hear :)

From what I found within the API Documentation setting the security level to null should be the correct way. 

if you check the method getDefaultSecurityLevel() provided by the IssueSecurityLevelManager, It might retune null. In my use case I've used the method to get the default security level of a project while cloning an issue to a new project. So instead of removing the level and setting the default, I always set the default level which is null, if there is no security level set for the project.

Result: the security level is set to null and the issue is "visible for everyone".

Source: IssueSecurityLevelManager.getDefaultSecurityLevel()

Maybe this helps you in addition.

Best regards
Andreas Morgner

Suggest an answer

Log in or Sign up to answer