Uploaded image for project: 'Jira Data Center'
  1. Jira Data Center
  2. JRASERVER-15841

Allow the ability to share filters/dashboards rather than the current publish/subscribe model - force favourites

    • 4
    • We collect Jira feedback from various sources, and we evaluate what we've collected when planning our product roadmap. To understand how this piece of feedback will be reviewed, see our Implementation of New Features Policy.

      NOTE: This suggestion is for JIRA Server. Using JIRA Cloud? See the corresponding suggestion.

      Some people want to share filters in the old way, such that the sharees automatically see that filter in their filter list.

      We have many business users and they seem incapable of doing Manage Filters, Search, entering some params, then clicking the grey stars.

      Prior to the upgrade we did have problems with filter and dashboard spam, where people were sharing with too wide a group, so this is an improvement. However in some circumstances we want to share a dashboard/filter and auto-favourite it for the sharees.

      Not sure how this would be implemented, eg allow everyone to do this, or just project admins, or add some new permission, or whatever.

            [JRASERVER-15841] Allow the ability to share filters/dashboards rather than the current publish/subscribe model - force favourites

            Rano added a comment -

            Marcos Quiroga

            import com.atlassian.jira.component.ComponentAccessor
            import com.atlassian.jira.issue.search.SearchRequest
            import com.atlassian.jira.issue.search.SearchRequestManager
            import com.atlassian.jira.favourites.FavouritesManager
            import com.atlassian.jira.user.ApplicationUser
            import com.atlassian.jira.portal.PortalPage
            import com.atlassian.jira.portal.PortalPageManager
            import com.atlassian.jira.favourites.FavouritesManager
            import com.atlassian.jira.user.util.UserUtil
            import com.atlassian.crowd.embedded.api.*
            // Set the portal page ID and group to share with here
            def portalPageIds = [10300]
            def groupNames = ['[ИС]']
            def groupManager = ComponentAccessor.getGroupManager()
            def srm = ComponentAccessor.getComponentOfType(SearchRequestManager.class)
            def portalPageManager = ComponentAccessor.getComponent(PortalPageManager)
            FavouritesManager favouritesManager = ComponentAccessor.getComponentOfType(FavouritesManager.class);
            for (String groupName: groupNames) {
            def grpUserList = groupManager.getUsersInGroup(groupName)
            for (ApplicationUser user:grpUserList){
            for (Long portalPageId: portalPageIds)

            { PortalPage portalPage = portalPageManager.getPortalPageById(portalPageId) try Unknown macro: \{ favouritesManager.addFavourite(user, portalPage) log.info("Adding portal " + portalPageId.toString() + " to user}

            catch (Exception ex)

            Unknown macro: { log.warn("Failed Adding portal " + portalPageId.toString() + " to user}
            //catch
            } //for portalID
            } //for group users
            } //for groups

            Rano added a comment - Marcos Quiroga import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.search.SearchRequest import com.atlassian.jira.issue.search.SearchRequestManager import com.atlassian.jira.favourites.FavouritesManager import com.atlassian.jira.user.ApplicationUser import com.atlassian.jira.portal.PortalPage import com.atlassian.jira.portal.PortalPageManager import com.atlassian.jira.favourites.FavouritesManager import com.atlassian.jira.user.util.UserUtil import com.atlassian.crowd.embedded.api.* // Set the portal page ID and group to share with here def portalPageIds = [10300] def groupNames = [' [ИС] '] def groupManager = ComponentAccessor.getGroupManager() def srm = ComponentAccessor.getComponentOfType(SearchRequestManager.class) def portalPageManager = ComponentAccessor.getComponent(PortalPageManager) FavouritesManager favouritesManager = ComponentAccessor.getComponentOfType(FavouritesManager.class); for (String groupName: groupNames) { def grpUserList = groupManager.getUsersInGroup(groupName) for (ApplicationUser user:grpUserList){ for (Long portalPageId: portalPageIds) { PortalPage portalPage = portalPageManager.getPortalPageById(portalPageId) try Unknown macro: \{ favouritesManager.addFavourite(user, portalPage) log.info("Adding portal " + portalPageId.toString() + " to user} catch (Exception ex) Unknown macro: { log.warn("Failed Adding portal " + portalPageId.toString() + " to user} //catch } //for portalID } //for group users } //for groups

            Rano added a comment -

            Marcos Quiroga

            The script could not be compiled: <pre>org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script162.groovy: 25: expecting '{', found 'Unknown' @ line 25, column 1. Unknown macro:

            { favouritesManager.addFavourite(user, portalPage) log.info("Adding portal " + portalPageId.toString() + " to user}

            ^ 1 error </pre>.

            Rano added a comment - Marcos Quiroga The script could not be compiled: <pre>org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script162.groovy: 25: expecting '{', found 'Unknown' @ line 25, column 1. Unknown macro: { favouritesManager.addFavourite(user, portalPage) log.info("Adding portal " + portalPageId.toString() + " to user} ^ 1 error </pre>.

            After some minor changes on script generated by Lacey McDonnell this code is 100% working for me, on Jira Server 8.8.1[

            https://jira.atlassian.com/secure/ViewProfile.jspa?name=lmcdonnell]

            import com.atlassian.jira.component.ComponentAccessor
            import com.atlassian.jira.issue.search.SearchRequest
            import com.atlassian.jira.issue.search.SearchRequestManager
            import com.atlassian.jira.favourites.FavouritesManager
            import com.atlassian.jira.user.ApplicationUser
            import com.atlassian.jira.portal.PortalPage
            import com.atlassian.jira.portal.PortalPageManager
            import com.atlassian.jira.favourites.FavouritesManager
            import com.atlassian.jira.user.util.UserUtil
            import com.atlassian.crowd.embedded.api.*
            // Set the portal page ID and group to share with here
            def portalPageIds = [Dashboard_ID]
            def groupNames = ['Group_NAME']
            def groupManager = ComponentAccessor.getGroupManager()
            def srm = ComponentAccessor.getComponentOfType(SearchRequestManager.class)
            def portalPageManager = ComponentAccessor.getComponent(PortalPageManager)
            FavouritesManager favouritesManager = ComponentAccessor.getComponentOfType(FavouritesManager.class);
            for (String groupName: groupNames) {
            def grpUserList = groupManager.getUsersInGroup(groupName)
            for (ApplicationUser user:grpUserList){
            for (Long portalPageId: portalPageIds) {
            PortalPage portalPage = portalPageManager.getPortalPageById(portalPageId)
            try

            Unknown macro: { favouritesManager.addFavourite(user, portalPage) log.info("Adding portal " + portalPageId.toString() + " to user}

            catch (Exception ex)

            Unknown macro: { log.warn("Failed Adding portal " + portalPageId.toString() + " to user}

            //catch
            } //for portalID
            } //for group users
            } //for groups

             

            Marcos Quiroga added a comment - After some minor changes on script generated by Lacey McDonnell  this code is 100% working for me, on Jira Server 8.8.1[ https://jira.atlassian.com/secure/ViewProfile.jspa?name=lmcdonnell] import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.search.SearchRequest import com.atlassian.jira.issue.search.SearchRequestManager import com.atlassian.jira.favourites.FavouritesManager import com.atlassian.jira.user.ApplicationUser import com.atlassian.jira.portal.PortalPage import com.atlassian.jira.portal.PortalPageManager import com.atlassian.jira.favourites.FavouritesManager import com.atlassian.jira.user.util.UserUtil import com.atlassian.crowd.embedded.api.* // Set the portal page ID and group to share with here def portalPageIds = [Dashboard_ID] def groupNames = ['Group_NAME'] def groupManager = ComponentAccessor.getGroupManager() def srm = ComponentAccessor.getComponentOfType(SearchRequestManager.class) def portalPageManager = ComponentAccessor.getComponent(PortalPageManager) FavouritesManager favouritesManager = ComponentAccessor.getComponentOfType(FavouritesManager.class); for (String groupName: groupNames) { def grpUserList = groupManager.getUsersInGroup(groupName) for (ApplicationUser user:grpUserList){ for (Long portalPageId: portalPageIds) { PortalPage portalPage = portalPageManager.getPortalPageById(portalPageId) try Unknown macro: { favouritesManager.addFavourite(user, portalPage) log.info("Adding portal " + portalPageId.toString() + " to user} catch (Exception ex) Unknown macro: { log.warn("Failed Adding portal " + portalPageId.toString() + " to user} //catch } //for portalID } //for group users } //for groups  

            Marcos Quiroga added a comment - - edited

            Same error here (than the one posted by Lacey)

            The script could not be compiled: <pre>org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script60.groovy: 28: unexpected token: < @ line 28, column 1. <ApplicationUser> selGrpUsers ^ 1 error </pre>

             
            To bad, this will help us a lot... All the rest of the scripts around give us errors as well. 
            Jira version 8.8 Server.

            cc dfateev

            Marcos Quiroga added a comment - - edited Same error here (than the one posted by Lacey) The script could not be compiled: <pre>org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script60.groovy: 28: unexpected token: < @ line 28, column 1. <ApplicationUser> selGrpUsers ^ 1 error </pre>   To bad, this will help us a lot... All the rest of the scripts around give us errors as well.  Jira version 8.8 Server. cc  dfateev

            Lacey Also added a comment - - edited

            dfateev

            I'm getting errors on this script in Jira 8.5   Had to enter lines between the single line dual imports, and it's throwing unexpected token at ( for debug level setting. I remove that, it throws error at < for application user. Remove the <> then throws error on almost all of the second half of the script. This is what I came up with.

             

             

            import com.atlassian.jira.component.ComponentAccessor
            import com.atlassian.jira.issue.search.SearchRequest
            import com.atlassian.jira.issue.search.SearchRequestManager
            import com.atlassian.jira.favourites.FavouritesManager
            import com.atlassian.jira.user.ApplicationUser
            import com.atlassian.jira.portal.PortalPage
            import com.atlassian.jira.portal.PortalPageManager
            import com.atlassian.jira.favourites.FavouritesManager
            import com.atlassian.jira.user.util.UserUtil
            import com.atlassian.crowd.embedded.api.*
            
            // Set the portal page ID and group to share with here
            def portalPageIds = [10400]
            def groupNames = ['jira-software-users']
            def groupManager = ComponentAccessor.getGroupManager()SearchRequestManager srm = ComponentAccessor.getComponentOfType(SearchRequestManager.class);
            def portalPageManager = ComponentAccessor.getComponent(PortalPageManager)
            FavouritesManager favouritesManager = ComponentAccessor.getComponentOfType(FavouritesManager.class);
            
            for (String groupName: groupNames) {
                def grpUserList = groupManager.getUsersInGroup(groupName)
                for (ApplicationUser user:grpUserList){
                     for (Long portalPageId: portalPageIds) {
                          PortalPage portalPage = portalPageManager.getPortalPageById(portalPageId)
                          try{
                             favouritesManager.addFavourite(user, portalPage) 
                             log.info("Adding portal " + portalPageId.toString() + " to user: " + user)
                          } catch (Exception ex){
                             log.warn("Failed Adding portal " + portalPageId.toString() + " to user: " + user + "\n" + ex)
                          } //catch 
                     } //for portalID
                } //for group users
            } //for groups
            
            
            

             

             

             

            Lacey Also added a comment - - edited dfateev I'm getting errors on this script in Jira 8.5   Had to enter lines between the single line dual imports, and it's throwing unexpected token at ( for debug level setting. I remove that, it throws error at < for application user. Remove the <> then throws error on almost all of the second half of the script. This is what I came up with.     import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.search.SearchRequest import com.atlassian.jira.issue.search.SearchRequestManager import com.atlassian.jira.favourites.FavouritesManager import com.atlassian.jira.user.ApplicationUser import com.atlassian.jira.portal.PortalPage import com.atlassian.jira.portal.PortalPageManager import com.atlassian.jira.favourites.FavouritesManager import com.atlassian.jira.user.util.UserUtil import com.atlassian.crowd.embedded.api.* // Set the portal page ID and group to share with here def portalPageIds = [10400] def groupNames = [ 'jira-software-users' ] def groupManager = ComponentAccessor.getGroupManager()SearchRequestManager srm = ComponentAccessor.getComponentOfType(SearchRequestManager.class); def portalPageManager = ComponentAccessor.getComponent(PortalPageManager) FavouritesManager favouritesManager = ComponentAccessor.getComponentOfType(FavouritesManager.class); for ( String groupName: groupNames) { def grpUserList = groupManager.getUsersInGroup(groupName) for (ApplicationUser user:grpUserList){ for ( Long portalPageId: portalPageIds) { PortalPage portalPage = portalPageManager.getPortalPageById(portalPageId) try { favouritesManager.addFavourite(user, portalPage) log.info( "Adding portal " + portalPageId.toString() + " to user: " + user) } catch (Exception ex){ log.warn( "Failed Adding portal " + portalPageId.toString() + " to user: " + user + "\n" + ex) } // catch } // for portalID } // for group users } // for groups      
            Katherine Yabut made changes -
            Workflow Original: JAC Suggestion Workflow [ 3050551 ] New: JAC Suggestion Workflow 3 [ 3691655 ]
            Status Original: RESOLVED [ 5 ] New: Closed [ 6 ]

            avinashp added a comment -

            @dmitriy Thanks a lot . The script is working but it is removing the current shared permissions. For example if a dashboard is shared with project "abc" and group "jira-users" after running the script with new group it is replacing the entire permission to new group. The dahboard shared permission is "new group" we are loosing the project "abc". Is there any way that we can just add the new group instead of replacing the group ?? 

             

            avinashp added a comment - @dmitriy Thanks a lot . The script is working but it is removing the current shared permissions. For example if a dashboard is shared with project "abc" and group "jira-users" after running the script with new group it is replacing the entire permission to new group. The dahboard shared permission is "new group" we are loosing the project "abc". Is there any way that we can just add the new group instead of replacing the group ??   

            Dmitriy Fateev added a comment - - edited

            I worked on this problem again and made a completely new version of script, which now is able to add list of Jira groups to Dashboard shared list:

            // This script can be run from Scriptrunner console to set Dashboards listed in the variable dashboardIds as favourites for users & groups listed in the variables userNames & groupNames and share Dashboard to groups listed in the variable sharedGroups
            import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.user.ApplicationUser
            import com.atlassian.jira.user.util.UserManagerimport com.atlassian.jira.security.groups.GroupManager
            import com.atlassian.jira.bc.JiraServiceContextimport com.atlassian.jira.bc.JiraServiceContextImpl
            import com.atlassian.jira.portal.PortalPageimport com.atlassian.jira.bc.portal.PortalPageService
            import com.atlassian.jira.sharing.SharedEntityimport com.atlassian.jira.sharing.SharePermissionImpl
            import com.atlassian.jira.sharing.type.ShareType
            import org.apache.log4j.Levellog.setLevel(Level.DEBUG)
            
            List<Integer> dashboardIds = [ // change Dashboard Ids for your case
              11111,
              22222,
              33333
            ]
            List<String> groupNames = [ // change group names for your case or comment out this list, if userlist is not needed 
              'jiragroup1''jiragroup2''jiragroup3' 
            ]
            List<String> userNames = [ // change user names for your case or comment out this list, if userlist is not needed  
              'user1@company.com',
              'user2@company.com',
              'user3@company.com'
            ] 
            List<String> sharedGroups = [ // change Dashboard shared groups for your case or comment out this list, if userlist is not needed
              'jiragroup4',
              'jiragroup5'
            ]    
            
            PortalPage portalPageList
            <ApplicationUser> selGrpUsers
            List<String> allUserNames = new ArrayList<>()
            ApplicationUser curUser =  ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
            JiraServiceContext context = new JiraServiceContextImpl(curUser)
            UserManager userManager = ComponentAccessor.getUserManager()
            GroupManager groupManager = ComponentAccessor.getGroupManager() 
            PortalPageService portalPageService = ComponentAccessor.getComponent(PortalPageService)
            
            if (!groupNames?.isEmpty()) { // read list of group names if non-empty
              for (String groupName: groupNames) {
                try{
                  selGrpUsers = groupManager.getUsersInGroup(groupName) as List<ApplicationUser>
                } catch (Exception ex) {
                  log.error("Can't find Jira group with name '"+groupName+"'\n" + ex)
                }
                if (!selGrpUsers?.isEmpty()) allUserNames += selGrpUsers.collect{it.getName().toLowerCase()}
              }
              log.debug("Usernames list for all groups:\n"+allUserNames)}
            
            if (!userNames?.isEmpty()) allUserNames += userNames.collect{it.toLowerCase()}
            allUserNames.unique()
            log.debug("Usernames list for all groups and separate users:\n"+allUserNames)
            
            if (!allUserNames?.isEmpty()) {
              for (Long dashboardId: dashboardIds) {
                portalPage =  portalPageService.getPortalPage(context, dashboardId)
                if (portalPage) {
                  if (!sharedGroups?.isEmpty()) {
                    SharedEntity.SharePermissions perms
                    List<String> sharedGroupsResult = new ArrayList<>()
                    sharedGroups.each {
                      if (groupManager.groupExists(it)) {
                        if (groupManager.isUserInGroup(curUser, it)) sharedGroupsResult.add(it)
                        else log.error("User '"+curUser.name+"' must be a member of the group '"+it+"' to be able to share Jira dashboard to the group. Can't add this group to Dashboard share.")
                      } else log.error("Can't find Jira group with name '"+it+"'. Therefore can't share Jira dashboard to non-existing group.")
                    }
                    if (!sharedGroupsResult?.isEmpty()) {
                      perms = new SharedEntity.SharePermissions(sharedGroupsResult.collect{new SharePermissionImpl(ShareType.Name.GROUP, it, null)}.toSet())
                      portalPage = portalPage.portalPage(portalPage)
                        .permissions(perms)
                        .build()                                                                
                    }
                  }
                  for (String userName: allUserNames) {
                    try {
                      portalPage = portalPageService.updatePortalPage(context, portalPage, true)
                      log.info("Adding portal "+dashboardId?.toString()+" to user: "+userName)
                    } catch (Exception ex) {
                      log.error("Failed Adding portal "+dashboardId?.toString()+" to user: "+userName+"\n"+ex)
                    }
                  }
                } else log.error("Can't find Jira dashboard with Id: "+dashboardId)  
              }
            } else log.error("List of usernames and usernames from groups is empty. Therefore nothing to do.")

             

            Dmitriy Fateev added a comment - - edited I worked on this problem again and made a completely new version of script, which now is able to add list of Jira groups to Dashboard shared list: // This script can be run from Scriptrunner console to set Dashboards listed in the variable dashboardIds as favourites for users & groups listed in the variables userNames & groupNames and share Dashboard to groups listed in the variable sharedGroups import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.user.ApplicationUser import com.atlassian.jira.user.util.UserManagerimport com.atlassian.jira.security.groups.GroupManager import com.atlassian.jira.bc.JiraServiceContextimport com.atlassian.jira.bc.JiraServiceContextImpl import com.atlassian.jira.portal.PortalPageimport com.atlassian.jira.bc.portal.PortalPageService import com.atlassian.jira.sharing.SharedEntityimport com.atlassian.jira.sharing.SharePermissionImpl import com.atlassian.jira.sharing.type.ShareType import org.apache.log4j.Levellog.setLevel(Level.DEBUG) List< Integer > dashboardIds = [ // change Dashboard Ids for your case 11111, 22222, 33333 ] List< String > groupNames = [ // change group names for your case or comment out this list, if userlist is not needed  'jiragroup1' ,  'jiragroup2' ,  'jiragroup3'   ] List< String > userNames = [ // change user names for your case or comment out this list, if userlist is not needed  'user1@company.com' ,   'user2@company.com' ,   'user3@company.com' ]  List< String > sharedGroups = [ // change Dashboard shared groups for your case or comment out this list, if userlist is not needed 'jiragroup4' , 'jiragroup5' ]     PortalPage portalPageList <ApplicationUser> selGrpUsers List< String > allUserNames = new ArrayList<>() ApplicationUser curUser =  ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() JiraServiceContext context = new JiraServiceContextImpl(curUser) UserManager userManager = ComponentAccessor.getUserManager() GroupManager groupManager = ComponentAccessor.getGroupManager()  PortalPageService portalPageService = ComponentAccessor.getComponent(PortalPageService) if (!groupNames?.isEmpty()) { // read list of group names if non-empty   for ( String groupName: groupNames) {     try {     selGrpUsers = groupManager.getUsersInGroup(groupName) as List<ApplicationUser>     } catch (Exception ex) {       log.error( "Can 't find Jira group with name ' " +groupName+ "'\n" + ex)     }   if (!selGrpUsers?.isEmpty()) allUserNames += selGrpUsers.collect{it.getName().toLowerCase()}   } log.debug( "Usernames list for all groups:\n" +allUserNames)} if (!userNames?.isEmpty()) allUserNames += userNames.collect{it.toLowerCase()} allUserNames.unique() log.debug( "Usernames list for all groups and separate users:\n" +allUserNames) if (!allUserNames?.isEmpty()) {   for ( Long dashboardId: dashboardIds) {     portalPage =  portalPageService.getPortalPage(context, dashboardId)     if (portalPage) {     if (!sharedGroups?.isEmpty()) {       SharedEntity.SharePermissions perms         List< String > sharedGroupsResult = new ArrayList<>()         sharedGroups.each {           if (groupManager.groupExists(it)) {             if (groupManager.isUserInGroup(curUser, it)) sharedGroupsResult.add(it)             else log.error( "User '" +curUser.name+ "' must be a member of the group '" +it+ "' to be able to share Jira dashboard to the group. Can't add this group to Dashboard share." )           } else log.error( "Can 't find Jira group with name ' " +it+ " '. Therefore can' t share Jira dashboard to non-existing group." )         } if (!sharedGroupsResult?.isEmpty()) {           perms = new SharedEntity.SharePermissions(sharedGroupsResult.collect{ new SharePermissionImpl(ShareType.Name.GROUP, it, null )}.toSet())           portalPage = portalPage.portalPage(portalPage)           .permissions(perms)             .build()                                                                }   }       for ( String userName: allUserNames) {        try {         portalPage = portalPageService.updatePortalPage(context, portalPage, true )           log.info( "Adding portal " +dashboardId?.toString()+ " to user: " +userName)         } catch (Exception ex) {           log.error( "Failed Adding portal " +dashboardId?.toString()+ " to user: " +userName+ "\n" +ex)         }       }     } else log.error( "Can't find Jira dashboard with Id: " +dashboardId)  } } else log.error( "List of usernames and usernames from groups is empty. Therefore nothing to do ." )  

            @Avinash, for now my version of script can't add group to the shared list, but I'll think about it whenever possible.

            Dmitriy Fateev added a comment - @Avinash, for now my version of script can't add group to the shared list, but I'll think about it whenever possible.

            Avinash added a comment -

            @Dmitriy - Does this script also help to add the group in the shared list ? I am trying to bulk update the dashboard shared groups from xgroup to ygroup due to change of names in the group.   

            Avinash added a comment - @Dmitriy - Does this script also help to add the group in the shared list ? I am trying to bulk update the dashboard shared groups from xgroup to ygroup due to change of names in the group.   

              Unassigned Unassigned
              2e9235c6cdbf Jamie Echlin
              Votes:
              59 Vote for this issue
              Watchers:
              53 Start watching this issue

                Created:
                Updated:
                Resolved: