Trying to get the following custom JQL Function working in data center.
To compare a custom field and check if its group value is in the list of groups that the current user is a member of.
package com.onresolve.jira.groovy.jql
import com.atlassian.jira.JiraDataType
import com.atlassian.jira.JiraDataTypes
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.operand.QueryLiteral
import com.atlassian.jira.jql.query.QueryCreationContext
import com.atlassian.jira.permission.ProjectPermissions
import com.atlassian.jira.project.version.VersionManager
import com.atlassian.query.clause.TerminalClause
import com.atlassian.query.operand.FunctionOperand
class AssignedToMyGroups extends AbstractScriptedJqlFunction implements JqlFunction {
def versionManager = ComponentAccessor.getComponent(VersionManager)
def permissionManager = ComponentAccessor.getPermissionManager()
@Override
String getDescription() {
"Issues where Group field is one of My Groups"
}
@Override
List<Map> getArguments() {
Collections.EMPTY_LIST // <1>
}
@Override
String getFunctionName() {
"AssignedToMyGroups"
}
@Override
JiraDataType getDataType() {
JiraDataTypes.VERSION // <2>
}
def groupManager = ComponentAccessor.groupManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
final username = loggedInUser.username
@Override
List<QueryLiteral> getValues(
groupManager.getGroupNamesForUser(username)
)
}
Solved this problem in a slightly different way in the end by creating a plain, servlet based JIRA plugin using...
atlas-create-jira-plugin
...instead of a REST API type plugin from...
atlas-create-refapp-plugin
By using the plain, servlet based type of JIRA plugin, there was no authentication filter getting in the way of calling my servlet's doGet method. I was able to have full access to the request and response objects through the doGet method signature:
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
...
}
I was then able to do things like check if the request was from a logged in user with:
ComponentAccessor.getJiraAuthenticationContext().isLoggedInUser()
...and redirect incoming requests for non-logged in users...
resp.sendRedirect("/login.jsp?os_destination=" + URLEncoder.encode(returnUrl, "UTF-8"));N.B. I found that the redirect after the login page would only work if the returnUrl was back to my servlet and not, e.g., Google or somewhere else.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.