Script/ database change to "shared with" parametr to share all my filters with all logged users

Joanna Bajda September 12, 2017

Hi,

 

I'm lookig for a script/ a way to share all jira filters with "all logged users" at once.

I have around 3k filters and need to change permissions for all of them, anyone can help with that?

 

Best Regards

Joanna

1 answer

0 votes
Dinesh September 12, 2017

List of User Logins/Logouts from Audit

This groovy script creates an xml output of the audit log filtered by the User Access category, so dates of when users logged in or logged out.

script:

  1. import com.axeda.drm.sdk.device.ModelFinder  
  2. import com.axeda.drm.sdk.Context  
  3. import com.axeda.common.sdk.id.Identifier  
  4. import com.axeda.drm.sdk.device.Model  
  5. import com.axeda.drm.sdk.device.DeviceFinder  
  6. import com.axeda.drm.sdk.device.Device  
  7. import com.axeda.drm.sdk.audit.AuditCategoryList  
  8. import com.axeda.drm.sdk.audit.AuditCategory  
  9. import com.axeda.drm.sdk.audit.AuditEntryFinder  
  10. import com.axeda.drm.sdk.audit.SortType  
  11. import com.axeda.drm.sdk.audit.AuditEntry  
  12. import groovy.xml.MarkupBuilder  
  13.   
  14. /* 
  15. * AuditEntryList.groovy 
  16. * Creates an xml output of the audit log filtered by the User Access category, so dates of when users logged in or logged out. 
  17. * @param days        -   (REQ):Str number of days to search. 
  18. * @author Sara Streeter <sstreeter@axeda.com> 
  19. */  
  20.   
  21. def writer = new StringWriter()  
  22. def xml = new MarkupBuilder(writer)  
  23.   
  24. try {  
  25.     def ctx = Context.getUserContext()  
  26.     ModelFinder modelFinder = new ModelFinder(ctx, new Identifier(1))  
  27.     Model model = modelFinder.find()  
  28.     DeviceFinder deviceFinder = new DeviceFinder(ctx, new Identifier(1))  
  29.     Device device = deviceFinder.find()  
  30.     AuditCategoryList acl = new AuditCategoryList()  
  31.     acl.add(AuditCategory.USER_ACCESS)  
  32.     long now = System.currentTimeMillis()  
  33.     Date today = new Date(now)  
  34.     def paramdays = parameters.days ? parameters.days: 5  
  35.     long days = 1000 * 60 * 60 * 24 * Integer.valueOf(paramdays)  
  36.   
  37.     AuditEntryFinder aef = new AuditEntryFinder(ctx)  
  38.     aef.setCategories(acl)  
  39.     aef.setToDate(today)  
  40.     aef.setFromDate(new Date(now - (days)))  
  41.     aef.setSortType(SortType.DATE)  
  42.     aef.sortDescending()  
  43.     List<AuditEntry> audits = aef.findAll()  
  44.   
  45. // assemble the response  
  46.     xml.Response() {  
  47.         audits.each { AuditEntry audit ->  
  48.          
  49.             Audit() {  
  50.                 id(audit?.id.value)  
  51.                 user(audit?.user?.username)  
  52.                 date(audit?.date)  
  53.                 category(audit?.category?.bundleKey)  
  54.                 message(audit?.message)  
  55.             }  
  56.         }  
  57.     }  
  58.   
  59. } catch (def ex) {  
  60.     xml.Response() {  
  61.         Fault {  
  62.             Code('Groovy Exception')  
  63.             Message(ex.getMessage())  
  64.             StringWriter sw = new StringWriter();  
  65.             PrintWriter pw = new PrintWriter(sw);  
  66.             ex.printStackTrace(pw);  
  67.             Detail(sw.toString())  
  68.         }  
  69.     }  
  70. }  
  71.   
  72. return ['Content-Type': 'text/xml', 'Content': writer.toString()] 
Joanna Bajda September 12, 2017

Hi Dinesh,

 

It's not what I"m looking for I'm afraid, 

I need to change permissions for all my filters, and what to do this with script if it's possible.

Joanna

Dinesh September 13, 2017

Hi Joanna,

      Try this script in script runner plugin and if possible send the screenshot of your requirement where you should change the permissions of all your filters. 

Dinesh.

Joanna Bajda September 14, 2017

This script does not work at all, please see screen shot, but as I said before it's not what I'm looking for (This groovy script creates an xml output of the audit log filtered by the User Access category, so dates of when users logged in or logged out)

 

 

What I need is:

 

I have over 2k shared filters - shared with some groups, projects, public etc. I

need to change Shared With parametr all of my filters to "Shared with all logged users". All users in my company need to be able to see all filters,

Doing this one by one will take ages, so I'm looking for a script or maybe database change will do the job.

shared filters.png

error.png

Dinesh September 14, 2017

ok

Dinesh September 18, 2017

Hi,

Script to change permissions

import
com.atlassian.jira.bc.JiraServiceContextImpl import com.atlassian.jira.bc.filter.SearchRequestService import com.atlassian.jira.bc.issue.search.SearchService import com.atlassian.jira.component.ComponentAccessor // import com.atlassian.jira.issue.search.SearchRequest import com.atlassian.jira.sharing.SharePermissionImpl import com.atlassian.jira.sharing.SharedEntity import com.atlassian.jira.sharing.type.ShareType import com.atlassian.jira.issue.search.SearchRequestManager import com.atlassian.jira.issue.search.SearchRequest def searchRequestService = ComponentAccessor.getComponent(SearchRequestService) def user = ComponentAccessor.jiraAuthenticationContext?.getLoggedInUser() def searchService = ComponentAccessor.getComponent(SearchService) def serviceContext = new JiraServiceContextImpl(user) long filterId = ------ def searchRequestManager = ComponentAccessor.getComponent(SearchRequestManager) def ab = searchRequestManager.getSearchRequestById(filterId) def sharePerm = new SharePermissionImpl(null, ShareType.Name.GLOBAL, null, null) ab.setPermissions(new SharedEntity.SharePermissions([sharePerm] as Set))

Try this and do some changes according to your requirement.

Suggest an answer

Log in or Sign up to answer