It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Jython: Search for dashboards

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

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

3,709 views 11 5
Join discussion

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