Search in sources :

Example 6 with StatusNotFoundException

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

the class GroupContestProblemManager method addProblemFromPublic.

public void addProblemFromPublic(ContestProblemDto contestProblemDto) throws StatusNotFoundException, StatusForbiddenException, StatusFailException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Long pid = contestProblemDto.getPid();
    Problem problem = problemEntityService.getById(pid);
    if (problem == null || problem.getAuth() != 1 || problem.getIsGroup()) {
        throw new StatusNotFoundException("该题目不存在或已被隐藏!");
    }
    Long cid = contestProblemDto.getCid();
    Contest contest = contestEntityService.getById(cid);
    if (contest == null) {
        throw new StatusNotFoundException("该比赛不存在!");
    }
    Long gid = contest.getGid();
    Group group = groupEntityService.getById(gid);
    if (group == null || group.getStatus() == 1 && !isRoot) {
        throw new StatusNotFoundException("该团队不存在或已被封禁!");
    }
    if (!userRolesVo.getUid().equals(contest.getUid()) && !isRoot && !groupValidator.isGroupRoot(userRolesVo.getUid(), gid)) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    String displayId = contestProblemDto.getDisplayId();
    QueryWrapper<ContestProblem> contestProblemQueryWrapper = new QueryWrapper<>();
    contestProblemQueryWrapper.eq("cid", cid).and(wrapper -> wrapper.eq("pid", pid).or().eq("display_id", displayId));
    ContestProblem contestProblem = contestProblemEntityService.getOne(contestProblemQueryWrapper, false);
    if (contestProblem != null) {
        throw new StatusFailException("添加失败,该题目已添加或者题目的比赛展示ID已存在!");
    }
    String displayName = problem.getTitle();
    ContestProblem newCProblem = new ContestProblem();
    boolean isOk = contestProblemEntityService.saveOrUpdate(newCProblem.setCid(cid).setPid(pid).setDisplayTitle(displayName).setDisplayId(displayId));
    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) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) Problem(top.hcode.hoj.pojo.entity.problem.Problem) ContestProblem(top.hcode.hoj.pojo.entity.contest.ContestProblem) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Contest(top.hcode.hoj.pojo.entity.contest.Contest) ContestProblem(top.hcode.hoj.pojo.entity.contest.ContestProblem) Session(org.apache.shiro.session.Session)

Example 7 with StatusNotFoundException

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

the class GroupContestProblemManager method deleteContestProblem.

public void deleteContestProblem(Long pid, Long cid) throws StatusNotFoundException, StatusForbiddenException, StatusFailException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Contest contest = contestEntityService.getById(cid);
    if (contest == null) {
        throw new StatusNotFoundException("该比赛不存在!");
    }
    Long gid = contest.getGid();
    Group group = groupEntityService.getById(gid);
    if (group == null || group.getStatus() == 1 && !isRoot) {
        throw new StatusNotFoundException("该团队不存在或已被封禁!");
    }
    if (!userRolesVo.getUid().equals(contest.getUid()) && !isRoot && !groupValidator.isGroupRoot(userRolesVo.getUid(), gid)) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    QueryWrapper<ContestProblem> contestProblemQueryWrapper = new QueryWrapper<>();
    contestProblemQueryWrapper.eq("cid", cid).eq("pid", pid);
    boolean isOk = contestProblemEntityService.remove(contestProblemQueryWrapper);
    if (isOk) {
        UpdateWrapper<Judge> judgeUpdateWrapper = new UpdateWrapper<>();
        judgeUpdateWrapper.eq("cid", cid).eq("pid", pid);
        judgeEntityService.remove(judgeUpdateWrapper);
    } 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) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Contest(top.hcode.hoj.pojo.entity.contest.Contest) ContestProblem(top.hcode.hoj.pojo.entity.contest.ContestProblem) Judge(top.hcode.hoj.pojo.entity.judge.Judge) Session(org.apache.shiro.session.Session)

Example 8 with StatusNotFoundException

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

the class GroupDiscussionManager method getDiscussionList.

