Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Hide fields GLOBALLY based on Group

Mathias HD November 16, 2021

Hi,
i have a interesting case where i try to hide a Field based on Group membership.
It is very important that the field is only shown to People of a certain group over a number of different Projects but it must be hidden to everyone else no matter project member ship or not. Only the Global group membership counts.

So far i tried Scriptrunner Behaviors and they work fine to hide the field if the current user is not in the defined Group BUT if i search for the Issue and use the Field in my columns i easily get access to the field and view its values.

So i tried the Script runner custom Fields and there i can set the value based on group member ship. So the value is only shown if i'm a member of the configured group.

So now i need to fuse both fields functions. The field should be filled by conventional methods but only show the value if the Group membership is correct and checked via the Script in the scripted field.
Is it possible to set the value in the Custom Scriptrunner field and keep it there and just toggle if its view able or not?

Here is my WIP:

import com.atlassian.jira.component.ComponentAccessor

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def isinGroup = ComponentAccessor.getUserUtil().getGroupNamesForUser(user.name).contains("Can_View_Field")

if(isinGroup)
{
return "ValueSetBefore/SavedValue"
}
else
{
return "REDACTED"
}

Or do i need to fill the field each time the Field is shown/called?

1 answer

0 votes
Florian PEREZ
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 Leaders.
November 16, 2021

Hello  !  

I might have wrong but I think for doing this you should use Scriptrunner behaviour instead of scripted field.  

You should be able to select you fields you need to hide and provide the condition in order to make them visible if user is in the right group. 

The following link is not exactly the same case but I think you can build up arround to get this working : behaviour case 

One other solution (but it is waaaaaay worse) can be to add an AJS into the description of each field to hide them conditionally but I do not recommand this.  

Have fun ! 

Mathias HD November 17, 2021

Hi,

thanks for the hint!
The problem with Behaviors here is they only count in specific screens or view.
As soon as somebody searches for the Issues they can get the stored values anyway.
The Globally is an Important part here.
As we generate the Value from a outside source in this case, i could just put the logic of filling the field inside the:
if(isinGroup)
{
return "Logic to fill the field from external source each time the field gets viewed"
}
But i think this will be highly unpractical and inperfomant.

Best Regards!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events