It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Getting Reporter's Customer Organization Membership in ScriptRunner

James Mclellan Nov 20, 2017

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

0 votes
Thanos Batagiannis [Adaptavist] Community Leader Dec 05, 2017 • edited

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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Jira Software

How to prevent the propagation of unused project schemes, workflows & screens in Jira software

Atlassian ranks project attributes as the third most important factor impacting performance in the category of data. It’s not surprising, since project attributes are precisely the rules used to ma...

1,326 views 1 16
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you