Forums

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

Can ScriptRunner bulk change the viewers of a set of filters?

Jeremy Jedlicka
Contributor
April 13, 2022

I have a large set of filters that have been created by users within my project and I was just asked if it's possible to make all of these viewable by everyone logged in.  Is this possible?  I know ScriptRunner has the built-in function to bulk change ownership, but I want to leave to filter owner as the user.

Any suggestions to point me in the right direction?

1 answer

1 vote
PD Sheehan
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.
April 22, 2022

Yes, that's possible with scriptrunner.

Here is a short script I've prepared.

import com.atlassian.jira.bc.JiraServiceContextImpl
import com.atlassian.jira.bc.filter.SearchRequestService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.sharing.SharePermissionImpl
import com.atlassian.jira.sharing.SharedEntity
import com.atlassian.jira.sharing.rights.ShareRights
import com.atlassian.jira.sharing.type.ShareType
import com.atlassian.jira.user.ApplicationUser

//you need to find and update the filters user an system admin priviledged user in case the current user doesn't have permission to adjust a filter
ApplicationUser adminUser = ComponentAccessor.userManager.getUserByName('admin')
JiraServiceContextImpl serviceContext = new JiraServiceContextImpl(adminUser)
SearchRequestService searchRequestService = ComponentAccessor.getComponent(SearchRequestService)

def filtersToChange= [12345, 23456] //list all the filters you want to change

filtersToChange.each{filterId ->
def filter = searchRequestService.getFilter(serviceContext, filterId)
//get all the current permission (but no the view permission, this will be replaced by the Authenticated one)
def perms = filter.permissions.permissionSet.collect().findAll{it.rights != ShareRights.VIEW}
//the new permission we will be adding
def authenticatedPerm = new SharePermissionImpl(null, ShareType.Name.AUTHENTICATED,null,null, ShareRights.VIEW)
perms.add( authenticatedPerm)

filter.setPermissions(new SharedEntity.SharePermissions(perms.toSet()))
searchRequestService.updateFilter(serviceContext, filter)
}



Adam Rypel _MoroSystems_
Community Champion
December 7, 2022

Works perfectly, thanks.

Suggest an answer

Log in or Sign up to answer