use of com.epam.ta.reportportal.ws.model.project.AssignUsersRQ in project service-api by reportportal.
the class ProjectControllerTest method assignProjectUsersPositive.
@Test
void assignProjectUsersPositive() throws Exception {
AssignUsersRQ rq = new AssignUsersRQ();
Map<String, String> user = new HashMap<>();
user.put("default", "MEMBER");
rq.setUserNames(user);
mockMvc.perform(put("/v1/project/test_project/assign").with(token(oAuthHelper.getSuperadminToken())).contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(rq))).andExpect(status().isOk());
}
use of com.epam.ta.reportportal.ws.model.project.AssignUsersRQ in project service-api by reportportal.
the class UpdateProjectHandlerImpl method assignUsers.
@Override
public OperationCompletionRS assignUsers(String projectName, AssignUsersRQ assignUsersRQ, ReportPortalUser user) {
if (UserRole.ADMINISTRATOR.equals(user.getUserRole())) {
Project project = projectRepository.findByName(normalizeId(projectName)).orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, normalizeId(projectName)));
List<String> assignedUsernames = project.getUsers().stream().map(u -> u.getUser().getLogin()).collect(toList());
assignUsersRQ.getUserNames().forEach((name, role) -> {
ProjectRole projectRole = ProjectRole.forName(role).orElseThrow(() -> new ReportPortalException(ROLE_NOT_FOUND, role));
assignUser(name, projectRole, assignedUsernames, project);
});
} else {
expect(assignUsersRQ.getUserNames().keySet(), not(Preconditions.contains(equalTo(user.getUsername())))).verify(UNABLE_ASSIGN_UNASSIGN_USER_TO_PROJECT, "User should not assign himself to project.");
ReportPortalUser.ProjectDetails projectDetails = projectExtractor.extractProjectDetails(user, projectName);
Project project = projectRepository.findById(projectDetails.getProjectId()).orElseThrow(() -> new ReportPortalException(ErrorType.PROJECT_NOT_FOUND, normalizeId(projectName)));
List<String> assignedUsernames = project.getUsers().stream().map(u -> u.getUser().getLogin()).collect(toList());
assignUsersRQ.getUserNames().forEach((name, role) -> {
ProjectRole projectRole = ProjectRole.forName(role).orElseThrow(() -> new ReportPortalException(ROLE_NOT_FOUND, role));
ProjectRole modifierRole = projectDetails.getProjectRole();
expect(modifierRole.sameOrHigherThan(projectRole), BooleanUtils::isTrue).verify(ACCESS_DENIED);
assignUser(name, projectRole, assignedUsernames, project);
});
}
return new OperationCompletionRS("User(s) with username='" + assignUsersRQ.getUserNames().keySet() + "' was successfully assigned to project='" + normalizeId(projectName) + "'");
}
Aggregations