JIRA Scripting, Plugin and Report Development, ScriptRunner & Tempo tips
Limiting report display to a project or user group
Written on August 14, 2016
We needed to display JIRA report only in a certain project and for users in specific groups. The group part was easy, but getting current project’s key was not.
I found several solutions on the internet, but none of them worked. In the end I used a combination of parsing HTTP request and the UserProjectHistoryManager class.
To hide or show a report, you simply return true or false in report’s showReport() method.
To check whether current user belongs to a group I created a simple method:
Now the project key. I got it using the UserProjectHistoryManager.getProjectHistoryWithoutPermissionChecks() method, but it doesn’t immediately reflect changing the project from the main menu.
So I combined it with extracting the key directly from the HTTP request.
I did not find a way to get UserProjectHistoryManager using ComponentAccessor, so I used @Scanned annotation on the class and @ComponentImport in the report’s constructor for it to be injected automatically. There was no need to import UserProjectHistoryManager in atlassian-plugin.xml on JIRA 7, but it seems it might be necessary in older versions.
This is the method for getting current project’s key:
To show the report only for project “PRJ” and the “managers” group, I called the above methods like this:
This is the final class with all methods combined:
Comments