I need to copy the users and roles from a project to another. I’ve already done many similar activities such as copying versions/components/workflow scheme from a project to another. However getting into users and roles, I’ve looked into ProjectRoleAndActorStore, ProjectRoleManager and other provided objects but couldn’t perform or find any method that can help.
I’ve written a simple code that move ProjectRoles from a project to another without being sure of what it does actually, it compiled but I still didn’t get the users and roles in the new project am copying
This is what I’ve done so far:
public void copyUsersRoles() {
projectRoleAndActorStore = ComponentAccessor.getComponentOfType(ProjectRoleAndActorStore.class);
Collection<ProjectRole> allProjectRoles = projectRoleAndActorStore.getAllProjectRoles();
for(ProjectRole projectRole : allProjectRoles) {
ProjectRoleActors sourceProjectRoleActors =
projectRoleManager.getProjectRoleActors(projectRole, sourceProject);
ProjectRoleActors targetProjectRoleActors =
projectRoleManager.getProjectRoleActors(projectRole, targetProject);
targetProjectRoleActors.addRoleActors(sourceProjectRoleActors.getRoleActors());
projectRoleAndActorStore.updateProjectRoleActors(targetProjectRoleActors);
}
}