use of top.hcode.hoj.common.exception.StatusForbiddenException in project HOJ by HimitZH.
the class GroupProblemManager method getProblemCases.
public List<ProblemCase> getProblemCases(Long pid, Boolean isUpload) 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("对不起,您无权限操作!");
}
QueryWrapper<ProblemCase> problemCaseQueryWrapper = new QueryWrapper<>();
problemCaseQueryWrapper.eq("pid", pid).eq("status", 0);
if (isUpload) {
problemCaseQueryWrapper.last("order by length(input) asc,input asc");
}
return problemCaseEntityService.list(problemCaseQueryWrapper);
}
use of top.hcode.hoj.common.exception.StatusForbiddenException in project HOJ by HimitZH.
the class GroupProblemManager method compileInteractive.
public void compileInteractive(CompileDTO compileDTO, Long gid) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
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("对不起,您无权限操作!");
}
if (StringUtils.isEmpty(compileDTO.getCode()) || StringUtils.isEmpty(compileDTO.getLanguage())) {
throw new StatusFailException("参数不能为空!");
}
compileDTO.setToken(judgeToken);
dispatcher.dispatcherJudge("compile", "/compile-interactive", compileDTO);
}
use of top.hcode.hoj.common.exception.StatusForbiddenException in project HOJ by HimitZH.
the class GroupTrainingManager method getAdminTrainingList.
public IPage<Training> getAdminTrainingList(Integer limit, Integer currentPage, 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("对不起,您无权限操作!");
}
if (currentPage == null || currentPage < 1)
currentPage = 1;
if (limit == null || limit < 1)
limit = 10;
return groupTrainingEntityService.getAdminTrainingList(limit, currentPage, gid);
}
use of top.hcode.hoj.common.exception.StatusForbiddenException in project HOJ by HimitZH.
the class GroupTrainingManager method updateTraining.
@Transactional(rollbackFor = Exception.class)
public void updateTraining(TrainingDto trainingDto) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
Long tid = trainingDto.getTraining().getId();
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("对不起,您无权限操作!");
}
trainingDto.getTraining().setIsGroup(training.getIsGroup());
trainingEntityService.updateById(trainingDto.getTraining());
if (trainingDto.getTraining().getAuth().equals(Constants.Training.AUTH_PRIVATE.getValue())) {
if (!Objects.equals(training.getPrivatePwd(), trainingDto.getTraining().getPrivatePwd())) {
UpdateWrapper<TrainingRegister> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("tid", tid);
trainingRegisterEntityService.remove(updateWrapper);
}
}
TrainingCategory trainingCategory = trainingDto.getTrainingCategory();
if (trainingCategory.getGid() != null && trainingCategory.getGid().longValue() != gid) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
if (trainingCategory.getId() == null) {
try {
trainingCategory.setGid(gid);
trainingCategoryEntityService.save(trainingCategory);
} catch (Exception ignored) {
QueryWrapper<TrainingCategory> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("name", trainingCategory.getName());
trainingCategory = trainingCategoryEntityService.getOne(queryWrapper, false);
}
}
MappingTrainingCategory mappingTrainingCategory = mappingTrainingCategoryEntityService.getOne(new QueryWrapper<MappingTrainingCategory>().eq("tid", training.getId()), false);
if (mappingTrainingCategory == null) {
mappingTrainingCategoryEntityService.save(new MappingTrainingCategory().setTid(training.getId()).setCid(trainingCategory.getId()));
adminTrainingRecordManager.checkSyncRecord(trainingDto.getTraining());
} else {
if (!mappingTrainingCategory.getCid().equals(trainingCategory.getId())) {
UpdateWrapper<MappingTrainingCategory> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("tid", training.getId()).set("cid", trainingCategory.getId());
boolean isOk = mappingTrainingCategoryEntityService.update(null, updateWrapper);
if (isOk) {
adminTrainingRecordManager.checkSyncRecord(trainingDto.getTraining());
} else {
throw new StatusFailException("修改失败");
}
}
}
}
use of top.hcode.hoj.common.exception.StatusForbiddenException in project HOJ by HimitZH.
the class GroupTrainingManager method addTraining.
@Transactional(rollbackFor = Exception.class)
public void addTraining(TrainingDto trainingDto) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
Long gid = trainingDto.getTraining().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("对不起,您无权限操作!");
}
trainingDto.getTraining().setIsGroup(true);
Training training = trainingDto.getTraining();
trainingEntityService.save(training);
TrainingCategory trainingCategory = trainingDto.getTrainingCategory();
if (trainingCategory.getGid() != null && trainingCategory.getGid() != gid) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
if (trainingCategory.getId() == null) {
try {
trainingCategory.setGid(gid);
trainingCategoryEntityService.save(trainingCategory);
} catch (Exception ignored) {
QueryWrapper<TrainingCategory> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("name", trainingCategory.getName());
trainingCategory = trainingCategoryEntityService.getOne(queryWrapper, false);
}
}
boolean isOk = mappingTrainingCategoryEntityService.save(new MappingTrainingCategory().setTid(training.getId()).setCid(trainingCategory.getId()));
if (!isOk) {
throw new StatusFailException("添加失败!");
}
}
Aggregations