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, "查询成功!");
}
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;
}
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;
}
Aggregations