Is a user a Service Desk agent

agent

#1

Hi, is it possible to determine if a user is a Service Desk agent. I see that there is a jira-servicedesk-users group but I’m not sure how bullet proof this is

Thanks
Paul


#2

Doe this maybe help: https://confluence.atlassian.com/jirakb/how-to-retrieve-application-access-of-a-user-in-jira-940695257.html ?


#3

Or this Java API: https://docs.atlassian.com/jira-servicedesk/3.8.1/com/atlassian/servicedesk/api/permission/ServiceDeskPermissionService.html#isAgent-com.atlassian.jira.user.ApplicationUser-com.atlassian.servicedesk.api.ServiceDesk-


#4

Hi @tobitheo, for the Rest API, that could be good as long as having the application role jira-servicedesk means you are an agent. I’ll have a look around and see what I can find. Would probably try something similar using the appropriate Java manager class

Thanks
Paul


#5

Hi @tobitheo, for the ServiceDeskPermissionService interface I had actually tried that earlier (probably should have mentioned it :slight_smile: ). I tried to get it using the ServiceDeskComponentAccessor class. My problem with that was it has to all be done using reflection because the plugin may be in a non-service desk instance of Jira (so I can’t use the usual autowiring). I kept getting class not found errors even though the Jira instance had Service Desk. Any ideas for this?

Thanks
Paul


#6

The Servicedesk plugin is also just a plugin and as such, it can happen that it starts after your plugin.
You’ll have to check for its availability every time you try to access it.


#7

When I was trying to access everything had been running for quite a while. I’m not sure if something is needed in the atlassian-plugin.xml but if it does then that probably wouldn’t work with non service desk Jira.

I’ll dig around in the application access stuff and see what I can find

Thanks
Paul


#8

Here’s some code we use to try and get the OrganizationService, maybe it helps:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.plugin.osgi.container.OsgiContainerManager;
import com.atlassian.servicedesk.api.organization.OrganizationService;
import org.osgi.util.tracker.ServiceTracker;

// ... later:

        OsgiContainerManager osgiContainerManager = ComponentAccessor.getComponentOfType(OsgiContainerManager.class);
        ServiceTracker serviceTracker = osgiContainerManager.getServiceTracker("com.atlassian.servicedesk.api.organization.OrganizationService");
        if(serviceTracker == null) {
            // Not available
        } else {
            Object service = serviceTracker.getService();
            if(service != null && service instanceof OrganizationService) {
                // Service is available, do something with it
            } else {
                // Service is null or no OrganizationService
            }
        }

#9

Thanks @tobitheo, I’ll give it a go

Thanks
Paul


#10

Ok that worked great for getting an instance of com.atlassian.servicedesk.api.permission.ServiceDeskPermissionService, now all I have to do is figure out how to get the com.atlassian.servicedesk.api.ServiceDesk for the project which shouldn’t be too hard.

Thanks for your help, much appreciated
Paul