Search in sources :

Example 6 with ProjectUser

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;
}
Also used : ProjectUser(com.webank.wedatasphere.qualitis.project.entity.ProjectUser) ProjectResponse(com.webank.wedatasphere.qualitis.project.response.ProjectResponse) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse)

Example 7 with ProjectUser

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);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) ProjectUser(com.webank.wedatasphere.qualitis.project.entity.ProjectUser) Project(com.webank.wedatasphere.qualitis.project.entity.Project) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) User(com.webank.wedatasphere.qualitis.entity.User) ProjectUser(com.webank.wedatasphere.qualitis.project.entity.ProjectUser) ProjectUserResponse(com.webank.wedatasphere.qualitis.project.response.ProjectUserResponse) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with ProjectUser

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());
}
Also used : ProjectUser(com.webank.wedatasphere.qualitis.project.entity.ProjectUser) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) ArrayList(java.util.ArrayList)

Example 9 with ProjectUser

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());
}
Also used : Project(com.webank.wedatasphere.qualitis.project.entity.Project) ProjectUser(com.webank.wedatasphere.qualitis.project.entity.ProjectUser) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ProjectUser (com.webank.wedatasphere.qualitis.project.entity.ProjectUser)9 Transactional (org.springframework.transaction.annotation.Transactional)5 Project (com.webank.wedatasphere.qualitis.project.entity.Project)4 ArrayList (java.util.ArrayList)4 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)3 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)3 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)3 User (com.webank.wedatasphere.qualitis.entity.User)2 ProjectResponse (com.webank.wedatasphere.qualitis.project.response.ProjectResponse)2 ProjectUserResponse (com.webank.wedatasphere.qualitis.project.response.ProjectUserResponse)2 DataSourceQo (com.webank.wedatasphere.qualitis.query.queryqo.DataSourceQo)2 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)2 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)2 RoleDao (com.webank.wedatasphere.qualitis.dao.RoleDao)1 UserDao (com.webank.wedatasphere.qualitis.dao.UserDao)1 UserRoleDao (com.webank.wedatasphere.qualitis.dao.UserRoleDao)1 Role (com.webank.wedatasphere.qualitis.entity.Role)1 TaskDataSource (com.webank.wedatasphere.qualitis.entity.TaskDataSource)1 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)1 EventTypeEnum (com.webank.wedatasphere.qualitis.project.constant.EventTypeEnum)1