You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
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:
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.JiraPermissionHolderType
import com.atlassian.jira.permission.ProjectPermissions
import com.adaptavist.hapi.jira.projects.Projects
def projects = Projects.allProjects
projects.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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.JiraPermissionHolderType
import com.atlassian.jira.permission.ProjectPermissions
import com.adaptavist.hapi.jira.projects.Projects
def projects = Projects.allProjects
projects.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.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ram,
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry for the delay in responding. Was pretty busy these couple of weeks.
Could you please specify which code sample did you use?
Was it the first example or the second example I provided?
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.