I am trying to find issues in a project a JSM Customer Can see.
Using the Search Service with the Customers ApplicationUser gives 0 issues.
So I am trying to seach with a jira user and find issues the JSM Customer can see (I have verified on the portal the Customer can see issues:
// 1. Get the necessary components
def searchService = ComponentAccessor.getComponent(SearchService)
def userManager = ComponentAccessor.getUserManager()
def permissionManager = ComponentAccessor.getPermissionManager()
def browsePermission = new ProjectPermissionKey("BROWSE_PROJECTS")
// 2. Define the user (the JSM Customer) and the query
ApplicationUser automation = userManager.getUserByKey("automation")
ApplicationUser customer = userManager.getUserByName("bnp@mos-eisley.dk")
def jqlSearch = "project = SUPPORT"
if (customer) {
// 3. Always validate the query for the specific user first
def parseResult = searchService.parseQuery(automation, jqlSearch)
if (parseResult.isValid()) {
// 4. Execute the search within the customer's permission context
def searchResults = searchService.search(automation, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
def issues = searchResults.getResults()
issues.each { issue ->
if (permissionManager.hasPermission(browsePermission, issue, customer))
{
log.warn("Customer can see: ${issue.key} - ${issue.summary}")
}
else
{
log.warn("Customer cant see: ${issue.key} - ${issue.summary}")
}
}
} else {
log.error("Invalid JQL for this user: " + parseResult.getErrors().getErrorMessages())
}
} else {
log.error("User not found.")
}