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
Community showcase
Posted Thursday in Marketplace Apps

You + one app + a desert island...

Hi all! My name is Miles and I work on the Marketplace team. We’re looking for better ways to recommend and suggest apps that are truly crowd favorites, so of course we wanted to poll the Community. ...

1,760 views 4 6
Join discussion

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