Jython: Search for dashboards

marius.erlenbruch August 3, 2020

Hi,

I am currently writing a script that should search for dashboards that are shared globally. I want to find all dashboards with those sharing permissions:

- Shared with anyone on the web
- Shared with logged-in users

I already managed to find all dashboards that are "shared with anyone on the web" with this search parameters:

searchParameters = SharedEntitySearchParametersBuilder().setShareTypeParameter(GlobalShareTypeSearchParameter.GLOBAL_PARAMETER).toSearchParameters() 

 

But I am struggling to find the fitting search parameters for the second share type (logged-in users). I already tried this.

searchParameters = SharedEntitySearchParametersBuilder().setShareTypeParameter(AuthenticatedUserShareTypeSearchParameter.AUTHENTICATED_USER_PARAMETER).toSearchParameters()

 But I get an error with those parameters:

root cause: Traceback (most recent call last): File "/home/jira/jss/jython/workflow/testmer/test.py", line 35, in <module> searchDashResults = portalPageService.search(serviceContext, searchParameters, 0, 20000) at java.util.Objects.requireNonNull(Objects.java:203) at org.apache.lucene.search.TermQuery.<init>(TermQuery.java:165) at com.atlassian.jira.sharing.type.AuthenticatedUserShareQueryFactory.getQuery(AuthenticatedUserShareQueryFactory.java:42) at com.atlassian.jira.sharing.type.AuthenticatedUserShareQueryFactory.getQuery(AuthenticatedUserShareQueryFactory.java:37) at com.atlassian.jira.sharing.index.DefaultQueryFactory$1.add(DefaultQueryFactory.java:45) at com.atlassian.jira.sharing.index.DefaultQueryFactory$Builder.build(DefaultQueryFactory.java:107) at com.atlassian.jira.sharing.index.DefaultQueryFactory.create(DefaultQueryFactory.java:49) at com.atlassian.jira.sharing.index.DefaultSharedEntitySearcher.search(DefaultSharedEntitySearcher.java:72) at com.atlassian.jira.portal.DefaultPortalPageManager.lambda$search$1(DefaultPortalPageManager.java:276) at com.atlassian.jira.sharing.index.DefaultSharedEntityIndexer.withSearcher(DefaultSharedEntityIndexer.java:188) at com.atlassian.jira.portal.DefaultPortalPageManager.search(DefaultPortalPageManager.java:276) at com.atlassian.jira.bc.portal.DefaultPortalPageService.search(DefaultPortalPageService.java:492) at sun.reflect.GeneratedMethodAccessor6835.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) java.lang.NullPointerException: java.lang.NullPointerException

It seems that you have tried to perform an illegal workflow operation.

If you think this message is wrong, please contact your Jira administrators.

 

 

This is my current script:

from com.atlassian.jira.bc import JiraServiceContextImplfrom com.atlassian.jira.bc.portal import PortalPageServicefrom com.atlassian.jira.component import ComponentAccessorfrom com.atlassian.jira.portal import PortalPagefrom com.atlassian.jira.sharing import SharedEntityfrom com.atlassian.jira.sharing import SharePermissionImplfrom com.atlassian.jira.sharing.type import ShareTypefrom com.atlassian.jira.sharing.rights import ShareRights from com.atlassian.jira.bc.filter import SearchRequestServicefrom com.atlassian.jira.sharing.search import GlobalShareTypeSearchParameterfrom com.atlassian.jira.sharing.search import SharedEntitySearchParametersBuilderfrom com.atlassian.jira.sharing.search import AuthenticatedUserShareTypeSearchParameterfrom com.atlassian.jira.sharing.search import GroupShareTypeSearchParameter

searchRequestService = ComponentAccessor.getComponent(SearchRequestService)portalPageService = ComponentAccessor.getComponent(PortalPageService)currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()context = JiraServiceContextImpl(currentUser)

# Setting search parametersserviceContext = JiraServiceContextImpl(currentUser)

# GlobalShareTypeSearchParameter.GLOBAL_PARAMETER == "Shared with anyone on the web":
#searchParameters = SharedEntitySearchParametersBuilder().setShareTypeParameter(GlobalShareTypeSearchParameter.GLOBAL_PARAMETER).toSearchParameters()

# Search for dashboards with share setting "Shared with all logged-in users":
searchParameters = SharedEntitySearchParametersBuilder().setShareTypeParameter(AuthenticatedUserShareTypeSearchParameter.AUTHENTICATED_USER_PARAMETER).toSearchParameters()
# Search validationsearchRequestService.validateForSearch(serviceContext, searchParameters)

# Search for dashboards
if searchParameters:
searchDashResults = portalPageService.search(serviceContext, searchParameters, 0, 20000)
searchDashResultsList = searchDashResults.getResults()

dashCount = searchDashResults.getTotalResultCount() log.warn("CDSP: Found " + str(dashCount) + " dashboards...")

for dashboard in searchDashResultsList:
dashName = dashboard.getName()

dashPermissions = dashboard.getPermissions()

log.warn(
"CDSP: Found '" + dashName + "' with permissions: '" + str(dashPermissions) + "'")

 

Could anybody help me here? Any suggestions?
I am running Jira Server 8.5.5 and Jira Scripting Suite 2.8.0

 

Thanks,
Marius

1 answer

0 votes
Markus Fischbacher January 27, 2021

Hi Marius,

have you managed to get it working?
I'm in the same situation. Need to find all Filters shared with Any logged in User.

Any help is appreciated.

Regards,
Markus

marius.erlenbruch January 31, 2021

Hi Markus,

I managed to find out about those using a database query, directly on our Jira server.

General example:

select * from sharepermissions where entitytype='PortalPage'

This will get all dashboards (=PortalPage). The same query can be used for filters. You will get a query result showing the sharetype. For example group or loggedin. After that you can add this to your query and search only for those.

select * from sharepermissions where entitytype='PortalPage' and sharetype='loggedin'

 

Regards,
Marius

Markus Fischbacher February 1, 2021

Hi Marius,

thank your for that tip.
I just got a reply from Adaptavist support.

Search

SELECT * FROM sharepermissions WHERE entitytype IN ('SearchRequest','PortalPage') AND sharetype = 'loggedin';

 Replace with Group

UPDATE sharepermissions SET sharetype = 'group', param1 = '<group name>' WHERE sharetype = 'loggedin' AND entitytype IN ('SearchRequest'); 

 

And an idea for the API

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('<username>')
def searchRequests = searchRequestService.getOwnedFilters( (com.atlassian.jira.user.ApplicationUser) user)
searchRequests.each {
 def isshared = 0
 it.getPermissions().getPermissionSet().each {
    if( it.getType() == ShareType.Name.AUTHENTICATED ) {
      isshared++
    }
  }
   
if (isshared > 0 ) {
    log.error it.getName()
    log.error it.getPermissions()
    
  }
}

how to construct SharePermission? (atlassian.com)

Regards,
Markus

Suggest an answer

Log in or Sign up to answer