use of top.hcode.hoj.common.exception.StatusNotFoundException in project HOJ by HimitZH.
the class GroupTrainingProblemManager method updateTrainingProblem.
public void updateTrainingProblem(TrainingProblem trainingProblem) throws StatusNotFoundException, StatusForbiddenException, StatusFailException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
Training training = trainingEntityService.getById(trainingProblem.getTid());
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("对不起,您无权限操作!");
}
boolean isOk = trainingProblemEntityService.updateById(trainingProblem);
if (!isOk) {
throw new StatusFailException("修改失败!");
}
}
use of top.hcode.hoj.common.exception.StatusNotFoundException in project HOJ by HimitZH.
the class GroupTrainingProblemManager method addProblemFromGroup.
@Transactional(rollbackFor = Exception.class)
public void addProblemFromGroup(String problemId, Long tid) throws StatusNotFoundException, StatusForbiddenException, StatusFailException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
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("对不起,您无权限操作!");
}
QueryWrapper<Problem> problemQueryWrapper = new QueryWrapper<>();
problemQueryWrapper.eq("problem_id", problemId).eq("gid", gid);
Problem problem = problemEntityService.getOne(problemQueryWrapper);
if (problem == null) {
throw new StatusNotFoundException("该题目不存在或不是团队题目!");
}
QueryWrapper<TrainingProblem> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("tid", tid).and(wrapper -> wrapper.eq("pid", problem.getId()).or().eq("display_id", problem.getProblemId()));
TrainingProblem trainingProblem = trainingProblemEntityService.getOne(queryWrapper);
if (trainingProblem != null) {
throw new StatusFailException("添加失败,该题目已添加或者题目的训练展示ID已存在!");
}
TrainingProblem newTProblem = new TrainingProblem();
boolean isOk = trainingProblemEntityService.save(newTProblem.setTid(tid).setPid(problem.getId()).setDisplayId(problem.getProblemId()));
if (isOk) {
UpdateWrapper<Training> trainingUpdateWrapper = new UpdateWrapper<>();
trainingUpdateWrapper.set("gmt_modified", new Date()).eq("id", tid);
trainingEntityService.update(trainingUpdateWrapper);
adminTrainingRecordManager.syncAlreadyRegisterUserRecord(tid, problem.getId(), newTProblem.getId());
} else {
throw new StatusFailException("添加失败!");
}
}
use of top.hcode.hoj.common.exception.StatusNotFoundException in project HOJ by HimitZH.
the class GroupManager method getGroup.
public Group getGroup(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 (!group.getVisible() && !isRoot && !groupValidator.isGroupMember(userRolesVo.getUid(), gid)) {
throw new StatusForbiddenException("该团队并非公开团队,不支持访问!");
}
if (!isRoot && !groupValidator.isGroupRoot(userRolesVo.getUid(), gid)) {
group.setCode(null);
}
return group;
}
use of top.hcode.hoj.common.exception.StatusNotFoundException in project HOJ by HimitZH.
the class GroupManager method getGroupAccess.
public AccessVo getGroupAccess(Long gid) throws StatusFailException, StatusNotFoundException, StatusForbiddenException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
boolean access = false;
if (groupValidator.isGroupMember(userRolesVo.getUid(), gid) || isRoot) {
access = true;
Group group = groupEntityService.getById(gid);
if (group == null || group.getStatus() == 1 && !isRoot) {
throw new StatusNotFoundException("该团队不存在或已被封禁!");
}
if (!isRoot && !group.getVisible() && !groupValidator.isGroupMember(userRolesVo.getUid(), gid)) {
throw new StatusForbiddenException("该团队并非公开团队,不支持访问!");
}
}
AccessVo accessVo = new AccessVo();
accessVo.setAccess(access);
return accessVo;
}
use of top.hcode.hoj.common.exception.StatusNotFoundException in project HOJ by HimitZH.
the class GroupAnnouncementManager method addAnnouncement.
public void addAnnouncement(Announcement announcement) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
Long gid = announcement.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("对不起,您无权限操作!");
}
boolean isOk = announcementEntityService.save(announcement);
if (!isOk) {
throw new StatusFailException("添加失败");
}
}
Aggregations