<img height="1" width="1" style="display: none" src="https://www.facebook.com/tr?id=976470819114134&amp;ev=PageView&amp;noscript=1">

Sharing your filter editing burdens across the team

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchRequestEntity
import com.atlassian.jira.issue.search.SearchRequestAdminManager
import com.atlassian.jira.issue.search.SearchRequestManager
import com.atlassian.jira.util.Visitor
import com.atlassian.jira.sharing.SharedEntity.SharePermissions
import com.atlassian.jira.sharing.SharePermissionImpl
import com.atlassian.jira.sharing.rights.ShareRights
import com.atlassian.jira.sharing.type.ShareType
import com.google.common.collect.Sets

def filtersWithName = []
def myNameRegex = ~/.*?NA.*?/
def editorGroup = 'NA-Administrators'
def searchService = ComponentAccessor.getComponent(SearchService)
def searchRequestAdminManager = ComponentAccessor.getComponent(SearchRequestAdminManager)
def searchRequestManager = ComponentAccessor.getComponent(SearchRequestManager)
    
def editPermission = new SharePermissionImpl(ShareType.Name.GROUP, editorGroup, null, ShareRights.VIEW_EDIT)

searchRequestManager.visitAll(new Visitor<SearchRequestEntity>() {
 @Override
 void visit(SearchRequestEntity filter) {
	def name = filter.name
 	if (name.findAll(myNameRegex)) {
		def searchRequest = searchRequestManager.getSearchRequestById(filter.id)
        log.warn searchRequest.getPermissions()
 		if (searchRequest.getPermissions().getPermissionSet().contains(editPermission)) {
    		log.warn(searchRequest.getName() + ' already has edit permission for ' + editorGroup)
        } else {
            searchRequest.setPermissions(new SharePermissions(Sets.union(searchRequest.getPermissions().getPermissionSet(), Collections.singleton(editPermission))))
            searchRequestManager.update(searchRequest)
            log.warn searchRequest.getPermissions()
        }
 	}
 }
})



import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.portal.PortalPageManager
import com.atlassian.jira.portal.PortalPage.Builder
import com.atlassian.jira.portal.PortalPage
import com.atlassian.jira.sharing.SharedEntity.SharePermissions
import com.atlassian.jira.sharing.SharePermissionImpl
import com.atlassian.jira.sharing.rights.ShareRights
import com.atlassian.jira.sharing.type.ShareType
import com.google.common.collect.Sets


// This is for a static list of Dashboard IDs that need to have edit rights updated to allow gadgets to be modified.
// You could search for IDs by using the PortalPageManager search function
// see https://docs.atlassian.com/software/jira/docs/api/7.13.1/com/atlassian/jira/portal/PortalPageManager.html

def portalPageManager = ComponentAccessor.getComponent(PortalPageManager)
def output = ""
for (region in ['NA','EU']) {
 def dashboardIDs = []
 def editorGroup = ''
 if (region == 'EU') {
 dashboardIDs = [19432,20234]
 editorGroup = 'EU- administrators'
 } else if (region == 'NA') {
 dashboardIDs = [19410,20300,20812]
 editorGroup = 'NA-Administrators'
 }
 def editPermission = new SharePermissionImpl(ShareType.Name.GROUP, editorGroup, null, ShareRights.VIEW_EDIT)
 
 for (id in dashboardIDs) {
 // 1. Get portal page
 def portalPage = portalPageManager.getPortalPageById(id)
 
 // 2. Get permissions
 // output = portalPage.getPermissions().getPermissionSet().toString()
 // 3. Create new portal page with new permission
 
 def newPortalPage = new PortalPage.Builder().
 /* .description(portalPage.getDescription())
 .favouriteCount(portalPage.getFavouriteCount())
 .layout(portalPage.getLayout())
 .name(portalPage.getName())
 .owner(portalPage.getOwner()) */
 portalPage(portalPage).
 permissions(new SharePermissions(Sets.union(
 portalPage.getPermissions().getPermissionSet(), 
 Collections.singleton(editPermission)))).
 build()
 
 
 output += id +": " + newPortalPage.getPermissions().getPermissionSet().toString() + "\n"
 
 // 4. Update portal page
 portalPageManager.update(newPortalPage) 
 }
}
output