Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Script to Add Project Role to Permission in all Permission Schemes

Edited

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:

 

import com.atlassian.jira.permission.JiraPermissionHolderType
import com.atlassian.jira.permission.ProjectPermissions

def project = Projects.getByKey('RBM')

def permissionscheme = project.permissionScheme
// gives the View Only role Browse Projects permission
permissionscheme.addPermission(ProjectPermissions.BROWSE_PROJECTS, JiraPermissionHolderType.PROJECT_ROLE, '10700')
How can I do it for all projects, or even better, all Permission Schemes?

2 answers

Suggest an answer

Log in or Sign up to answer
1 vote
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jun 17, 2023 • edited

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.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.

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jun 20, 2023 • edited

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.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 

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: 

 

Something went wrong: MissingMethodException

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.

 

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jul 08, 2023

Hi @William Tanner

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

0 votes
Mohamed Benziane
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jun 17, 2023

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()
TAGS
AUG Leaders

Atlassian Community Events