添加成员时检查是否是重复添加
This commit is contained in:
parent
c23f5bd795
commit
8f80544a6c
|
@ -3,7 +3,6 @@ package io.metersphere.service;
|
||||||
import io.metersphere.base.domain.*;
|
import io.metersphere.base.domain.*;
|
||||||
import io.metersphere.base.mapper.*;
|
import io.metersphere.base.mapper.*;
|
||||||
import io.metersphere.base.mapper.ext.ExtUserRoleMapper;
|
import io.metersphere.base.mapper.ext.ExtUserRoleMapper;
|
||||||
import io.metersphere.commons.constants.RoleConstants;
|
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.CodingUtil;
|
import io.metersphere.commons.utils.CodingUtil;
|
||||||
import io.metersphere.controller.request.member.AddMemberRequest;
|
import io.metersphere.controller.request.member.AddMemberRequest;
|
||||||
|
@ -247,10 +246,17 @@ public class UserService {
|
||||||
return extUserRoleMapper.getMemberList(request);
|
return extUserRoleMapper.getMemberList(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void addMember(AddMemberRequest request) {
|
public void addMember(AddMemberRequest request) {
|
||||||
if (!CollectionUtils.isEmpty(request.getUserIds())) {
|
if (!CollectionUtils.isEmpty(request.getUserIds())) {
|
||||||
for (String userId : 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()) {
|
for (String roleId : request.getRoleIds()) {
|
||||||
UserRole userRole = new UserRole();
|
UserRole userRole = new UserRole();
|
||||||
userRole.setRoleId(roleId);
|
userRole.setRoleId(roleId);
|
||||||
|
@ -264,6 +270,7 @@ public class UserService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void deleteMember(String workspaceId, String userId) {
|
public void deleteMember(String workspaceId, String userId) {
|
||||||
UserRoleExample example = new UserRoleExample();
|
UserRoleExample example = new UserRoleExample();
|
||||||
|
@ -275,6 +282,14 @@ public class UserService {
|
||||||
public void addOrganizationMember(AddOrgMemberRequest request) {
|
public void addOrganizationMember(AddOrgMemberRequest request) {
|
||||||
if (!CollectionUtils.isEmpty(request.getUserIds())) {
|
if (!CollectionUtils.isEmpty(request.getUserIds())) {
|
||||||
for (String userId : 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()) {
|
for (String roleId : request.getRoleIds()) {
|
||||||
UserRole userRole = new UserRole();
|
UserRole userRole = new UserRole();
|
||||||
userRole.setId(UUID.randomUUID().toString());
|
userRole.setId(UUID.randomUUID().toString());
|
||||||
|
@ -288,6 +303,7 @@ public class UserService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void delOrganizationMember(String organizationId, String userId) {
|
public void delOrganizationMember(String organizationId, String userId) {
|
||||||
UserRoleExample userRoleExample = new UserRoleExample();
|
UserRoleExample userRoleExample = new UserRoleExample();
|
||||||
|
|
Loading…
Reference in New Issue