Please help me to provide a resolution for the below issue. Appreciate your quick feedback. Thanks in advance.
Requirement
User should be added “Administrators” Project Role via JIRA Plugin Code
Detailed description of the issue
I am developing JIRA Plugin to add user to the “Administrators” Project Role via JIRA Plugin.
Plugin failed to perform this functionality for few users (for other users, it works well) & returned the error message “We can’t find the ‘user’ in any accessible user directly. Check if they are still available & active and try again.” However, I can add the same user via JIRA UI and JIRA REST API without any issue. Please find the code snippet below as reference.
ProjectRoleManager projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager.class);
ProjectRoleService projectRoleService = ComponentAccessor.getComponent(ProjectRoleService.class);
ProjectRole projectRole = projectRoleManager.getProjectRole(“Administrators”);
ArrayList actors = new ArrayList<>();
actors.add(“userId”);
ErrorCollection errorCollection = new SimpleErrorCollection();
projectRoleService.addActorsToProjectRole(user, (Collection)actors, projectRole , project, ProjectRoleActor.USER_ROLE_ACTOR_TYPE, errorCollection);
if(errorCollection.hasAnyErrors())
{
return “Failed to add user !!”;
}
else
{
return “Successfully added user”;
}
Diagnostic Steps
I have followed these steps to verify this issue
- Verified JIRA DB to check if there is any trailing space/blank space for that user. But no such extra space available.
- User can be added to the “Administrators” role via JIRA UI manually
- User can be added to the “Administrators” role via JIRA REST API