use of top.hcode.hoj.pojo.entity.group.GroupMember in project HOJ by HimitZH.
the class ContestCalculateRankManager method getSuperAdminUidList.
private List<String> getSuperAdminUidList(Long gid) {
List<String> superAdminUidList = userInfoEntityService.getSuperAdminUidList();
if (gid != null) {
QueryWrapper<GroupMember> groupMemberQueryWrapper = new QueryWrapper<>();
groupMemberQueryWrapper.eq("gid", gid).eq("auth", 5);
List<GroupMember> groupRootList = groupMemberEntityService.list(groupMemberQueryWrapper);
for (GroupMember groupMember : groupRootList) {
superAdminUidList.add(groupMember.getUid());
}
}
return superAdminUidList;
}
use of top.hcode.hoj.pojo.entity.group.GroupMember 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.pojo.entity.group.GroupMember 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.pojo.entity.group.GroupMember 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.pojo.entity.group.GroupMember in project HOJ by HimitZH.
the class GroupManager method getGroupAuth.
public Integer getGroupAuth(Long gid) {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
QueryWrapper<GroupMember> groupMemberQueryWrapper = new QueryWrapper<>();
groupMemberQueryWrapper.eq("gid", gid).eq("uid", userRolesVo.getUid());
GroupMember groupMember = groupMemberEntityService.getOne(groupMemberQueryWrapper);
Integer auth = 0;
if (groupMember != null) {
auth = groupMember.getAuth();
}
return auth;
}
Aggregations