use of top.hcode.hoj.common.exception.StatusFailException 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("添加失败");
}
}
use of top.hcode.hoj.common.exception.StatusFailException 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("删除失败!");
}
}
use of top.hcode.hoj.common.exception.StatusFailException 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);
}
}
use of top.hcode.hoj.common.exception.StatusFailException 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());
}
}
}
use of top.hcode.hoj.common.exception.StatusFailException in project HOJ by HimitZH.
the class GroupMemberManager method updateMember.
public void updateMember(GroupMember groupMemberDto) throws StatusFailException, StatusForbiddenException, StatusNotFoundException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
Long gid = groupMemberDto.getGid();
Group group = groupEntityService.getById(gid);
if (group == null || group.getStatus() == 1 && !isRoot) {
throw new StatusNotFoundException("该团队不存在或已被封禁!");
}
if (group.getUid().equals(groupMemberDto.getUid())) {
throw new StatusNotFoundException("对不起,不允许操作团队的Owner权限!");
}
boolean isAgreedNewMember = false;
QueryWrapper<GroupMember> groupMemberQueryWrapper = new QueryWrapper<>();
groupMemberQueryWrapper.eq("gid", gid).eq("uid", userRolesVo.getUid()).in("auth", 4, 5);
GroupMember currentGroupMember = groupMemberEntityService.getOne(groupMemberQueryWrapper);
if (!isRoot && currentGroupMember == null) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
QueryWrapper<GroupMember> changeGroupMemberQueryWrapper = new QueryWrapper<>();
changeGroupMemberQueryWrapper.eq("gid", gid).eq("uid", groupMemberDto.getUid());
GroupMember changeGroupMember = groupMemberEntityService.getOne(changeGroupMemberQueryWrapper);
if (changeGroupMember == null) {
throw new StatusNotFoundException("该用户不在团队中!");
}
if (!isRoot && (changeGroupMember.getAuth() >= currentGroupMember.getAuth() || groupMemberDto.getAuth() >= currentGroupMember.getAuth())) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
boolean isOk = groupMemberEntityService.updateById(groupMemberDto);
if (!isOk) {
throw new StatusFailException("更新失败,请重新尝试!");
} else {
if (changeGroupMember.getAuth() <= 2) {
// 之前是申请中,则之后通过审批就要发消息
groupMemberEntityService.addWelcomeNoticeToGroupNewMember(gid, group.getName(), groupMemberDto.getUid());
}
}
}
Aggregations