public IPage<Discussion> getDiscussionList(Integer limit, Integer currentPage, Long gid, String pid) 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 (!groupValidator.isGroupMember(userRolesVo.getUid(), gid) && !isRoot) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    QueryWrapper<Discussion> discussionQueryWrapper = new QueryWrapper<>();
    if (!StringUtils.isEmpty(pid)) {
        discussionQueryWrapper.eq("pid", pid);
    }
    IPage<Discussion> iPage = new Page<>(currentPage, limit);
    discussionQueryWrapper.eq("status", 0).eq("gid", gid).orderByDesc("top_priority").orderByDesc("gmt_create").orderByDesc("like_num").orderByDesc("view_num");
    return discussionEntityService.page(iPage, discussionQueryWrapper);
}
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) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) Discussion(top.hcode.hoj.pojo.entity.discussion.Discussion) Session(org.apache.shiro.session.Session)

Example 9 with StatusNotFoundException

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

the class GroupMemberManager method deleteMember.

public void deleteMember(String uid, Long gid) throws StatusFailException, 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 (userRolesVo.getUid().equals(uid)) {
        throw new StatusNotFoundException("对不起,您无法删除自己!");
    }
    if (group.getUid().equals(uid)) {
        throw new StatusNotFoundException("对不起,不允许删除团队的Owner!");
    }
    QueryWrapper<GroupMember> groupMemberQueryWrapper = new QueryWrapper<>();
    groupMemberQueryWrapper.eq("gid", gid).eq("uid", userRolesVo.getUid()).in("auth", 4, 5);
    GroupMember currentGroupMember = groupMemberEntityService.getOne(groupMemberQueryWrapper);
    if (currentGroupMember == null && !isRoot) {
        throw new StatusForbiddenException("对不起,您无权限操作!");
    }
    QueryWrapper<GroupMember> changeGroupMemberQueryWrapper = new QueryWrapper<>();
    changeGroupMemberQueryWrapper.eq("gid", gid).eq("uid", uid);
    GroupMember changeGroupMember = groupMemberEntityService.getOne(changeGroupMemberQueryWrapper);
    if (changeGroupMember == null) {
        throw new StatusNotFoundException("该用户不在团队中!");
    }
    if (!isRoot && currentGroupMember.getAuth() <= changeGroupMember.getAuth()) {
        throw new StatusNotFoundException("对不起,您无权限操作!");
    }
    boolean isOk = groupMemberEntityService.remove(changeGroupMemberQueryWrapper);
    if (!isOk) {
        throw new StatusFailException("删除失败,请重新尝试!");
    } else {
        groupMemberEntityService.addRemoveNoticeToGroupMember(gid, group.getName(), userRolesVo.getUsername(), uid);
    }
}
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 10 with StatusNotFoundException

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

the class GroupMemberManager method addMember.

public void addMember(Long gid, String code, String reason) throws StatusFailException, 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) {
        throw new StatusNotFoundException("该团队不存在!");
    }
    if (!isRoot && (group.getStatus() == 1 || !group.getVisible())) {
        throw new StatusNotFoundException("该团队已被封禁或未公开显示!");
    }
    if (group.getAuth() == 3 && !code.equals(group.getCode())) {
        throw new StatusFailException("邀请码错误,请重新尝试!");
    }
    if (group.getAuth() != 1 && !StringUtils.isEmpty(reason) && (reason.length() < 5 || reason.length() > 100)) {
        throw new StatusFailException("申请理由的长度应为 5 到 100!");
    }
    QueryWrapper<GroupMember> groupMemberQueryWrapper = new QueryWrapper<>();
    groupMemberQueryWrapper.eq("uid", userRolesVo.getUid()).eq("gid", gid);
    GroupMember groupMember = groupMemberEntityService.getOne(groupMemberQueryWrapper);
    if (groupMember != null) {
        if (groupMember.getAuth() == 1) {
            throw new StatusForbiddenException("您已申请过,请勿重复申请!");
        } else if (groupMember.getAuth() >= 3) {
            throw new StatusForbiddenException("您已经加入了该团队,请勿再申请!!");
        }
    }
    GroupMember newGroupMember = new GroupMember();
    newGroupMember.setUid(userRolesVo.getUid()).setGid(gid).setReason(reason);
    if (group.getAuth() == 1) {
        newGroupMember.setAuth(3);
    } else {
        newGroupMember.setAuth(1);
    }
    boolean isOk = groupMemberEntityService.save(newGroupMember);
    if (!isOk) {
        throw new StatusFailException("申请失败,请重新尝试!");
    } else {
        if (group.getAuth() == 1) {
            groupMemberEntityService.addWelcomeNoticeToGroupNewMember(gid, group.getName(), userRolesVo.getUid());
        } else {
            groupMemberEntityService.addApplyNoticeToGroupRoot(gid, group.getName(), userRolesVo.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)

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