Search in sources :

Example 26 with StatusForbiddenException

use of top.hcode.hoj.common.exception.StatusForbiddenException in project HOJ by HimitZH.

the class GroupProblemManager method getProblemCases.

public List<ProblemCase> getProblemCases(Long pid, Boolean isUpload) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Problem problem = problemEntityService.getById(pid);
    if (problem == null) {
        throw new StatusNotFoundException("该题目不存在!");
    }
    Long gid = problem.getGid();
    Group group = groupEntityService.getById(gid);
    if (group == null || group.getStatus() == 1 && !isRoot) {
        throw new StatusNotFoundException("该团队不存在或已被封禁!");
    }
    if (!userRolesVo.getUsername().equals(problem.getAuthor()) && !isRoot && !groupValidator.isGroupRoot(userRolesVo.getUid(), gid)) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    QueryWrapper<ProblemCase> problemCaseQueryWrapper = new QueryWrapper<>();
    problemCaseQueryWrapper.eq("pid", pid).eq("status", 0);
    if (isUpload) {
        problemCaseQueryWrapper.last("order by length(input) asc,input asc");
    }
    return problemCaseEntityService.list(problemCaseQueryWrapper);
}
Also used : Group(top.hcode.hoj.pojo.entity.group.Group) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) StatusNotFoundException(top.hcode.hoj.common.exception.StatusNotFoundException) Problem(top.hcode.hoj.pojo.entity.problem.Problem) ProblemCase(top.hcode.hoj.pojo.entity.problem.ProblemCase) Session(org.apache.shiro.session.Session)

Example 27 with StatusForbiddenException

use of top.hcode.hoj.common.exception.StatusForbiddenException in project HOJ by HimitZH.

the class GroupProblemManager method compileInteractive.

public void compileInteractive(CompileDTO compileDTO, Long gid) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Group group = groupEntityService.getById(gid);
    if (group == null || group.getStatus() == 1 && !isRoot) {
        throw new StatusNotFoundException("该团队不存在或已被封禁!");
    }
    if (!isRoot && !groupValidator.isGroupAdmin(userRolesVo.getUid(), gid)) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    if (StringUtils.isEmpty(compileDTO.getCode()) || StringUtils.isEmpty(compileDTO.getLanguage())) {
        throw new StatusFailException("参数不能为空!");
    }
    compileDTO.setToken(judgeToken);
    dispatcher.dispatcherJudge("compile", "/compile-interactive", compileDTO);
}
Also used : Group(top.hcode.hoj.pojo.entity.group.Group) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) StatusNotFoundException(top.hcode.hoj.common.exception.StatusNotFoundException) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Session(org.apache.shiro.session.Session)

Example 28 with StatusForbiddenException

use of top.hcode.hoj.common.exception.StatusForbiddenException in project HOJ by HimitZH.

the class GroupTrainingManager method getAdminTrainingList.

public IPage<Training> getAdminTrainingList(Integer limit, Integer currentPage, Long gid) throws StatusNotFoundException, StatusForbiddenException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Group group = groupEntityService.getById(gid);
    if (group == null || group.getStatus() == 1 && !isRoot) {
        throw new StatusNotFoundException("该团队不存在或已被封禁!");
    }
    if (!isRoot && !groupValidator.isGroupAdmin(userRolesVo.getUid(), gid)) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    if (currentPage == null || currentPage < 1)
        currentPage = 1;
    if (limit == null || limit < 1)
        limit = 10;
    return groupTrainingEntityService.getAdminTrainingList(limit, currentPage, gid);
}
Also used : Group(top.hcode.hoj.pojo.entity.group.Group) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) StatusNotFoundException(top.hcode.hoj.common.exception.StatusNotFoundException) Session(org.apache.shiro.session.Session)

Example 29 with StatusForbiddenException

use of top.hcode.hoj.common.exception.StatusForbiddenException in project HOJ by HimitZH.

the class GroupTrainingManager method updateTraining.

