Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Facing error when calling “getOrganizations” method as customer

Suprija Sirikonda _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 1, 2021

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

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events