use of com.webank.wedatasphere.qualitis.project.response.ProjectUserResponse in project Qualitis by WeBankFinTech.
the class ProjectUserServiceImpl method getAllProjectUser.
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = true, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<List<ProjectUserResponse>> getAllProjectUser(Long projectId) throws UnExpectedRequestException, PermissionDeniedRequestException {
List<ProjectUserResponse> projectUserResponses = new ArrayList<>();
Project projectInDb = projectDao.findById(projectId);
if (projectInDb == null) {
throw new UnExpectedRequestException("{&PROJECT}: [ID=" + projectId + "] {&DOES_NOT_EXIST}");
}
String userName = HttpUtils.getUserName(httpRequest);
List<ProjectUser> projectUsers = projectUserDao.findByProject(projectInDb);
List<String> projectUserNames = projectUsers.stream().map(ProjectUser::getUserName).collect(Collectors.toList());
if (!projectUserNames.contains(userName)) {
throw new PermissionDeniedRequestException("{&HAS_NO_PERMISSION_TO_ACCESS}", 403);
}
for (ProjectUser currentProjectUser : projectUsers) {
List<String> userNames = projectUserResponses.stream().map(ProjectUserResponse::getAuthorizedUser).collect(Collectors.toList());
String currentUser = currentProjectUser.getUserName();
if (userNames.contains(currentUser)) {
continue;
}
String projectCreator = projectInDb.getCreateUser();
ProjectUserResponse projectUserResponse = new ProjectUserResponse(projectInDb.getName(), projectCreator, currentUser);
List<Integer> permissions = getPermissionList(projectUsers, currentUser);
projectUserResponse.setPermissions(permissions);
projectUserResponses.add(projectUserResponse);
}
return new GeneralResponse<>("200", "{&SUCCESS_TO_GET_PROJECT_USER}", projectUserResponses);
}
use of com.webank.wedatasphere.qualitis.project.response.ProjectUserResponse in project Qualitis by WeBankFinTech.
the class ProjectUserServiceImpl method authorizePermission.
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<ProjectUserResponse> authorizePermission(AuthorizeProjectUserRequest authorizeProjectUserRequest, Long loginUserId, boolean modify) throws UnExpectedRequestException, PermissionDeniedRequestException, RoleNotFoundException {
List<ProjectUser> projectUsers = new ArrayList<>();
AuthorizeProjectUserRequest.checkRequest(authorizeProjectUserRequest);
Project projectInDb = projectDao.findById(authorizeProjectUserRequest.getProjectId());
String projectUser = authorizeProjectUserRequest.getProjectUser();
LOGGER.info("User[id={}] start to authorize user[name={}]", loginUserId, projectUser);
if (projectInDb == null) {
throw new UnExpectedRequestException("{&PROJECT}: [ID=" + authorizeProjectUserRequest.getProjectId() + "] {&DOES_NOT_EXIST}");
}
User projectUserInDb = userDao.findByUsername(projectUser);
if (projectUserInDb == null) {
LOGGER.warn("Project user is from outside, qualitis will auto add user. Name: " + projectUser);
userService.autoAddUser(projectUser);
}
User loginUser = userDao.findById(loginUserId);
if (!checkPermission(projectInDb, loginUser.getUserName(), ProjectUserPermissionEnum.CREATOR.getCode())) {
throw new PermissionDeniedRequestException("{&NO_PERMISSION_MODIFYING_PROJECT}", 403);
}
if (loginUser.getUserName().equals(projectUser)) {
return null;
}
List<Integer> permissions = new ArrayList<>();
if (modify) {
projectUserDao.deleteByProjectAndUserName(projectInDb, projectUser);
LOGGER.info("Success to delete original project user permissions.");
}
for (Integer permission : authorizeProjectUserRequest.getProjectPermissions()) {
ProjectUser tmp = new ProjectUser(permission, projectInDb, projectUser);
LOGGER.info("User[name={}] get permission[ID={}].", projectUser, permission);
projectUsers.add(tmp);
permissions.add(permission);
}
projectUserDao.saveAll(projectUsers);
// projectEventService.record(projectInDb.getId(), loginUser.getUserName(), "authorized", projectUser, EventTypeEnum.MODIFY_PROJECT.getCode());
ProjectUserResponse projectUserResponse = new ProjectUserResponse(projectInDb.getName(), loginUser.getUserName(), projectUser);
projectUserResponse.setPermissions(permissions);
return new GeneralResponse<>("200", "{&SUCCESS_TO_ADD_PROJECT_USER}", projectUserResponse);
}
Aggregations