Forums

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

Bulk edit filter/board/structure owner from a specific user into a group due to the fact when the fi

Gilad Shtern
Contributor
October 19, 2022

Hi,

I'd like to bulk edit filter/board/structure owner from a specific user into a group due to the fact when the filter is not available when a owner is on inactive state.

However, I didn't managed to do so via:

1.Filter bulk

2.Update filter share permission by API.

 

Ver: DC 8.22.16

Kindly,

Gilad

 

1 answer

0 votes
Rilwan Ahmed
Community Champion
October 19, 2022

Hi @Gilad Shtern ,

You can change owner of the filters and Dashboard one by one from Administration settings --> System --> SHARED ITEMS.

 image.png

Gilad Shtern
Contributor
October 19, 2022

Hi @Rilwan Ahmed 

One by one, is not an option when we need to change lot of filter or boards.

Kindly,

Gilad

Tom Lister
Community Champion
October 19, 2022

HI @Gilad Shtern 

Do you have a scripting app like scriptrunner to perform this?

Gilad Shtern
Contributor
October 19, 2022

Hi Tom,

You probably want to use: Change dashboard ownership build in script.

However, this option allow you to switch into another user. 

I'd like to switch from a user into a group otherwise its meaningles as the 2nd will become inactive.

Kindly,

Gilad

Tom Lister
Community Champion
October 19, 2022

Hi Gilad

i have some scripts for changing ownership somewhere.

I’ll try and locate them tomorrow.

Tom Lister
Community Champion
October 20, 2022

Hi Gilad

Try this for as a template ( added to my Github server-dc/Scriptrunner/Admin/permChanges.groovy)

 

import com.atlassian.jira.sharing.type.ShareType

import com.atlassian.jira.sharing.SharedEntity

import com.atlassian.jira.issue.search.SearchRequestManager

import com.atlassian.jira.sharing.SharePermissionImpl

import com.atlassian.jira.sharing.SharePermission

import com.atlassian.jira.bc.filter.SearchRequestService

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.user.util.UserManager

import com.atlassian.jira.issue.search.SearchRequest

import com.atlassian.jira.bc.JiraServiceContextImpl

import com.atlassian.jira.sharing.rights.ShareRights

def userManager = ComponentAccessor.getUserManager()

try {

def ownerUser = userManager.getUserByName("listertuk-admin")

log.warn("LOGGER decomUser " + ownerUser)

def user2 = userManager.getUserByName("listertuk-user2")

log.warn("LOGGER decomUser " +user2)

def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def groupName = "Group1"

SearchRequestService searchRequestService = ComponentAccessor.getComponent(SearchRequestService.class)

SearchRequestManager searchRequestManager = ComponentAccessor.getComponent(SearchRequestManager.class)

def contextImpl = new JiraServiceContextImpl(ownerUser)

Collection<SearchRequest> searchRequests = searchRequestManager.getAllOwnedSearchRequests(ownerUser)

//Collection<SearchRequest> searchRequests = searchRequestService.getOwnedFilters(ownerUser)

if(searchRequests.size() > 0) {

searchRequests.each { s ->

log.warn s

//set owner

//s.setOwner(user2)

Set<SharePermission> permissionsSet = new HashSet<SharePermission>(

s.getPermissions().getPermissionSet()

)

log.warn permissionsSet

permissionsSet.add(new SharePermissionImpl( ShareType.Name.GROUP, groupName, ShareRights.VIEW_EDIT.toString()))

s.setPermissions(new SharedEntity.SharePermissions(permissionsSet))

searchRequestManager.update(loggedInUser, s)

}

} else {

log.warn "LOGGER ${ownerUser.getName()} no filters found."

}

} catch(Exception e) {

log.warn e.getMessage()

}
Gilad Shtern
Contributor
October 23, 2022

Hi Tom,

When I execute your script, I get an error message: "Permission type 'loggedin' must not be included with other permissions" & all viewer/editors deleted.

In addition, I wasn't able to change owner into a group, only for a specific user.

The highlight is to add:

1)A specific group into owner

2)Add group into the editors, as well.

 

Kindly,
Gilad

Tom Lister
Community Champion
October 24, 2022

Hi @Gilad Shtern 

