I am try to list all projects that a user is a Project Administrator, got code below with error on line 26. Any advise?
import com.atlassian.jira.bc.projectroles.ProjectRoleService;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectManager;
import com.atlassian.jira.security.roles.ProjectRole;
import com.atlassian.jira.security.roles.ProjectRoleActors;
import com.atlassian.jira.security.roles.ProjectRoleManager;
import com.atlassian.jira.security.roles.RoleActor;
StringBuilder output = new StringBuilder();
ProjectManager projectManager = ComponentAccessor.getProjectManager();
ProjectRoleService projectRoleService = (ProjectRoleService) ComponentAccessor.getComponentOfType(ProjectRoleService.class);
ProjectRoleManager projectRoleManager = (ProjectRoleManager) ComponentAccessor.getComponentOfType(ProjectRoleManager.class);
final Collection<ProjectRole> projectRoles = projectRoleManager.getProjectRoles();
for(Project project : projectManager.getProjectObjects())
{
for(ProjectRole projectRole: projectRoles)
{
//for (RoleActor actor : projectRoleActors.getRoleActors()) {
// if(projectRole.getDescriptor().equals("Developers")) {
final ProjectRoleActors projectRoleActors = projectRoleManager.getProjectRoleActors(projectRole, project);
// name of role here
//final ProjectRole devsRole = projectRoleManager.getProjectRole("Project Administrators")
for (RoleActor actor : projectRoleActors.getRoleActors()) {
if(projectRoleManager.getProjectRole().equals("Project Administrators")){
output.append(project.getKey()).append(" : ").append(projectRole.getName()).append(" : ").append(actor.getDescriptor()).append("\n");
}
}
// }
// }
}
}
return output.toString();
I am
I'm not sure what you're wanting to do throughout all of your code, but this should be a simple example to get you started. I have not tested it directly, but I think it should work. If you have any trouble, please let me know. :)
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
def projectManager = ComponentAccessor.projectManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def allProjects = projectManager.getProjects()
def adminProjects = []
allProjects.each{
def projectRoles = projectRoleManager.getProjectRoles(user, it)
if(projectRoles.find(){it.getName() == "Project Administrators"}){
adminProjects.push(it.key)
}
}
return (adminProjects)
Also, if you want to go more in detail with what you're trying to accomplish I can try to code something up for you.
Hi Jenna,
I am trying to somehow display a list of selected JIRA projects and the user-roles of those project on a JIRA dashboard. I have looked into this and I couldn't find any dashboard gadget that could give me that. I think the only way I can get this information is by writing groovy script like above which I am not good at :( . I was wondering if you could help me write a groovy script so that I could display the list I am asking for. I don't mind having a scripted field to show that information in a JIRA issue. I could create a story or task for each of those project and list those stories on the dashboard which would show that scripted field.
I honestly don't care about how it should look but here is an example what I am trying to accomplish.
Project | Developers | Scrum Master | Product Owner |
Project A | Tom, Adam, Julia | Robert | Lew |
Project B | Cynthia, Melissa, Jared | John | Terri |
Project C |
|
|
|
|
|
|
|
Thank you so much!
- Shahriar
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.
Happy to help!
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.