Getting Reporter's Customer Organization Membership in ScriptRunner

Good morning.


I am trying to add automation that tests an issue reporter's membership in a customer organization.

I'm using the OrganizationService is com.atlassian.servicedesk.api.organization and the getById method, where I pass in the reporter's ApplicationUser object and specific customer organization IDs I wish to test against.

 

I'm getting a response of 'sd.customer.organisation.error.user.no.view.permission : 'You do not have permission to view this organization'

 

This response makes sense to me, the reporter I am passing in is not yet trusted. That is what I am trying to determine.

 

How can I, as a trusted automation/administrator, query the customer organization membership of the reporter?

1 answer

Hi James, 

The use of the OrganizationService.getById() seems ok, but I am not sure that gives you the result you want 

Quoting their javadocs (which make no sense)

/**
* Checks whether the user is an agent or a member of the organization. True if
* - valid licensed,
* - is a member if the organization
*
* @param user the user who you want to check
* @param organizationId the ID of the organization you want retrieve.
* @return the organization.
*/

But I believe the error you get it may has to do with permissions that the logged in user has (or in your case has not) and not the reporter

Apart from that could you please try the following script (check your logs for the debug messages or errors )?

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.servicedesk.api.organization.OrganizationService

def loggedInUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def issue = ComponentAccessor.issueManager.getIssueByCurrentKey("ATG-1") //the issue to get the reporter from
def reporter = issue.reporter

def organisationService = ComponentAccessor.getOSGiComponentInstanceOfType(OrganizationService)
def organizationQuery = organisationService.newOrganizationsQueryBuilder().serviceDeskId(1).build()

def organizationsInProjectResult = organisationService.getOrganizations(loggedInUser, organizationQuery)
if (organizationsInProjectResult.isLeft()) {
log.error organizationsInProjectResult.left().get()
return
}

def organizationA = organizationsInProjectResult.right().get().results.find {it.name == "OrgA"}
log.debug "Organization is $organizationA"


def usersInOrganizationQuery = organisationService.newUsersInOrganizationQuery().customerOrganization(organizationA).build()

def usersInOrganization = organisationService.getUsersInOrganization(loggedInUser, usersInOrganizationQuery)
if (usersInOrganization.isLeft()) {
log.error usersInOrganization.left().get()
return
}

def isUserInOrganization = usersInOrganization.right().get().results.find {it.key == reporter.key} ? true : false
log.debug "Is user in organizaion ? $isUserInOrganization"

Regards, Thanos

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Monday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

598 views 6 12
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