Groovy to automatically add a few hundreds of Security levels to a particular Issue Security Scheme

Rupa Jain December 18, 2016

Hi,

I need to add around 300 'Security Levels' to a particular 'Issue Security Scheme' in JIRA along with the groups.

Is it possible to implement this using Scriptrunner plugin or through Groovy or any other way?

 

Thanks,

Rupa

8 answers

1 accepted

1 vote
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 22, 2016

Here is code to create a new scheme, and a new level with a single group:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.security.IssueSecuritySchemeManager
import com.atlassian.jira.scheme.SchemeEntity

def issueSecurityLevelManager = ComponentAccessor.getIssueSecurityLevelManager()
def issueSecuritySchemeManager = ComponentAccessor.getComponent(IssueSecuritySchemeManager)

def scheme = issueSecuritySchemeManager.createSchemeObject("FRIDAY", "Issue security scheme for testing")
def level = issueSecurityLevelManager.createIssueSecurityLevel(scheme.id, "Private", "Group only")
def entity = new SchemeEntity("group", "jira-users", level.id)
def gv = issueSecuritySchemeManager.getScheme(scheme.id)

issueSecuritySchemeManager.createSchemeEntity(gv, entity)
Carlos David August 7, 2017

 I'm trying to get this to work in Jira 7.3.1, can you help? The final two lines no longer work it seems

https://community.atlassian.com/t5/JIRA-questions/Add-group-to-security-level-Groovy/qaq-p/616979#M204150

Shaakunthala August 9, 2017

Worked with JIRA 7.1.9

Deepali Kohli April 24, 2023

Hi!

Need help with creating the the entity for user custom field value (multiuser customfield) , I tried

 

def entity = new SchemeEntity("multiuser CF""user/group",securityLevel.id)
Thanks,
Deepali Kohli
0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 20, 2016

Issue security levels can have a "Group Custom Field Value". Why don't you write the customer group to a group custom field (can be hidden), and use that in the security scheme.

Alex Suslin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 20, 2016

it's ok if you don't need single user view only... I have proposed the solution with custom field multiple users, the same approach

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 20, 2016

Your method is very flexible, I agree. Easy to combine multiple groups etc if you need to.

0 votes
Rupa Jain December 20, 2016

The Security Level is set automatically through Groovy post function depending on which group the Reporter belongs to.

 

Example: Say there are two Customers ABC and XYZ. 
ABC has 2 users Sam and Betty.
XYZ has 2 users Tom and Harry. 

What we need is that Sam can see what ticket Betty creates (what users of ABC create) and should not be able to view what all tickets Tom and Harry create(XYZ users).

Is this possible using your solution?

0 votes
Alex Suslin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 19, 2016

May I propose a better solution? I have implemented something like this in my company see the link: "Visible For" field in JIRA

 

  1. Create custom field (multiple user picker) Visible For
  2. Put that field on screens (all view, edit, create - screen scheme and issue type screen scheme) and make required through field configuration scheme
  3. Create Security Scheme with single security level (grant permissions to reporter, assignee, any needed roles and custom field "Visible For". Make that security level a default one for that project. You can even not show security level field on the screen =)

Now, if you need the issue to be visible by that customer, just add him to Visible For

 

P.S. Add all customers to any project role with browse permission, so that role can see issues in the project - permission scheme.

 

Rupa Jain December 20, 2016

The Security Level is set automatically through Groovy post function depending on which group the Reporter belongs to.

 

Example: Say there are two Customers ABC and XYZ. 
ABC has 2 users Sam and Betty.
XYZ has 2 users Tom and Harry. 

What we need is that Sam can see what ticket Betty creates (what users of ABC create) and should not be able to view what all tickets Tom and Harry create(XYZ users).

Is this possible using your solution?

Alex Suslin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 20, 2016

You can change multiple user picker to multiple group picker and put Sam's group in that field. (you can even make a postfunction to fill visible for field with sam's group)

Rupa Jain April 13, 2017

Is it possible to make this Group Picker field non-searchable when using Advanced JQL?

I tried using the 'Search Template' but it does not work.

0 votes
Alex Suslin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 19, 2016

I will propose the solution I have implemented in my company in the answer section, cause select one of 300 security levels from the dropdown will be a headache.

0 votes
Rupa Jain December 19, 2016

We have that many different customers using the same project and hence need that many levels so that they cannot see tickets created by other Customers.

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 19, 2016

issueSecurityLevelManager.createIssueSecurityLevel(scheme.id, "Private", "Reporter only")

But, agree with Alex.

Rupa Jain December 19, 2016

Jamie,

I tried the following:

import com.atlassian.jira.issue.security.IssueSecurityLevelManager

IssueSecurityLevelManager issueSecurityLevelManager;
issueSecurityLevelManager.createIssueSecurityLevel(11238,"Sample Level","Example")

But getting an error : Cannot invoke method createIssueSecurityLevel() on null object

Also is there a way to add group-name or multiple group-names to Security levels?

Rupa Jain December 20, 2016

I had previously used Jelly to accomplish this:

<JiraJelly xmlns:jira="jelly:com.atlassian.jira.jelly.enterprise.JiraTagLib">
<jira:CreateIssueSecurityScheme name="FRIDAY ISSUE SCHEME">
<jira:AddIssueSecurityLevel name="Test level1" description="">
<jira:AddIssueSecurity type="group" group="abc-users"/>
<jira:AddIssueSecurity type="group" group="xyz-users"/>
</jira:AddIssueSecurityLevel>
</jira:CreateIssueSecurityScheme>
</JiraJelly>


Looking to find its alternative within Scriptrunner.

Thanos Batagiannis _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 21, 2016

You have to get the IssueSecurityLevelManager via ComponentAccessor 

def issueSecurityLevelManager = ComponentAccessor.getIssueSecurityLevelManager()
0 votes
Alex Suslin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 19, 2016

woah! 300 security levels on a single scheme? Don't you want to re-think the architecture? 

Suggest an answer

Log in or Sign up to answer