Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How to replace all filter views

Hey, I have the following code that updates all the filters in our Jira instance to ADD the view "All logged in users", but I'm running into difficulties when a filter already has a specified view. This script clashes with that and Jira gives the warning that "all logged in users view cannot be used with others. 

I've been searching how to modify this code to replace all current views instead of add, but haven't had any luck.  I'm thinking the offending line of code is:

permissionsSet.add(new SharePermissionImpl(Name.AUTHENTICATED, null, null));

Can anyone help modifying this to REPLACE all views, and not merely ADD an new view?

Here is my full script:

import com.atlassian.jira.sharing.SharePermissionImpl
import com.atlassian.jira.sharing.SharePermission
import com.atlassian.jira.sharing.SharePermissionImpl
import com.atlassian.jira.sharing.SharedEntity.SharePermissions
import com.atlassian.jira.sharing.type.ShareType.Name
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.filter.SearchRequestService

def userSearchService = ComponentAccessor.getComponent(UserSearchService)
def userSearchParams = new UserSearchParams.Builder()
        .maxResults(10000) //Sets the number of users to search
def allUsers = userSearchService.findUserNames("", userSearchParams)

(String item : allUsers) {
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
def filterUser = ComponentAccessor.getUserManager ().getUserByName (item)
SearchRequestService searchRequestService = ComponentAccessor.getComponent(SearchRequestService.class)
Collection<SearchRequest> searchRequests = searchRequestService.getOwnedFilters(filterUser).each{filter->
  SearchRequestManager srm = ComponentAccessor.getComponent(SearchRequestManager.class);
  Set<SharePermission> permissionsSet = new HashSet<SharePermission>(

 permissionsSet.add(new SharePermissionImpl(Name.AUTHENTICATED, null, null));
 filter.setPermissions(new SharePermissions(permissionsSet));
    srm.update(user, filter);

1 answer

1 vote

The way to deal with that is to filter out any View permissions from the permissionSet.

Here is an example:

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

/* ... */
newPermissionsList = permissionsSet.collect().findAll{it.rights != ShareRights.VIEW}
newPermissionsList.add(new SharePermissionImpl(null, Name.AUTHENTICATED, null,null, ShareRights.VIEW))
filter.setPermissions(new SharePermissions(newPermissionsList.toSet()))
srm.update(user, filter)

You'll see the new import. 

The next line converts the set to a list via "collect()" and then filters with findAll
We can then add the new permission (I used a newer signature of the SharePermissionImpl constructor that isn't depracated) to the list.

And then finally, we convert the list back to a set before adding it to the filter.

@Peter-Dave Sheehan

Thanks a lot! That worked wonderfully.

Suggest an answer

Log in or Sign up to answer

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you