Hello, everyone
I added new custom web item via sciptrunner in jira. It should be shown only when current user didn't have permission to browse project.
My condition (is not work):
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.plugin.ProjectPermissionKey
import com.atlassian.jira.project.Project
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
Project project = jiraHelper.project
def permissionManager = ComponentAccessor.getPermissionManager()
ProjectPermissionKey browse_projects = new ProjectPermissionKey("BROWSE_PROJECTS")
def hasPerm = permissionManager.hasPermission(browse_projects, project, currentUser)
(!hasPerm)
I guess the problem is jiraHelper return the last project that user used/browsed when user has not permission to browse current project .
Is it any other solution I can use in the condition to define project correctly?
Hi @Айри Мизуно where do you want to display this Web Item? What context is set?
Hi @Martin Bayer _MoroSystems_ s_r_o__
On the system.top.navigation.bar. I added custom web item (button) that run code and display dialog. The code is the rest endpoint indicated on link. Maybe it could be define the current project in the rest endpoint?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you try to log "project" value? I'm not sure that "system.top.navigation.bar" has Project in its context.
What should your action do? Is it really so 'genera' action that it make sense to have it as part of the top bar?
But first, I would add logging and you can check that project value is present.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.plugin.ProjectPermissionKey
import com.atlassian.jira.project.Project
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
Project project = jiraHelper.project
log.error(project)
def permissionManager = ComponentAccessor.getPermissionManager()
ProjectPermissionKey browse_projects = new ProjectPermissionKey("BROWSE_PROJECTS")
def hasPerm = permissionManager.hasPermission(browse_projects, project, currentUser)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, @Martin Bayer _MoroSystems_ s_r_o__
Yes, I tried to log before. I passed the value of project as parameter in the link to REST endpoint and logs the value of parameter in the code of endpoint.
So I came to the conclusion that every time when I open project which user can't browse jiraHelper return the last project that user browsed. It seems like jiraHelper can't get project if user can't browse project and returns previous value.
I added logs as you advised. Result is the same.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, @Martin Bayer _MoroSystems_ s_r_o__
Yes, I tried to log before. I passed the value of project as parameter in the link to REST endpoint and logs the value of parameter in the code of endpoint.
So I came to conclusion that every time when user open project which he can't browse jiraHelper return the last project that user browsed. It seems like jiraHelper can't get project if user can't browse project and returns previous value.
I added logs as you advised. Result is the same.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Айри Мизуно what is the use case? Does it make sense to invoke condtition based on the project on top bar? It is safer to have functionality for "project" in "project context"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I'm not sure that web item shown for "project" in "project context" if user couldn't browse project. I'll check.
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are right, it won't work probably. CAn you describe your use case please? It's hard to think about it when I don't have context.
Thank you :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The condition isn't matter, the web item will shown anyway. Now I need to define the current project in the web item and pass it to the REST endpoint or in the code of REST endpoint even if the user has no permission to browse.
Web item calls REST endpoint, REST endpoint returns dialog window.
In the dialog window will be a link on which user can go and create issue. One of the custom fields of issue is should be equal to the "defined project". I would like to preset the value of this field.
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.