添加成员时检查是否是重复添加

This commit is contained in:
shiziyuan9527 2020-03-03 15:09:31 +08:00
parent c23f5bd795
commit 8f80544a6c
1 changed files with 36 additions and 20 deletions

View File

@ -3,7 +3,6 @@ package io.metersphere.service;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtUserRoleMapper;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.CodingUtil;
import io.metersphere.controller.request.member.AddMemberRequest;
@ -247,10 +246,17 @@ public class UserService {
return extUserRoleMapper.getMemberList(request);
}
@Transactional(rollbackFor = Exception.class)
public void addMember(AddMemberRequest request) {
if (!CollectionUtils.isEmpty(request.getUserIds())) {
for (String userId : request.getUserIds()) {
UserRoleExample userRoleExample = new UserRoleExample();
userRoleExample.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(request.getWorkspaceId());
List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample);
if (userRoles.size() > 0) {
User user = userMapper.selectByPrimaryKey(userId);
String username = user.getName();
MSException.throwException("The user [" + username + "] already exists in the current workspace");
} else {
for (String roleId : request.getRoleIds()) {
UserRole userRole = new UserRole();
userRole.setRoleId(roleId);
@ -264,6 +270,7 @@ public class UserService {
}
}
}
}
public void deleteMember(String workspaceId, String userId) {
UserRoleExample example = new UserRoleExample();
@ -275,6 +282,14 @@ public class UserService {
public void addOrganizationMember(AddOrgMemberRequest request) {
if (!CollectionUtils.isEmpty(request.getUserIds())) {
for (String userId : request.getUserIds()) {
UserRoleExample userRoleExample = new UserRoleExample();
userRoleExample.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(request.getOrganizationId());
List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample);
if (userRoles.size() > 0) {
User user = userMapper.selectByPrimaryKey(userId);
String username = user.getName();
MSException.throwException("The user [" + username + "] already exists in the current organization");
} else {
for (String roleId : request.getRoleIds()) {
UserRole userRole = new UserRole();
userRole.setId(UUID.randomUUID().toString());
@ -288,6 +303,7 @@ public class UserService {
}
}
}
}
public void delOrganizationMember(String organizationId, String userId) {
UserRoleExample userRoleExample = new UserRoleExample();