The downside of directly updating Jira via code is that you can bypass some of the checks in the GUI and create unworkable configs. 

Screenshot 2022-10-24 at 11.21.07.png

This works in my server because I rarely add 'Any logged in user' as a permission. When re-test with that set I can recreate your error.

It will be necessary to remove that permission before adding a new View permission. I will update and test my code and repost shortly. Whether this is needed to be removed depends on each case but I'll assume any additions will need to remove type "loggedin" before adding any new perms.

Ownership of the the filter can only be set to a user. VIEW and VIEW_EDIT can be set to groups.

Could you post your amended code?

Tom Lister
Community Champion
October 24, 2022

Hi @Gilad Shtern 

This version will remove the loggedin permission before updating. 

Will add the group to edit permission - I had used the wrong SharePermissionImpl constructor. Also defined groupName specifically as String as that prevented the constructor error being warned.

 

import com.atlassian.jira.sharing.type.ShareType

import com.atlassian.jira.sharing.SharedEntity

import com.atlassian.jira.issue.search.SearchRequestManager

import com.atlassian.jira.sharing.SharePermissionImpl

import com.atlassian.jira.sharing.SharePermission

import com.atlassian.jira.bc.filter.SearchRequestService

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.user.util.UserManager

import com.atlassian.jira.issue.search.SearchRequest

import com.atlassian.jira.bc.JiraServiceContextImpl

import com.atlassian.jira.sharing.rights.ShareRights

def userManager = ComponentAccessor.getUserManager()

try {

def ownerUser = userManager.getUserByName('listertuk-admin')

log.warn('LOGGER decomUser ' + ownerUser)

def user2 = userManager.getUserByName('listertuk-user2')

log.warn('LOGGER decomUser ' + user2)

def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

String groupName = 'Group1'

SearchRequestService searchRequestService = ComponentAccessor.getComponent(SearchRequestService.class)

SearchRequestManager searchRequestManager = ComponentAccessor.getComponent(SearchRequestManager.class)

def contextImpl = new JiraServiceContextImpl(ownerUser)

Collection<SearchRequest> searchRequests = searchRequestManager.getAllOwnedSearchRequests(ownerUser)

if (searchRequests.size() > 0) {

searchRequests.each { s ->

log.warn s

//set owner

//s.setOwner(user2)

Set<SharePermission> permissionsSet = new HashSet<SharePermission>(

s.getPermissions().getPermissionSet()

)

log.warn('start ' + permissionsSet)

try {

def newPerm = new SharePermissionImpl(ShareType.Name.GROUP, groupName, '', ShareRights.VIEW_EDIT)

//log.warn permissionsSet.contains(newPerm)

permissionsSet.add(newPerm)

permissionsSet.forEach() { perm ->

if (perm.type.toString() == 'loggedin') {

//log.warn('loggedin ' + perm.type.toString() == 'loggedin')

//log.warn('before remove ' + permissionsSet.contains(perm))

permissionsSet.remove(perm)

//log.warn('after remove ' + ' ' + perm + permissionsSet)

}

}

} catch (Exception e) {

log.warn('ERROR1 ' + e.getMessage())

}

//log.warn('*(*(' + permissionsSet)

s.setPermissions(new SharedEntity.SharePermissions(permissionsSet))

searchRequestManager.update(loggedInUser, s)

}

} else {

log.warn "LOGGER ${ownerUser.getName()} no filters found."

}

} catch (Exception e) {

log.warn('ERROR2 ' + e.getMessage())

}
Gilad Shtern
Contributor
October 24, 2022

In the end, I switched all into applicable user by using build-in scrpit.

It took some time.

Kindly,

Gilad

David Niro
Atlassian Partner
October 24, 2022

Hello @Gilad Shtern ,

For updating the run as users for your Structure Generators, you can use the script found here.

Hope it helps!

Best,
David

Like Dave Rosenlund _Trundl_ likes this
Tom Lister
Community Champion
October 25, 2022

Hi @Gilad Shtern 

If you need to just bulk change owners the you could uncomment the lines in my script

//set owner

//s.setOwner(user2)

and remove the section on getting an updating permissions. 

Suggest an answer

Log in or Sign up to answer