how to construct SharePermission?

Adam Thompson [AVANT] July 23, 2015

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?

 

4 answers

2 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 27, 2015

I think you want something like:

it.setPermissions(
    new SharedEntity.SharePermissions([
        new SharePermissionImpl( ShareType.Name.GROUP, "jira-developers", "")
    ] as Set)
)
Eric Salonen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2019

This was the answer for me as well - please OP accept this as the answer.

Łukasz Sielski priv April 28, 2020

Hello @JamieA,

 

I wanted to create SharePermissionImpl but the one that include ShareRight
SharePermissionImpl(Long id, ShareType.Name type, String param1, String param2, ShareRight rights).

But the only way I manged to do is by :

ShareRight shareRight

def filter = searchRequestService.getFilter(serviceContextcurrentUser, 12200)
def perm = filter.getPermissions()

perm.getPermissionSet().each {impl ->

shareRight = impl.getRights()}

 

Is there a better way to do so?

 

Thanks,

Lukasz

1 vote
Eric Salonen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2019
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.portal.PortalPageManager
import com.atlassian.jira.portal.PortalPage
import com.atlassian.jira.util.collect.EnclosedIterable
import com.atlassian.jira.sharing.SharedEntity.SharePermissions
import com.atlassian.jira.sharing.SharePermissionImpl
import com.atlassian.jira.sharing.type.ShareType
import com.atlassian.jira.portal.PortalPage.Builder

def log = Logger.getLogger("GlobalSharedDashboardRemover")
log.setLevel(Level.INFO)

int count = 0
int authenticatedCount = 0

PortalPageManager portalPageManager = ComponentAccessor.getComponent(PortalPageManager)
EnclosedIterable<PortalPage> allPortalPagesInSystem = portalPageManager.getAll()

allPortalPagesInSystem.foreach{

if (it.getPermissions().isGlobal() == true && it.getId() != 10000){

count++
log.info "Found a new dashboard shared as global..."
log.info "Dashboard ID: " + it.getId()
log.info "Dashboard Name: " + it.getName()
log.info "Dashboard Owner: " + it.getOwnerUserName()
log.info "String representation of shares: " + it.getPermissions().toString()
log.info "PROCESSING DASHBOARD TO AUTHENTICATED..."
it = new PortalPage.Builder().
permissions(SharePermissions.AUTHENTICATED).owner(it.getOwner()).name(it.getName()).id(it.getId()).build()
portalPageManager.update(it)
log.info "Dashboard details after PROCESSING..."
log.info "String representation of shares: " + it.getPermissions().toString()
}

else
authenticatedCount++
}

log.info "Total dashboards processed that were shared to Global: " + count
log.info "Amount of dashboards shared to logged in users only before processing: " + authenticatedCount

count = 0
authenticatedCount = 0

EnclosedIterable<PortalPage> allPortalPagesInSystemSecondRound = portalPageManager.getAll()

allPortalPagesInSystemSecondRound.foreach{

if (it.getPermissions().isGlobal() == true)
count++

else
authenticatedCount++
}

log.info "Amount of global dashboards after processing: " + count
log.info "Amount of authenticated dashboards after processing: " + authenticatedCount

Here is also the equivalent for the dashboards.

1 vote
Eric Salonen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2019
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.issue.search.SearchRequestManager
import com.atlassian.jira.issue.search.SearchRequest
import com.atlassian.jira.util.collect.EnclosedIterable
import com.atlassian.jira.sharing.SharedEntity.SharePermissions
import com.atlassian.jira.sharing.SharePermissionImpl
import com.atlassian.jira.sharing.type.ShareType

def log = Logger.getLogger("GlobalSharedFilterRemover")
log.setLevel(Level.INFO)

int count = 0
int authenticatedCount = 0

SearchRequestManager searchRequestManager = ComponentAccessor.getComponent(SearchRequestManager)
EnclosedIterable<SearchRequest> allSearchRequestsInSystem = searchRequestManager.getAll()

allSearchRequestsInSystem.foreach{

if (it.getPermissions().isGlobal() == true){

count++
log.info "Found a new filter shared as global..."
log.info "Filter ID: " + it.getId()
log.info "Filter Name: " + it.getName()
log.info "Filter Owner: " + it.getOwnerUserName()
log.info "String representation of shares: " + it.getPermissions().toString()
log.info "PROCESSING FILTER TO AUTHENTICATED..."
it.setPermissions(new SharePermissions([new SharePermissionImpl(ShareType.Name.AUTHENTICATED, null, null)] as Set))
searchRequestManager.update(it)
log.info "Filter details after PROCESSING..."
log.info "String representation of shares: " + it.getPermissions().toString()
}

else
authenticatedCount++
}

log.info "Total filters processed that were shared to Global: " + count
log.info "Amount of filters shared to logged in users only before processing: " + authenticatedCount

count = 0
authenticatedCount = 0

EnclosedIterable<SearchRequest> allSearchRequestsInSystemSecondRound = searchRequestManager.getAll()

allSearchRequestsInSystemSecondRound.foreach{

if (it.getPermissions().isGlobal() == true)
count++

else
authenticatedCount++
}

log.info "Amount of global filters after processing: " + count
log.info "Amount of authenticated filters after processing: " + authenticatedCount

 This goes through all the filters in the Jira system and transfers all global filters to any-logged-in user.

1 vote
Sebastian Schöne July 28, 2015

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
TAGS
AUG Leaders

Atlassian Community Events