移除角色时判断是否需要清空lastWsId和lastOrgId

This commit is contained in:
shiziyuan9527 2020-06-08 16:08:53 +08:00
parent 66ecbc26f0
commit c14a8b24c3
1 changed files with 27 additions and 0 deletions

View File

@ -195,6 +195,17 @@ public class UserService {
String userId = user.getId();
UserRoleExample userRoleExample = new UserRoleExample();
userRoleExample.createCriteria().andUserIdEqualTo(userId);
List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleExample);
List<String> 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<Map<String, Object>> 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);
}