Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do I create AND populate an Issue Security Level with permissions via API?

Guilherme Peres October 20, 2014

I'm trying to programatically create some issue security levels with my Java plugin, and it's working well by using the IssueSecurityLevelManager's createIssueSecurityLevel method. However, it would be even better if I could populate that level with actual permissions, be it with groups, roles or user fields. Is there any practical way to do that using the same API?

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Andreas Ebert
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.
October 20, 2014

If you have a valid JIRA license, then I suggest you take a look at the JIRA sources and how it is done there in com.atlassian.jira.web.action.admin.issuesecurity.AddIssueSecurity#doExecute, i.e.:

IssueSecuritySchemeManager issueSecuritySchemeManager;
Long mySchemeId;
Long myLevelId;
String type; // see SecurityTypeManager#getSecurityTypes and permission-types.xml
String parameter; // type-specific, e.g. the group name if type=="group"
issueSecuritySchemeManager.createSchemeEntity(
		issueSecuritySchemeManager.getScheme(mySchemeId),
		new SchemeEntity(type, parameter, myLevelId)
	);
Guilherme Peres October 21, 2014

That worked like a charm, thank you very much! However, is there a way to fetch the IssueSecuritySchemeManager without using the deprecated ManagerFactory class? It still works, but I don't think it's recommended.

Andreas Ebert
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.
October 21, 2014

Yes, as the class javadoc of ManagerFactory[1] states, you should use ComponentAccessor instead. Or even better, use Constructor Injection[2] (if applicable): Simple place the manager/service as a parameter in the constructor of your class. [1] https://docs.atlassian.com/jira/latest/com/atlassian/jira/ManagerFactory.html [2] http://en.wikipedia.org/wiki/Dependency_injection#Constructor_injection

TAGS
AUG Leaders

Atlassian Community Events