How to restrict custom report visibility?

hi, here's the thing.

We have a couple of projects created in JIRA. Let's say they are proj1 and proj2.

Now we developed a plugin with a couple of report modules in it. Let's say they are rpt1 and rpt2.

After installed the plugin to JIRA, both rpt1 and rpt2 show in the report menu of proj1 and proj2.

But what we want is that only rpt1 appears in the report menu of proj1 and only rpt2 appears in the report menu in proj2.

For now I already know that there's a method showReport() in AbstractReport class returing true or false to control report to show or not. My idea is to get the current projectId to determine whether the report should show or not. The problem is that I don't know how to get the current project id in my extended report class.

Is there anyone can help? Thanks in advance.

Here's my custom report code:

public class TurnaroundTimeReport extends AbstractReport {
 
    @Override
    public String generateReportHtml(ProjectActionSupport projectActionSupport, Map map) throws Exception {
        return descriptor.getHtml("view", getVelocityParams(projectActionSupport, map));
    }
 
    private Map<String, ?> getVelocityParams(ProjectActionSupport action, Map map) {
        ...
        ...
        final List<Map> turnaroud = getTurnaroundTimeFromProject(yearmonth, customer);
        final Map<String, Object> velocityParams = new HashMap<String, Object>();
        velocityParams.put("report", this);
        velocityParams.put("action", action);       
        velocityParams.put("turnaround", turnaroud);        
        return velocityParams;
    }
 
    @Override
    public boolean showReport() {
    // I want to get the current project id here to determine whether the report should show or not.    
    return true
    }
    
    @Override
    public boolean isExcelViewSupported() {
        return true;
    }
 
    @Override
    public String generateReportExcel(ProjectActionSupport action, Map params) {
        final StringBuilder builder = new StringBuilder(50);
        builder.append("attachment;filename=\"");
        builder.append(getDescriptor().getName());
        builder.append(".xls\";");
        HttpServletResponse response = ActionContext.getResponse();
        response.addHeader("content-disposition", builder.toString());
        return descriptor.getHtml("excel", getVelocityParams(action, params));
    }
  
    private List<Map> getTurnaroundTimeFromProject(int yearmonth, String customer) {
        ...
        ...
        return turnaround;
    }
}


					
				
			
			
			
				

2 answers

1 accepted

You can get the current project with UserProjectHistoryManager:

UserProjectHistoryManager userProjectHistoryManager =  ComponentAccessor.getOSGiComponentInstanceOfType(UserProjectHistoryManager.class);

Project project = userProjectHistoryManager.getCurrentProject(Permissions.BROWSE, ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser());

Thank you very much, Conrad Rolack. It works.

But i'm using atlassian-plugin-sdk-3.7.2, so i made a little change.

UserProjectHistoryManager userProjectHistoryManager =
ComponentManager.getComponentInstanceOfType(UserProjectHistoryManager.class);

Hello, can you at least show abit of code so that we will know what are the classes that you actually need to use? Its hard to provide help without seeing some code.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

362 views 0 6
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you