Hi,
I looking to bulk add/replace groups in shared dashboards. We are migrating our old groups to new groups and we would like to modify the permissions in shared dashboard so as to add the new groups. Is there any API call or groovy script which can help achieve the functionality. The current version is 7.10 jira.
I don't have a ready script ... but you'll want to consult
The services can be reached with
def searchRequestService = ComponentAccessor.getComponent(SearchRequestService)def portalPageService = ComponentAccessor.getComponent(PortalPageService)
@PD Sheehan and @Avinash - I'm trying to do this myself, but having a little trouble with dashboards.
It seems that the SearchRequest class has methods for .setPermissions() and .setOwner(), but the PortalPage class does not have these same methods. Since that's the case, I've figured out how to update filters (SearchRequest) using the SearchRequestService interface successfully, but I'm not having the same luck with the PortalPageService interface.
Do either of you have any pointers on what other options there might be, or if I'm missing something glaring in the javadocs?
You might want to check out the PortalPage.Builder
I just created this on the fly on scriptrunner console... and it works:
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.bc.portal.PortalPageServiceimport com.atlassian.jira.issue.search.SearchRequestimport com.atlassian.jira.bc.filter.SearchRequestServiceimport com.atlassian.jira.portal.PortalPageimport com.atlassian.jira.sharing.SharedEntity.SharePermissionsimport com.atlassian.jira.sharing.SharePermissionImplimport com.atlassian.jira.sharing.SharedEntityimport com.atlassian.jira.sharing.type.ShareTypeimport com.atlassian.jira.bc.JiraServiceContextImpldef searchRequestService = ComponentAccessor.getComponent(SearchRequestService)def portalPageService = ComponentAccessor.getComponent(PortalPageService)def user = ComponentAccessor.jiraAuthenticationContext.loggedInUserdef serviceContext = new JiraServiceContextImpl(user)def sharePerm = new SharePermissionImpl(null, ShareType.Name.GROUP, "myGroupName", null)def sharePermissions = new SharedEntity.SharePermissions([sharePerm] as Set)def portalPageBuilder = new PortalPage.Builder().permissions(sharePermissions).name("test portal page").owner(user)def portalPage = portalPageBuilder.build()portalPageService.createPortalPage(serviceContext, portalPage)
A more extensive example is availble here:
https://scriptrunner.adaptavist.com/latest/jira/recipes/dashboard-gadgets.html
Sorry for hijacking this thread, but I was searching for the same solution. The script would fit perfectly for what I try to achieve but I get some errors when testing it.
I don't use Scriptrunner. We don't have this plugin. We have the "Jira Scripting Suite JSS" that is also using the Jira API.When I try to import some of the classes I get this error:No module named PortalPageService
I get the error for several other classes, too. So it looks like those are not available. Is there a way to find out which classes I can use?
first of all thx a lot - helped me!
any chance to let me know how to do this for all dashboards at once?
regards
You can't do this to all dashboard at once, but you can loop through all dashboards and do it one at a time
This uses the search method which is paged by default to prevent strain on the system. My example below only returns 100 pages starting at page 0 with an empty search parameter. You could do this multiple times, 100 pages at a time, or try larger numbers or even add some search parameters to filter the list.
import com.atlassian.jira.bc.portal.PortalPageServiceimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.bc.JiraServiceContextImplimport com.atlassian.jira.sharing.search.SharedEntitySearchParametersBuilderdef portalPageService = ComponentAccessor.getComponent(PortalPageService)def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()def context = new JiraServiceContextImpl(currentUser)def params = new SharedEntitySearchParametersBuilder()portalPageService.search(context,params.toSearchParameters(), 0,100).results.each{portalPage-> //do stuff to the portalPage}
Hey Peter, thx for your response.. as far as im new to scripting..
its possible to go over all dashboards, dont delete any other permissions and replace the "any logged in User" with a specific group like company_users?
450 dashboards..
It looks like you're new here. Sign in or register to get started.