Pregunta

I am currently developing a plugin that allows project administrators to manage users in groups. I have been combing through the api reference documentation and I cannot seem to find any calls that I can make that will allow me to see the groups associated with a particular project.

I have looked through the API's at every location that is relevant to what I am searching for to no avail.

I currently have a database query that provides me what I am looking for.

SELECT ROLETYPEPARAMETER AS "Groups"

FROM projectrole PROJECT_ROLE,
projectroleactor PROJECT_ROLE_ACTOR

JOIN project PROJECT
    ON PROJECT.id = PROJECT_ROLE_ACTOR.PID
JOIN cwd_group
    ON group_name = roletypeparameter

WHERE PROJECT_ROLE_ACTOR.projectroleid = PROJECT_ROLE.id
AND PKEY = <projectkey>;

I would prefer to manipulate this data through the API if at all possible.

All the other pieces are available for me to complete the plugin to add, remove users from groups.

I know the information that I am looking for is available. If you navigate to the roles page you have both the users in roles, and also the groups in roles. I'm sure i'm overlooking something minor with the API to give me the groups associated with the project.

¿Fue útil?

Solución

After implementing my database route, I came back to a non-database approach. This is the implementation that solves the problem.

The way the groups are implemented is as a role actor as a set underneath the project roles. One more level down you have your group names as a descriptor to the role actor.

//Create TreeMap to Store the Role-Group association.  Note a role can have more than one group
TreeMap<String,Collection<String>> projectGroups = new TreeMap<String,Collection<String>>();

//Get all the project roles
Collection<ProjectRole> projectRoles = projectRoleManager.getProjectRoles();

//Iterate through each role and get the groups associated with the role
for (ProjectRole projectRole : projectRoles)
{
    //Get the role actors for the project role 
    ProjectRoleActors roleActors = projectRoleManager.getProjectRoleActors(projectRole, project);

    //Create an iterator to grab all of the groups for this project role
    Iterator <RoleActor> roleActorIterator = roleActors.getRoleActors().iterator();

    //Create a collection of strings to store all of the group's roles to put in the map
    Collection <String> groupRoles = new ArrayList<String>();

    //Iterate the role actors to get the groups
    while (roleActorIterator.hasNext())
    {

        //Add the group by string name into collection
        groupRoles.add(roleActorIterator.next().getDescriptor());

    }//END While

    //Add that role, and the associated groups to that role into our map.
    projectGroups.put(projectRole.getName(), groupRoles);

}//END For

The output of this will look similarly to this

{Administrators=[jira-administrators], Developers=[jira-developers, jira-users], Users=[jira-users]} 
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top