use of top.hcode.hoj.common.exception.StatusNotFoundException 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());
}
}
}
use of top.hcode.hoj.common.exception.StatusNotFoundException in project HOJ by HimitZH.
the class GroupProblemManager method changeProblemAuth.
public void changeProblemAuth(Long pid, Integer auth) 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("对不起,您无权限操作!");
}
UpdateWrapper<Problem> problemUpdateWrapper = new UpdateWrapper<>();
problemUpdateWrapper.eq("id", pid).set("auth", auth).set("modified_user", userRolesVo.getUsername());
boolean isOk = problemEntityService.update(problemUpdateWrapper);
if (!isOk) {
throw new StatusFailException("修改失败");
}
}
use of top.hcode.hoj.common.exception.StatusNotFoundException in project HOJ by HimitZH.
the class GroupProblemManager method getProblem.
public Problem getProblem(Long pid) 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 (!groupValidator.isGroupRoot(userRolesVo.getUid(), gid) && !userRolesVo.getUsername().equals(problem.getAuthor()) && !isRoot) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
return problem;
}
use of top.hcode.hoj.common.exception.StatusNotFoundException in project HOJ by HimitZH.
the class GroupProblemManager method addProblem.
public void addProblem(ProblemDto problemDto) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
Long gid = problemDto.getProblem().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("对不起,您无权限操作!");
}
problemDto.getProblem().setProblemId(group.getShortName() + problemDto.getProblem().getProblemId());
QueryWrapper<Problem> problemQueryWrapper = new QueryWrapper<>();
problemQueryWrapper.eq("problem_id", problemDto.getProblem().getProblemId().toUpperCase());
int sameProblemIDCount = problemEntityService.count(problemQueryWrapper);
if (sameProblemIDCount > 0) {
throw new StatusFailException("该题目的Problem ID已存在,请更换!");
}
problemDto.getProblem().setIsGroup(true);
List<Tag> tagList = new LinkedList<>();
for (Tag tag : problemDto.getTags()) {
if (tag.getGid() != null && tag.getGid().longValue() != gid) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
if (tag.getId() == null) {
tag.setGid(gid);
}
tagList.add(tag);
}
problemDto.setTags(tagList);
boolean isOk = problemEntityService.adminAddProblem(problemDto);
if (!isOk) {
throw new StatusFailException("添加失败");
}
}
use of top.hcode.hoj.common.exception.StatusNotFoundException in project HOJ by HimitZH.
the class GroupProblemManager method getAllProblemTagsList.
public List<Tag> getAllProblemTagsList(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("对不起,您无权限操作!");
}
List<Tag> tagList;
QueryWrapper<Tag> tagQueryWrapper = new QueryWrapper<>();
tagQueryWrapper.isNull("gid").or().eq("gid", gid);
tagList = tagEntityService.list(tagQueryWrapper);
return tagList;
}
Aggregations