Search in sources :

Example 1 with AdminContestVo

use of top.hcode.hoj.pojo.vo.AdminContestVo in project HOJ by HimitZH.

the class AdminContestController method getContest.

@GetMapping("")
@RequiresAuthentication
@RequiresRoles(value = { "root", "admin", "problem_admin" }, logical = Logical.OR)
public CommonResult getContest(@RequestParam("cid") Long cid, HttpServletRequest request) {
    // 获取本场比赛的状态
    Contest contest = contestService.getById(cid);
    if (contest == null) {
        // 查询不存在
        return CommonResult.errorResponse("查询失败:该比赛不存在,请检查参数cid是否准确!");
    }
    // 获取当前登录的用户
    HttpSession session = request.getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    // 是否为超级管理员
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    // 只有超级管理员和比赛拥有者才能操作
    if (!isRoot && !userRolesVo.getUid().equals(contest.getUid())) {
        return CommonResult.errorResponse("对不起,你无权限操作!", CommonResult.STATUS_FORBIDDEN);
    }
    AdminContestVo adminContestVo = BeanUtil.copyProperties(contest, AdminContestVo.class, "starAccount");
    if (StringUtils.isEmpty(contest.getStarAccount())) {
        adminContestVo.setStarAccount(new ArrayList<>());
    } else {
        JSONObject jsonObject = JSONUtil.parseObj(contest.getStarAccount());
        List<String> starAccount = jsonObject.get("star_account", List.class);
        adminContestVo.setStarAccount(starAccount);
    }
    return CommonResult.successResponse(adminContestVo, "查询成功!");
}
Also used : AdminContestVo(top.hcode.hoj.pojo.vo.AdminContestVo) JSONObject(cn.hutool.json.JSONObject) HttpSession(javax.servlet.http.HttpSession) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) Contest(top.hcode.hoj.pojo.entity.contest.Contest) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) RequiresRoles(org.apache.shiro.authz.annotation.RequiresRoles)

Example 2 with AdminContestVo

use of top.hcode.hoj.pojo.vo.AdminContestVo in project HOJ by HimitZH.

the class GroupContestManager method getContest.

public AdminContestVo getContest(Long cid) throws StatusForbiddenException, StatusNotFoundException, 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("对不起,您无权限操作!");
    }
    AdminContestVo adminContestVo = BeanUtil.copyProperties(contest, AdminContestVo.class, "starAccount");
    if (StringUtils.isEmpty(contest.getStarAccount())) {
        adminContestVo.setStarAccount(new ArrayList<>());
    } else {
        JSONObject jsonObject = JSONUtil.parseObj(contest.getStarAccount());
        List<String> starAccount = jsonObject.get("star_account", List.class);
        adminContestVo.setStarAccount(starAccount);
    }
    return adminContestVo;
}
Also used : Group(top.hcode.hoj.pojo.entity.group.Group) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) StatusNotFoundException(top.hcode.hoj.common.exception.StatusNotFoundException) AdminContestVo(top.hcode.hoj.pojo.vo.AdminContestVo) JSONObject(cn.hutool.json.JSONObject) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) Contest(top.hcode.hoj.pojo.entity.contest.Contest) Session(org.apache.shiro.session.Session)

Example 3 with AdminContestVo

use of top.hcode.hoj.pojo.vo.AdminContestVo in project HOJ by HimitZH.

the class AdminContestManager method getContest.

public AdminContestVo getContest(Long cid) throws StatusFailException, StatusForbiddenException {
    // 获取本场比赛的状态
    Contest contest = contestEntityService.getById(cid);
    if (contest == null) {
        // 查询不存在
        throw new StatusFailException("查询失败:该比赛不存在,请检查参数cid是否准确!");
    }
    // 获取当前登录的用户
    UserRolesVo userRolesVo = (UserRolesVo) SecurityUtils.getSubject().getSession().getAttribute("userInfo");
    // 是否为超级管理员
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    // 只有超级管理员和比赛拥有者才能操作
    if (!isRoot && !userRolesVo.getUid().equals(contest.getUid())) {
        throw new StatusForbiddenException("对不起,你无权限操作!");
    }
    AdminContestVo adminContestVo = BeanUtil.copyProperties(contest, AdminContestVo.class, "starAccount");
    if (StringUtils.isEmpty(contest.getStarAccount())) {
        adminContestVo.setStarAccount(new ArrayList<>());
    } else {
        JSONObject jsonObject = JSONUtil.parseObj(contest.getStarAccount());
        List<String> starAccount = jsonObject.get("star_account", List.class);
        adminContestVo.setStarAccount(starAccount);
    }
    return adminContestVo;
}
Also used : AdminContestVo(top.hcode.hoj.pojo.vo.AdminContestVo) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) JSONObject(cn.hutool.json.JSONObject) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Contest(top.hcode.hoj.pojo.entity.contest.Contest)

Aggregations

JSONObject (cn.hutool.json.JSONObject)3 Contest (top.hcode.hoj.pojo.entity.contest.Contest)3 AdminContestVo (top.hcode.hoj.pojo.vo.AdminContestVo)3 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)3 StatusForbiddenException (top.hcode.hoj.common.exception.StatusForbiddenException)2 HttpSession (javax.servlet.http.HttpSession)1 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)1 RequiresRoles (org.apache.shiro.authz.annotation.RequiresRoles)1 Session (org.apache.shiro.session.Session)1 StatusFailException (top.hcode.hoj.common.exception.StatusFailException)1 StatusNotFoundException (top.hcode.hoj.common.exception.StatusNotFoundException)1 Group (top.hcode.hoj.pojo.entity.group.Group)1