I am working on a script to add a project role to the Browse Projects permission in all permission schemes. Currently, I can do it for one project at a time:
Hi,
you need to get access to this interface https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/project/ProjectManager.html
and call the following method, you will get a list off all projects in your instance
getProjectObjects()
Hi @William Tanner
Welcome to the Community.
Great to see you are using ScriptRunner HAPI features. :-)
You are on the right track. The main modification you will need to make is instead of using:-
def project = Projects.getByKey('RBM')
to invoke all projects, you will need to use:-
def projects = Projects.allProjects
Below is an updated example code for your reference:-
import com.atlassian.jira.permission.JiraPermissionHolderTypeimport com.atlassian.jira.permission.ProjectPermissionsimport com.adaptavist.hapi.jira.projects.Projects def projects = Projects.allProjectsprojects.each { def permissionscheme = it.permissionScheme permissionscheme.addPermission(ProjectPermissions.BROWSE_PROJECTS, JiraPermissionHolderType.PROJECT_ROLE, '10700')}
So invoking the allProjects method will return a Collection of all the projects.
You will then need to iterate through the list, i.e. using the each parameter as shown above and using the it variable to invoke the iteration and update all the projects.
I hope this helps to answer your question. :-)
Thank you and Kind regards,
Ram
Hi Ram,
Thanks for the script. It works for some projects, but we noticed it is not updating every permission scheme. Any idea why it would only update some permission schemes and not all? It appears to have update 54 projects (per the "Result" in the script), but not every project/permissions scheme.
Hi @LMI Atlassian
From what you have mentioned, it may be possible that not all the projects are using the same Permission Scheme.
Try modifying the code to:-
import com.atlassian.jira.permission.JiraPermissionHolderTypeimport com.atlassian.jira.permission.ProjectPermissionsimport com.adaptavist.hapi.jira.projects.Projectsdef projects = Projects.allProjectsprojects.each { def permissionscheme = it.permissionScheme permissionscheme.addPermission(it.permissionScheme, ProjectPermissions.BROWSE_PROJECTS, JiraPermissionHolderType.PROJECT_ROLE, '10700')}
and see if it makes a difference.
Also @William Tanner, if your question has been answered, please accept the solution.
Appreciate the response and, yes, we do have multiple permission schemes were are trying to update. When I tried the updated script you provided, I get an error:
No signature of method: com.atlassian.jira.permission.data.PermissionSchemeImpl.addPermission() is applicable for argument types: (com.atlassian.jira.permission.data.PermissionSchemeImpl, com.atlassian.jira.security.plugin.ProjectPermissionKey...) values: [PermissionSchemeImpl{id=10100, name=LMI Permission Scheme A, description=This is the default Permission Scheme. Any new projects that are created will be assigned this scheme., permissions=[PermissionGrantImpl{id=10500, holder=(PROJECT_ROLE, some(10101)), permission=ADD_COMMENTS}, PermissionGrantImpl{id=10504, holder=(PROJECT_ROLE, some(10101)), permission=BROWSE_PROJECTS},
And, then it has the following as a possible solution:
Possible solutions: addPermission(com.atlassian.jira.security.plugin.ProjectPermissionKey, com.atlassian.jira.permission.PermissionHolderType, java.lang.String), addPermission(com.atlassian.jira.security.plugin.ProjectPermissionKey, com.atlassian.jira.permission.PermissionHolderType), getPermissions(), getPermissions(), hasPermission(com.atlassian.jira.security.plugin.ProjectPermissionKey, com.atlassian.jira.permission.PermissionHolderType, java.lang.String)
Any suggestions? I am still learning Groovy and ScriptRunner.
It looks like you're new here. Sign in or register to get started.