Search in sources :

Example 11 with StatusNotFoundException

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

the class GroupMemberManager method updateMember.

public void updateMember(GroupMember groupMemberDto) throws StatusFailException, StatusForbiddenException, StatusNotFoundException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Long gid = groupMemberDto.getGid();
    Group group = groupEntityService.getById(gid);
    if (group == null || group.getStatus() == 1 && !isRoot) {
        throw new StatusNotFoundException("该团队不存在或已被封禁!");
    }
    if (group.getUid().equals(groupMemberDto.getUid())) {
        throw new StatusNotFoundException("对不起,不允许操作团队的Owner权限!");
    }
    boolean isAgreedNewMember = false;
    QueryWrapper<GroupMember> groupMemberQueryWrapper = new QueryWrapper<>();
    groupMemberQueryWrapper.eq("gid", gid).eq("uid", userRolesVo.getUid()).in("auth", 4, 5);
    GroupMember currentGroupMember = groupMemberEntityService.getOne(groupMemberQueryWrapper);
    if (!isRoot && currentGroupMember == null) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    QueryWrapper<GroupMember> changeGroupMemberQueryWrapper = new QueryWrapper<>();
    changeGroupMemberQueryWrapper.eq("gid", gid).eq("uid", groupMemberDto.getUid());
    GroupMember changeGroupMember = groupMemberEntityService.getOne(changeGroupMemberQueryWrapper);
    if (changeGroupMember == null) {
        throw new StatusNotFoundException("该用户不在团队中!");
    }
    if (!isRoot && (changeGroupMember.getAuth() >= currentGroupMember.getAuth() || groupMemberDto.getAuth() >= currentGroupMember.getAuth())) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    boolean isOk = groupMemberEntityService.updateById(groupMemberDto);
    if (!isOk) {
        throw new StatusFailException("更新失败,请重新尝试!");
    } else {
        if (changeGroupMember.getAuth() <= 2) {
            // 之前是申请中,则之后通过审批就要发消息
            groupMemberEntityService.addWelcomeNoticeToGroupNewMember(gid, group.getName(), groupMemberDto.getUid());
        }
    }
}
Also used : Group(top.hcode.hoj.pojo.entity.group.Group) GroupMember(top.hcode.hoj.pojo.entity.group.GroupMember) 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) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Session(org.apache.shiro.session.Session)

Example 12 with StatusNotFoundException

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

the class GroupProblemManager method changeProblemAuth.

public void changeProblemAuth(Long pid, Integer auth) 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("对不起,您无权限操作!");
    }
    UpdateWrapper<Problem> problemUpdateWrapper = new UpdateWrapper<>();
    problemUpdateWrapper.eq("id", pid).set("auth", auth).set("modified_user", userRolesVo.getUsername());
    boolean isOk = problemEntityService.update(problemUpdateWrapper);
    if (!isOk) {
        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) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) StatusNotFoundException(top.hcode.hoj.common.exception.StatusNotFoundException) Problem(top.hcode.hoj.pojo.entity.problem.Problem) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Session(org.apache.shiro.session.Session)

Example 13 with StatusNotFoundException

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

the class GroupProblemManager method getProblem.

public Problem getProblem(Long pid) 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 (!groupValidator.isGroupRoot(userRolesVo.getUid(), gid) && !userRolesVo.getUsername().equals(problem.getAuthor()) && !isRoot) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    return problem;
}
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) Problem(top.hcode.hoj.pojo.entity.problem.Problem) Session(org.apache.shiro.session.Session)

Example 14 with StatusNotFoundException

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

the class GroupProblemManager method addProblem.

public void addProblem(ProblemDto problemDto) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Long gid = problemDto.getProblem().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("对不起,您无权限操作!");
    }
    problemDto.getProblem().setProblemId(group.getShortName() + problemDto.getProblem().getProblemId());
    QueryWrapper<Problem> problemQueryWrapper = new QueryWrapper<>();
    problemQueryWrapper.eq("problem_id", problemDto.getProblem().getProblemId().toUpperCase());
    int sameProblemIDCount = problemEntityService.count(problemQueryWrapper);
    if (sameProblemIDCount > 0) {
        throw new StatusFailException("该题目的Problem ID已存在,请更换!");
    }
    problemDto.getProblem().setIsGroup(true);
    List<Tag> tagList = new LinkedList<>();
    for (Tag tag : problemDto.getTags()) {
        if (tag.getGid() != null && tag.getGid().longValue() != gid) {
            throw new StatusForbiddenException("对不起,您无权限操作!");
        }
        if (tag.getId() == null) {
            tag.setGid(gid);
        }
        tagList.add(tag);
    }
    problemDto.setTags(tagList);
    boolean isOk = problemEntityService.adminAddProblem(problemDto);
    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) LinkedList(java.util.LinkedList) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) Problem(top.hcode.hoj.pojo.entity.problem.Problem) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Tag(top.hcode.hoj.pojo.entity.problem.Tag) Session(org.apache.shiro.session.Session)

Example 15 with StatusNotFoundException

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

the class GroupProblemManager method getAllProblemTagsList.

public List<Tag> getAllProblemTagsList(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("对不起,您无权限操作!");
    }
    List<Tag> tagList;
    QueryWrapper<Tag> tagQueryWrapper = new QueryWrapper<>();
    tagQueryWrapper.isNull("gid").or().eq("gid", gid);
    tagList = tagEntityService.list(tagQueryWrapper);
    return tagList;
}
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) Tag(top.hcode.hoj.pojo.entity.problem.Tag) 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