Facing error when calling "getOrganizations" method as customer

We have configured a validator (using Groovy) to return true only if the customer belongs to an organization of the project. When we are using getOrganizations method of OrganizationService, it works as expected for agent but we are facing the below error for customers (even if they belong to an organization of the project), but as per the documentation, if the user is not an agent, the resource should return a list of organizations the user is a member of. :

com.atlassian.servicedesk.api.ForbiddenException: You don't have permission to access this Service Desk.
	at com.atlassian.servicedesk.internal.api.util.EitherExceptionUtils.httpStatusCodeToException(EitherExceptionUtils.java:91)
	at com.atlassian.servicedesk.internal.api.util.EitherExceptionUtils.lambda$anErrorEitherToException$0(EitherExceptionUtils.java:36)
	at io.atlassian.fugue.Either$Left.fold(Either.java:586)
	at com.atlassian.servicedesk.internal.api.util.EitherExceptionUtils.anErrorEitherToException(EitherExceptionUtils.java:32)
	at com.atlassian.servicedesk.internal.feature.organization.api.OrganizationServiceImpl.getOrganizations(OrganizationServiceImpl.java:66)
	at com.atlassian.servicedesk.api.organization.OrganizationService$getOrganizations$0.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:135)

We have also tried using “runInCustomerContext” of “CustomerContextService”, (as per this page) but same error. Lastly, we’ve tried to wrap the call in a “asUser” block with a SD Agent user as a parameter, but no luck.

The code which we have configured in validator :

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.servicedesk.api.ServiceDeskManager
import com.atlassian.servicedesk.api.organization.OrganizationService
import com.atlassian.servicedesk.api.util.paging.SimplePagedRequest

ServiceDeskManager serviceDeskManager = getComponent(ServiceDeskManager)
OrganizationService organizationService = getComponent(OrganizationService)

def projectObject = ComponentAccessor.getProjectManager().getProjectByCurrentKey(issue.get("project")?.key)
def currentUser = issue.get("reporter")
def serviceDeskProject = serviceDeskManager.getServiceDeskForProject(projectObject)
def serviceDeskId = serviceDeskProject?.id as Integer
def organizationsQuery = organizationService.newOrganizationsQueryBuilder().serviceDeskId(serviceDeskId).build()

def orgs = organizationService.getOrganizations(currentUser, organizationsQuery)
return !!orgs.getResults()

Is this behaviour expected for customers? or am I missing something here?

Thanks,
Suprija

1 Like