@Transactional(rollbackFor = Exception.class)
public void updateTraining(TrainingDto trainingDto) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Long tid = trainingDto.getTraining().getId();
    Training training = trainingEntityService.getById(tid);
    if (training == null) {
        throw new StatusNotFoundException("该训练不存在!");
    }
    Long gid = training.getGid();
    Group group = groupEntityService.getById(gid);
    if (group == null || group.getStatus() == 1 && !isRoot) {
        throw new StatusNotFoundException("该团队不存在或已被封禁!");
    }
    if (!userRolesVo.getUsername().equals(training.getAuthor()) && !isRoot && !groupValidator.isGroupRoot(userRolesVo.getUid(), gid)) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    trainingDto.getTraining().setIsGroup(training.getIsGroup());
    trainingEntityService.updateById(trainingDto.getTraining());
    if (trainingDto.getTraining().getAuth().equals(Constants.Training.AUTH_PRIVATE.getValue())) {
        if (!Objects.equals(training.getPrivatePwd(), trainingDto.getTraining().getPrivatePwd())) {
            UpdateWrapper<TrainingRegister> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("tid", tid);
            trainingRegisterEntityService.remove(updateWrapper);
        }
    }
    TrainingCategory trainingCategory = trainingDto.getTrainingCategory();
    if (trainingCategory.getGid() != null && trainingCategory.getGid().longValue() != gid) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    if (trainingCategory.getId() == null) {
        try {
            trainingCategory.setGid(gid);
            trainingCategoryEntityService.save(trainingCategory);
        } catch (Exception ignored) {
            QueryWrapper<TrainingCategory> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("name", trainingCategory.getName());
            trainingCategory = trainingCategoryEntityService.getOne(queryWrapper, false);
        }
    }
    MappingTrainingCategory mappingTrainingCategory = mappingTrainingCategoryEntityService.getOne(new QueryWrapper<MappingTrainingCategory>().eq("tid", training.getId()), false);
    if (mappingTrainingCategory == null) {
        mappingTrainingCategoryEntityService.save(new MappingTrainingCategory().setTid(training.getId()).setCid(trainingCategory.getId()));
        adminTrainingRecordManager.checkSyncRecord(trainingDto.getTraining());
    } else {
        if (!mappingTrainingCategory.getCid().equals(trainingCategory.getId())) {
            UpdateWrapper<MappingTrainingCategory> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("tid", training.getId()).set("cid", trainingCategory.getId());
            boolean isOk = mappingTrainingCategoryEntityService.update(null, updateWrapper);
            if (isOk) {
                adminTrainingRecordManager.checkSyncRecord(trainingDto.getTraining());
            } else {
                throw new StatusFailException("修改失败");
            }
        }
    }
}
Also used : Group(top.hcode.hoj.pojo.entity.group.Group) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) StatusNotFoundException(top.hcode.hoj.common.exception.StatusNotFoundException) StatusNotFoundException(top.hcode.hoj.common.exception.StatusNotFoundException) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Session(org.apache.shiro.session.Session) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with StatusForbiddenException

use of top.hcode.hoj.common.exception.StatusForbiddenException in project HOJ by HimitZH.

the class GroupTrainingManager method addTraining.

@Transactional(rollbackFor = Exception.class)
public void addTraining(TrainingDto trainingDto) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Long gid = trainingDto.getTraining().getGid();
    Group group = groupEntityService.getById(gid);
    if (group == null || group.getStatus() == 1 && !isRoot) {
        throw new StatusNotFoundException("该团队不存在或已被封禁!");
    }
    if (!isRoot && !groupValidator.isGroupAdmin(userRolesVo.getUid(), gid)) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    trainingDto.getTraining().setIsGroup(true);
    Training training = trainingDto.getTraining();
    trainingEntityService.save(training);
    TrainingCategory trainingCategory = trainingDto.getTrainingCategory();
    if (trainingCategory.getGid() != null && trainingCategory.getGid() != gid) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    if (trainingCategory.getId() == null) {
        try {
            trainingCategory.setGid(gid);
            trainingCategoryEntityService.save(trainingCategory);
        } catch (Exception ignored) {
            QueryWrapper<TrainingCategory> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("name", trainingCategory.getName());
            trainingCategory = trainingCategoryEntityService.getOne(queryWrapper, false);
        }
    }
    boolean isOk = mappingTrainingCategoryEntityService.save(new MappingTrainingCategory().setTid(training.getId()).setCid(trainingCategory.getId()));
    if (!isOk) {
        throw new StatusFailException("添加失败!");
    }
}
Also used : Group(top.hcode.hoj.pojo.entity.group.Group) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) StatusNotFoundException(top.hcode.hoj.common.exception.StatusNotFoundException) StatusNotFoundException(top.hcode.hoj.common.exception.StatusNotFoundException) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Session(org.apache.shiro.session.Session) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

StatusForbiddenException (top.hcode.hoj.common.exception.StatusForbiddenException)113 Session (org.apache.shiro.session.Session)105 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)93 StatusFailException (top.hcode.hoj.common.exception.StatusFailException)78 StatusNotFoundException (top.hcode.hoj.common.exception.StatusNotFoundException)67 Group (top.hcode.hoj.pojo.entity.group.Group)64 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)52 Contest (top.hcode.hoj.pojo.entity.contest.Contest)32 Problem (top.hcode.hoj.pojo.entity.problem.Problem)21 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)20 Transactional (org.springframework.transaction.annotation.Transactional)15 ContestProblem (top.hcode.hoj.pojo.entity.contest.ContestProblem)13 Discussion (top.hcode.hoj.pojo.entity.discussion.Discussion)12 GroupMember (top.hcode.hoj.pojo.entity.group.GroupMember)6 JSONObject (cn.hutool.json.JSONObject)5 FileReader (cn.hutool.core.io.file.FileReader)4 FileWriter (cn.hutool.core.io.file.FileWriter)4 LinkedList (java.util.LinkedList)4 Judge (top.hcode.hoj.pojo.entity.judge.Judge)4 Tag (top.hcode.hoj.pojo.entity.problem.Tag)4