I have a case where I need to hide the "Create" button in just ONE project. Using script fragments, I was able to hide the clone and move menu items without fail BUT when I try the same thing with the "Create" button, JIRA constantly throws the following in the log file. It WORKS the error shows every couple of seconds
[c.o.scriptrunner.fragments.JiraScriptCondition] Script condition failed: java.lang.NullPointerException
I select the "com.atlassian.jira.jira-header-plugin:create-issue" module key to hide. The code I put in is:
import com.atlassian.jira.component.ComponentAccessor
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def allowedUser = ComponentAccessor.groupManager.getGroupNamesForUser(currentUser).contains("AllowedGroup")
jiraHelper.project?.key != "TARGETPROJECT" || allowedUser
So... (to my tiny mind and appears to function as such), IF the project is not "PROJECT" OR the current user is allowed (even if IN "PROJECT"), the Create button shows. Conversely, if I am IN "PROJECT" and I AM an allowed user, it will show. If I am in PROJECT and NOT an allowed user, it does not show.
To validate the logic, I put it in the Script console with a small change to test with as such (where I am an "allowed user"):
import com.atlassian.jira.component.ComponentAccessor
def project = "TARGETPROJECT"
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def allowedUser = ComponentAccessor.groupManager.getGroupNamesForUser(currentUser).contains("AllowedGroup")
project != "TARGETPROJECT" || allowedUser
The above throws no errors and only the expected "true" or "false" depending on whether I am an "allowed user" depending on which group I set
Anyone have any clues? This is driving me mad (a short drive to be sure)
Try to write like this
import com.atlassian.jira.component.ComponentAccessor
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def allowedUser = ComponentAccessor.groupManager.getGroupNamesForUser(currentUser).contains("AllowedGroup")
jiraHelper?.project?.key != "TARGETPROJECT" || allowedUser
Hey Alexey,
Thanks for the quick answer. HOWEVER, I tried it as you put it in there (substituting back in the "real" group and project name. As before, it works BUT throws the error about every 2s:
http-nio-8080-exec-639 ERROR anonymous 990x6405302x1 - 172.26.10.19,127.0.0.1 / [c.o.scriptrunner.fragments.JiraScriptCondition] Script condition failed: java.lang.NullPointerExceptionAny thoughts?
Any thoughts? I have been forced (for the nonce) to run behind an NGINX proxy. Could that be giving me the problem?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you change the script to this one
import com.atlassian.jira.component.ComponentAccessor
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
log.error("Current user: " + currentUser)
def allowedUser = ComponentAccessor.groupManager.getGroupNamesForUser(currentUser).contains("AllowedGroup")
log.error("allowed User: " + allowedUser)
jiraHelper?.project?.key != "TARGETPROJECT" || allowedUser
and see the logs?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think the problem is with the currentUser because you execute your script under anonymous user.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm... Could be... I find that in the console it knows who *I* am if I try it in there and gives the expected true/false responses depending on what arguments I put in the script.
As much as I am loathe to hard code anything, should I, rather fill in actual humans rather than ask who is on the system at the moment? Perhaps it IS seeing it for things that come in via the API.
Conversely, should I put an explicit please ignore anonymous and what would the groovy look like for that?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you run the script I provided. In my case I get the user under which I am authenticated to Jira.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yup, @Alexey Matveev, you've hit the nail on the head. It IS the anonymous user:
http-nio-8080-exec-630 ERROR anonymous 1033x6421258x1 - 172.26.10.19,127.0.0.1 / [c.o.scriptrunner.fragments.JiraScriptCondition] Current user: null
How might I code to ignore the null/anonymous user?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.component.ComponentAccessor
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
log.error("Current user: " + currentUser)
if (currentUser != null) {
def allowedUser = ComponentAccessor.groupManager.getGroupNamesForUser(currentUser).contains("AllowedGroup")
log.error("allowed User: " + allowedUser)
jiraHelper?.project?.key != "TARGETPROJECT" || allowedUser
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well... that DID fix the continuous errors on null.. However (and I could live with this if I had to), it throws a pair of errors when navigating into and then out of the project with the hidden "Create" button
2018-01-30 18:27:53,996 http-nio-8080-exec-675 ERROR anonymous 1107x6486713x2 uvyzdk 172.26.10.103,127.0.0.1 /browse/HIDDEN [c.a.j.w.f.steps.requestcleanup.WebworkActionCleanupStep] Thread corrupted! ActionContext still references a HttpRequest. URL: 'https://companyURL.com/browse/HIDDEN'. Attempted to clean up: true
2018-01-30 18:27:57,928 http-nio-8080-exec-677 ERROR anonymous 1107x6486787x2 uvyzdk 172.26.10.103,127.0.0.1 /browse/VISIBLE [c.a.j.w.f.steps.requestcleanup.WebworkActionCleanupStep] Thread corrupted! ActionContext still references a HttpRequest. URL: 'https://companyURL.com/browse/VISIBLE'. Attempted to clean up: true
Something to live with or is there another module I should hide besides just the "com.atlassian.jira.jira-header-plugin:create-issue" module?
Further info: In looking at it, it SEEMS that the projects that throw the error are those that include the group that should be able to see the "Create" button in the project it is conditionally hidden...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Unfortunately I can not recreate your example in my Jira. In my Jira I have no errors and the current user is the user under whom I log in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think your extension is the correct one. It works but just that error. I greatly appreciate all your help on this. I suspect it is something that I'll eventually uncover. When I took over this system when moving to this company, I basically inherited a dumpster fire with extra hobos. At least I have the hobos mostly at bay...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.