diff --git a/backend/src/main/java/io/metersphere/service/UserService.java b/backend/src/main/java/io/metersphere/service/UserService.java index 00388570b0..2c8815b1db 100644 --- a/backend/src/main/java/io/metersphere/service/UserService.java +++ b/backend/src/main/java/io/metersphere/service/UserService.java @@ -195,6 +195,17 @@ public class UserService { String userId = user.getId(); UserRoleExample userRoleExample = new UserRoleExample(); userRoleExample.createCriteria().andUserIdEqualTo(userId); + List userRoles = userRoleMapper.selectByExample(userRoleExample); + List list = userRoles.stream().map(UserRole::getSourceId).collect(Collectors.toList()); + + if (!CollectionUtils.isEmpty(list)) { + if (list.contains(user.getLastWorkspaceId()) || list.contains(user.getLastOrganizationId())) { + user.setLastOrganizationId(""); + user.setLastWorkspaceId(""); + userMapper.updateByPrimaryKeySelective(user); + } + } + userRoleMapper.deleteByExample(userRoleExample); List> roles = user.getRoles(); if (!roles.isEmpty()) { @@ -275,6 +286,14 @@ public class UserService { UserRoleExample example = new UserRoleExample(); example.createCriteria().andRoleIdLike("%test%") .andUserIdEqualTo(userId).andSourceIdEqualTo(workspaceId); + + User user = userMapper.selectByPrimaryKey(userId); + if (StringUtils.equals(workspaceId, user.getLastWorkspaceId())) { + user.setLastWorkspaceId(""); + user.setLastOrganizationId(""); + userMapper.updateByPrimaryKeySelective(user); + } + userRoleMapper.deleteByExample(example); } @@ -305,6 +324,14 @@ public class UserService { public void delOrganizationMember(String organizationId, String userId) { UserRoleExample userRoleExample = new UserRoleExample(); userRoleExample.createCriteria().andRoleIdLike("%org%").andUserIdEqualTo(userId).andSourceIdEqualTo(organizationId); + + User user = userMapper.selectByPrimaryKey(userId); + if (StringUtils.equals(organizationId, user.getLastOrganizationId())) { + user.setLastWorkspaceId(""); + user.setLastOrganizationId(""); + userMapper.updateByPrimaryKeySelective(user); + } + userRoleMapper.deleteByExample(userRoleExample); }