Search in sources :

Example 21 with StatusNotFoundException

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

the class GroupTrainingProblemManager method updateTrainingProblem.

public void updateTrainingProblem(TrainingProblem trainingProblem) throws StatusNotFoundException, StatusForbiddenException, StatusFailException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Training training = trainingEntityService.getById(trainingProblem.getTid());
    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("对不起,您无权限操作!");
    }
    boolean isOk = trainingProblemEntityService.updateById(trainingProblem);
    if (!isOk) {
        throw new StatusFailException("修改失败!");
    }
}
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 22 with StatusNotFoundException

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

the class GroupTrainingProblemManager method addProblemFromGroup.

@Transactional(rollbackFor = Exception.class)
public void addProblemFromGroup(String problemId, Long tid) throws StatusNotFoundException, StatusForbiddenException, StatusFailException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    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("对不起,您无权限操作!");
    }
    QueryWrapper<Problem> problemQueryWrapper = new QueryWrapper<>();
    problemQueryWrapper.eq("problem_id", problemId).eq("gid", gid);
    Problem problem = problemEntityService.getOne(problemQueryWrapper);
    if (problem == null) {
        throw new StatusNotFoundException("该题目不存在或不是团队题目!");
    }
    QueryWrapper<TrainingProblem> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("tid", tid).and(wrapper -> wrapper.eq("pid", problem.getId()).or().eq("display_id", problem.getProblemId()));
    TrainingProblem trainingProblem = trainingProblemEntityService.getOne(queryWrapper);
    if (trainingProblem != null) {
        throw new StatusFailException("添加失败,该题目已添加或者题目的训练展示ID已存在!");
    }
    TrainingProblem newTProblem = new TrainingProblem();
    boolean isOk = trainingProblemEntityService.save(newTProblem.setTid(tid).setPid(problem.getId()).setDisplayId(problem.getProblemId()));
    if (isOk) {
        UpdateWrapper<Training> trainingUpdateWrapper = new UpdateWrapper<>();
        trainingUpdateWrapper.set("gmt_modified", new Date()).eq("id", tid);
        trainingEntityService.update(trainingUpdateWrapper);
        adminTrainingRecordManager.syncAlreadyRegisterUserRecord(tid, problem.getId(), newTProblem.getId());
    } 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) Date(java.util.Date) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) Problem(top.hcode.hoj.pojo.entity.problem.Problem) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Session(org.apache.shiro.session.Session) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with StatusNotFoundException

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

the class GroupManager method getGroup.

public Group getGroup(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 (!group.getVisible() && !isRoot && !groupValidator.isGroupMember(userRolesVo.getUid(), gid)) {
        throw new StatusForbiddenException("该团队并非公开团队,不支持访问!");
    }
    if (!isRoot && !groupValidator.isGroupRoot(userRolesVo.getUid(), gid)) {
        group.setCode(null);
    }
    return group;
}
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 24 with StatusNotFoundException

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

the class GroupManager method getGroupAccess.

public AccessVo getGroupAccess(Long gid) throws StatusFailException, StatusNotFoundException, StatusForbiddenException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    boolean access = false;
    if (groupValidator.isGroupMember(userRolesVo.getUid(), gid) || isRoot) {
        access = true;
        Group group = groupEntityService.getById(gid);
        if (group == null || group.getStatus() == 1 && !isRoot) {
            throw new StatusNotFoundException("该团队不存在或已被封禁!");
        }
        if (!isRoot && !group.getVisible() && !groupValidator.isGroupMember(userRolesVo.getUid(), gid)) {
            throw new StatusForbiddenException("该团队并非公开团队,不支持访问!");
        }
    }
    AccessVo accessVo = new AccessVo();
    accessVo.setAccess(access);
    return accessVo;
}
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) AccessVo(top.hcode.hoj.pojo.vo.AccessVo) Session(org.apache.shiro.session.Session)

Example 25 with StatusNotFoundException

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

the class GroupAnnouncementManager method addAnnouncement.

public void addAnnouncement(Announcement announcement) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Long gid = announcement.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("对不起,您无权限操作!");
    }
    boolean isOk = announcementEntityService.save(announcement);
    if (!isOk) {
        throw new StatusFailException("添加失败");
    }
}
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)

Aggregations

StatusNotFoundException (top.hcode.hoj.common.exception.StatusNotFoundException)68 StatusForbiddenException (top.hcode.hoj.common.exception.StatusForbiddenException)67 Session (org.apache.shiro.session.Session)66 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)63 Group (top.hcode.hoj.pojo.entity.group.Group)61 StatusFailException (top.hcode.hoj.common.exception.StatusFailException)40 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)29 Contest (top.hcode.hoj.pojo.entity.contest.Contest)17 Problem (top.hcode.hoj.pojo.entity.problem.Problem)15 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)11 Transactional (org.springframework.transaction.annotation.Transactional)7 ContestProblem (top.hcode.hoj.pojo.entity.contest.ContestProblem)7 GroupMember (top.hcode.hoj.pojo.entity.group.GroupMember)5 Discussion (top.hcode.hoj.pojo.entity.discussion.Discussion)4 Tag (top.hcode.hoj.pojo.entity.problem.Tag)4 JSONObject (cn.hutool.json.JSONObject)3 Date (java.util.Date)3 Judge (top.hcode.hoj.pojo.entity.judge.Judge)3 IPage (com.baomidou.mybatisplus.core.metadata.IPage)2 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)2