How to write the code to verify the customer permission using CustomerContextService

All,

Jira server app:
I have written the plugin module on the post function and updating the reporter when transitioned the ticket.
this postfunction is used in jira projects as well service desk projects.
So the issue is that the below code uses the service desk api to find the permissions on the customers. One way I got the customerContextService object using constructor injection but problem to using this way if I do not have service desk application installed. so this code is breaking.

I was trying avoid injection and try loading as below but not getting the object.
I really appreciate all your opinions and suggestions. thanks.

CustomerContextService customerContextService = ComponentAccessor.getComponent(CustomerContextService.class);
b = customerContextService.runInCustomerContext(new NoExceptionsCallable<Boolean>(){
    @Override
    public Boolean call() {
		boolean 	b = permissionManager.hasPermission(CREATE_ISSUES, project, applicationUser);
		Util.showLogMessage(applicationUser,project,b,Constants.REPORTER);
		return 	b;
	}
});

Hi!

Just wanted to say thanks for this post! It helped me with my approval problem! I just wanted to add that, in our case
CustomerContextService customerContextService = ComponentAccessor.getComponent(CustomerContextService.class);
returned null for customerContextService. We changed it to:
CustomerContextService customerContextService = ComponentAccessor.getOSGiComponentInstanceOfType(CustomerContextService.class);
and it worked fine!

Is that an ok way?

Cheers,
Marina

It is fine. One thing to make sure to handle the code with/with out jira service desk application.

1 Like