Search in sources :

Example 1 with TemplateUser

use of com.webank.wedatasphere.qualitis.rule.entity.TemplateUser in project Qualitis by WeBankFinTech.

the class RuleTemplateServiceImpl method deleteRuleTemplate.

@Override
public void deleteRuleTemplate(Long templateId) throws UnExpectedRequestException, PermissionDeniedRequestException {
    // Check template existence
    Template templateInDb = checkRuleTemplate(templateId);
    // Check operator permission
    User userInDb = userDao.findById(HttpUtils.getUserId(httpServletRequest));
    List<UserRole> userRoles = userRoleDao.findByUser(userInDb);
    Integer roleType = roleService.getRoleType(userRoles);
    if (roleType.equals(RoleDefaultTypeEnum.PROJECTOR.getCode())) {
        LOGGER.info("The projector is going to delete template.");
        if (templateInDb.getLevel().intValue() != RuleTemplateLevelEnum.PERSONAL_TEMPLATE.getCode()) {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
        if (userInDb.getId() != (templateInDb.getCreateUser().getId())) {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
    } else if (roleType.equals(RoleDefaultTypeEnum.DEPARTMENT_ADMIN.getCode())) {
        LOGGER.info("The department admin is going to delete template.");
        if (templateInDb.getLevel().intValue() == RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode()) {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
        List<User> createUsers = new ArrayList<>();
        for (UserRole userRole : userRoles) {
            Department department = userRole.getRole().getDepartment();
            if (department != null) {
                List<User> userList = userDao.findByDepartment(department);
                createUsers.addAll(userList);
            }
        }
        boolean exist = false;
        for (User user : createUsers) {
            if (user.getId() == templateInDb.getCreateUser().getId()) {
                exist = true;
                break;
            }
        }
        if (!exist) {
            throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
        }
    } else {
        if (templateInDb.getLevel().equals(RuleTemplateLevelEnum.DEFAULT_TEMPLATE.getCode())) {
            if (templateInDb.getCreateUser() == null || !userInDb.getUserName().equals(templateInDb.getCreateUser().getUserName())) {
                throw new PermissionDeniedRequestException("User {&HAS_NO_PERMISSION_TO_ACCESS}", 403);
            }
        }
        LOGGER.info("The system admin is going to delete template.");
    }
    // Check rules of template
    ruleService.checkRuleOfTemplate(templateInDb);
    // Delete 'Templatedepartment' or 'TemplateUser'
    clearTemplateUser(templateInDb);
    List<TemplateDataSourceType> templateDataSourceTypes = templateDataSourceTypeDao.findByTemplate(templateInDb);
    for (TemplateDataSourceType templateDataSourceType : templateDataSourceTypes) {
        templateDataSourceTypeDao.delete(templateDataSourceType);
    }
    ruleTemplateDao.deleteTemplate(templateInDb);
}
Also used : PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) Department(com.webank.wedatasphere.qualitis.entity.Department) TemplateDepartment(com.webank.wedatasphere.qualitis.rule.entity.TemplateDepartment) TemplateUser(com.webank.wedatasphere.qualitis.rule.entity.TemplateUser) User(com.webank.wedatasphere.qualitis.entity.User) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) List(java.util.List) ArrayList(java.util.ArrayList) TemplateDataSourceType(com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType) Template(com.webank.wedatasphere.qualitis.rule.entity.Template)

Example 2 with TemplateUser

use of com.webank.wedatasphere.qualitis.rule.entity.TemplateUser in project Qualitis by WeBankFinTech.

the class RuleTemplateServiceImpl method saveTemplateUser.

private void saveTemplateUser(User user, Template template) {
    TemplateUser templateUser = new TemplateUser();
    templateUser.setUser(user);
    templateUser.setTemplate(template);
    templateUserDao.saveTemplateUser(templateUser);
    LOGGER.info("Succeed to save user template.");
}
Also used : TemplateUser(com.webank.wedatasphere.qualitis.rule.entity.TemplateUser)

Aggregations

TemplateUser (com.webank.wedatasphere.qualitis.rule.entity.TemplateUser)2 Department (com.webank.wedatasphere.qualitis.entity.Department)1 User (com.webank.wedatasphere.qualitis.entity.User)1 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)1 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)1 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)1 TemplateDataSourceType (com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType)1 TemplateDepartment (com.webank.wedatasphere.qualitis.rule.entity.TemplateDepartment)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1