use of com.webank.wedatasphere.qualitis.project.entity.ProjectUser in project Qualitis by WeBankFinTech.
the class ProjectServiceImpl method getAllProjectByUserReal.
@Override
public GetAllResponse<ProjectResponse> getAllProjectByUserReal(PageRequest request, Integer projectType) throws UnExpectedRequestException {
// Check Arguments
PageRequest.checkRequest(request);
// Get user name
String userName = HttpUtils.getUserName(httpServletRequest);
// Paging get project
int page = request.getPage();
int size = request.getSize();
List<ProjectUser> projectUsers = projectUserDao.findByUsernameAndPermissionAndProjectType(userName, projectType, page, size);
long total = projectUserDao.countByUsernameAndPermissionAndProjectType(userName, projectType);
List<ProjectResponse> projectResponses = new ArrayList<>();
for (ProjectUser projectUser : projectUsers) {
projectResponses.add(new ProjectResponse(projectUser.getProject()));
}
GetAllResponse<ProjectResponse> response = new GetAllResponse<>();
response.setData(projectResponses);
response.setTotal(total);
return response;
}
use of com.webank.wedatasphere.qualitis.project.entity.ProjectUser 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);
}
use of com.webank.wedatasphere.qualitis.project.entity.ProjectUser in project Qualitis by WeBankFinTech.
the class RuleQueryServiceImpl method getProjectsByUserPerm.
private List<RuleQueryProject> getProjectsByUserPerm(DataSourceQo param, List<ProjectUser> projectUsers, Map<Long, RuleQueryProject> projectMap) {
if (projectUsers == null || projectUsers.isEmpty()) {
return null;
}
for (ProjectUser projectUser : projectUsers) {
List<RuleDataSource> projectDataSources = ruleDataSourceDao.findByProjectUser(projectUser.getProject().getId(), param.getCluster(), param.getDb(), param.getTable());
if (projectDataSources == null || projectDataSources.isEmpty()) {
continue;
}
addRuleDataSource(projectDataSources, projectMap, projectUser.getProject());
}
return new ArrayList<>(projectMap.values());
}
use of com.webank.wedatasphere.qualitis.project.entity.ProjectUser in project Qualitis by WeBankFinTech.
the class ProjectUserRepositoryTest method test.
@Test
@Transactional
public void test() {
// 保存是否成功
Project project = new Project();
project.setName("junitProject");
project.setCreateUser("setCreateUser");
project.setCreateUserFullName("setCreateUserFullName");
project.setDescription("setDescription");
project.setUserDepartment("setUserDepartment");
Project saveProject = projectRepository.save(project);
assertTrue(saveProject.getId() != 0);
ProjectUser saveEntity = new ProjectUser(ProjectUserPermissionEnum.CREATOR.getCode(), project, "v_wblwyan_test", "颜龙武");
ProjectUser entity = repository.save(saveEntity);
// 根据username查询的数据库对象是否和保存的值一致
List<ProjectUser> findByUserNameList = repository.findByUserName(entity.getUserName());
assertTrue(findByUserNameList.size() > 0);
assertEquals(findByUserNameList.get(0).getUserName(), entity.getUserName());
// 删除后,是否还能找到对象
repository.deleteByProject(project);
List<ProjectUser> deleteEntity = repository.findByUserName(entity.getUserName());
assertTrue(deleteEntity.isEmpty());
}
Aggregations