Forums

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

Issue Manager getIssueObject oddity

Ron Gates
Contributor
April 4, 2017

I was working on script for a Custom Listener (using Jira 7.3 and ScriptRunner 4.3) and noticed that following piece of code works:

import com.atlassian.jira.component.ComponentAccessor

def issueKey = "JIRA-1234";
def issueManager = ComponentAccessor.getIssueManager()
def issueObject = issueManager.getIssueObject("JIRA-1234")
def issueObjectID = issueObject.getId()


But when:

def issueObject = issueManager.getIssueObject("KEY-1234")


is being replaced by:

def issueObject = issueManager.getIssueObject(issueKey)


The code just assigns null to the issueObject variable and code returns following error:

java.lang.NullPointerException: Cannot invoke method getId() on null object

 

So in other words when the issue key is used directly as parameter for getIssueObject method - the code works. But when variable is used as a parameter - the code doesn't work.

Any idea why this is happening?

In the meantime, I have circumvented this problem using Search Provider (I share workaround in case somebody has similar problem and needs working solution):

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.web.bean.PagerFilter

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser);
def searchProvider = ComponentAccessor.getComponent(SearchProvider);
def authContext = ComponentAccessor.getJiraAuthenticationContext();
def issueKey = "JIRA-1234";
def jqlQuery = jqlQueryParser.parseQuery(issueKey);
def user = authContext.getLoggedInUser();
def results = searchProvider.search(jqlQuery, user, PagerFilter.getUnlimitedFilter());
def issues = results.getIssues();
def issueObject = issues[0];
def issueObjectID = issueObject.getId();

 

But still would like to know why getIssueObject method is not working with string variable.


Thanks in advance for clarifying this oddity for me!

2 answers

2 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Nic Brough -Adaptavist-
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 Champions.
August 14, 2023

Scriptrunner can't do this because there's no function in Confluence that does this.  Unless a macro app codes for "only allow in certain spaces", there's no way to do it.

Stefan Salzl
Community Champion
August 14, 2023

Thanks for your time and answer @Nic Brough -Adaptavist- 

highly appreciated. I was afraid this would not be possible but I thought: "well let´s give it a shot"

Best
Stefan

Like Nic Brough -Adaptavist- likes this
Nic Brough -Adaptavist-
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 Champions.
August 14, 2023

Always worth asking!

Like Stefan Salzl likes this
0 votes
Answer accepted
Radek Dostál
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 Champions.
August 14, 2023

Not as far as I know. Why does the macro show any 3rd party data though? That sounds rather weird to me.

Stefan Salzl
Community Champion
August 14, 2023

Any (kinda) connector makro shows data from another system even if it´s only the jira-macro in confluence (which shows eg. issue data from jira).

In this case it´s really another software where the macro communicates via API. 

IMHO permisssion or at least read/edit config should be possible within the addon-config and there should not be a need for this question here =S

Thanks for your time and question anyways.

Best
Stefan

Radek Dostál
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 Champions.
August 14, 2023

Well, jira issue macro (provided that it's the native one based off Application Links) will respect the user's permissions. If they can see any issues, then that means they can log in to jira and browse them. So, not really a leak.

Unauthorized user which doesn't have access to those issues won't see them.

 

You still haven't told us what macros / 3rd party app it is, so hard to tell.

Either way, if a macro contains hardcoded credentials in the background to authenticate to some remote app, then it's a bad macro and you should tell the vendor your use case so they can implement either restrictions, or support per-user data.

Macros are supposed to be generic, ask for parameters. No macro should just show some magical content from somewhere without respecting the user's permissions, and this is respected both within Confluence content as well as Application Links. This really sounds more like a vendor's oversight, not a Confluence one.

Like Stefan Salzl likes this
Stefan Salzl
Community Champion
August 14, 2023

Maybe jira was not the best example as other apps/connectors from outside of the atlassian universe use technical application users. never mind. 

Thanks for your time.

Stefan Salzl
Community Champion
August 14, 2023

Hi @Radek Dostál 

sorry, forgot to mention the addon as it is a vendor/company mainly action regional in German speaking area:
https://marketplace.atlassian.com/apps/1224860/adoit-enterprise-architect-for-confluence?hosting=cloud&tab=overview

 

AND: YES, I fully agree. As mentioned before an addon should absolutly respect/enable user´s permission.

Best
Stefan

TAGS
AUG Leaders

Atlassian Community Events