how to construct SharePermission?

I have a large number of filters owned by various users that are shared with Everyone, that really should only (at most) be shared with the jira-developers group.

I'm trying to use ScriptRunner to alter the sharing rather than force users to manually unshare hundreds of filters, but I'm running into a syntax problem...

What I have so far:

import com.atlassian.jira.bc.filter.SearchRequestService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchRequest
import com.atlassian.jira.sharing.SharedEntity
import com.atlassian.jira.sharing.type.ShareType
import com.atlassian.jira.sharing.SharePermissionImpl
def searchRequestService = ComponentAccessor.getOSGiComponentInstanceOfType(SearchRequestService.class)
def user = ComponentAccessor.userManager.getUserByName('--omitted--')
def searchRequests = searchRequestService.getOwnedFilters( (com.atlassian.jira.user.ApplicationUser) user)
searchRequests.each {
  def isshared = 0
  it.getPermissions().getPermissionSet().each {
    if( it.getType() == ShareType.Name.GLOBAL ) {
      isshared++
    }
  }
  if ( isshared > 0 ) {
    log.error it.getName()
    log.error it.getPermissions()
    
	it.setPermissions( 
		SharedEntity.SharePermissions( 
			SharePermissionImpl( ShareType.Name.GROUP, "jira-developers", "")
		)
	)
  }
}

 

Ignoring the awkward structure because I don't really know Groovy very well yet, I'm erroring out on the SharePermissionImpl constructor, with:

 

Error
No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.SharePermissionImpl() 
is applicable for argument types: (com.atlassian.jira.sharing.type.ShareType$Name, java.lang.String, 
java.lang.String) values: [group, jira-developers, ]

yet the API docs clearly show SharePermissionImpl taking ShareType.Name, String, String.

Obviously I'm missing something about the syntax, but I can't tell what.

(And, yes, I know I need to do an Update call at the end... I just haven't got there yet.)

Help?

 

2 answers

1 vote

I think you want something like:

it.setPermissions(
    new SharedEntity.SharePermissions([
        new SharePermissionImpl( ShareType.Name.GROUP, "jira-developers", "")
    ] as Set)
)

Hi Adam,

Maybe this free plugin would be a nice work around solution for your request?
https://marketplace.atlassian.com/plugins/aptis.plugins.shareYourJira
You will be able to share filter list or single issues to external users, but you see as a system admin or project admin every active share and the availability - control center of all active shares. You can even easily delete and edit the availability of every active share :)

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published yesterday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

66 views 0 5
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you