Forums

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

Custon JQL Function, User in Group from custom field

David Harkins
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.
May 4, 2023

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)

    )

         

}

1 answer

1 accepted

0 votes
Answer accepted
Paul Woolley
July 5, 2018

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.

Suggest an answer

Log in or Sign up to answer