in manager/dm-server/src/main/java/org/apache/doris/stack/component/DorisManagerUserSpaceComponent.java [250:327]
public NewUserSpaceInfo update(CoreUserEntity user, long spaceId, NewUserSpaceCreateReq updateReq) throws Exception {
checkRequestBody(updateReq.hasEmptyFieldNoCluster());
log.debug("update space {} information.", spaceId);
ClusterInfoEntity clusterInfo = clusterUserComponent.checkUserClusterAdminPermission(user, spaceId);
if (!clusterInfo.getName().equals(updateReq.getName())) {
nameCheck(updateReq.getName());
}
log.debug("The name not be changed");
clusterInfo.setName(updateReq.getName());
clusterInfo.setDescription(updateReq.getDescribe());
clusterInfo.setUpdateTime(new Timestamp(System.currentTimeMillis()));
log.debug("update space info.");
// Determine whether the cluster information needs to be changed
if (updateReq.getCluster() != null) {
// TODO: if the user name and password of Doris cluster already exist, they cannot be modified
if (clusterInfo.getAddress() != null) {
log.error("The space palo cluster information already exists.");
throw new DorisSpaceDuplicatedException();
}
clusterAccess(updateReq.getCluster(), clusterInfo);
}
// admin user update admin userList
if (user.isSuperuser()) {
checkAdminUserList(updateReq.getSpaceAdminUsers());
log.debug("Admin user update cluster admin user list.");
// Get the original space administrator list
List<Integer> oldAdminUsers = membershipRepository.getUserIdsByGroupId(clusterInfo.getAdminGroupId());
log.debug("Old admin users {}", oldAdminUsers);
log.debug("New admin users {}", updateReq.getSpaceAdminUsers());
// Get the new administrator role user in the space
List<Integer> addAdminUsers = ListUtil.getAddList(updateReq.getSpaceAdminUsers(), oldAdminUsers);
log.debug("Add admin users {}", addAdminUsers);
for (Integer adminUserId : addAdminUsers) {
if (adminUserId < 0) {
continue;
}
// Judge whether the user is in the current space
List<ClusterUserMembershipEntity> membershipEntities =
clusterUserMembershipRepository.getByUserIdAndClusterId(adminUserId, spaceId);
if (membershipEntities.isEmpty()) {
// Users are not in the space yet. They are added to the space
// and also to the administrator and alluser user groups
clusterUserComponent.addAdminUserToCluster(adminUserId, clusterInfo);
} else {
// The user is already in the space, but not an administrator,
// and is added to the administrator group
clusterUserComponent.addGroupUserMembership(adminUserId, clusterInfo.getAdminGroupId());
}
}
// Get the administrator role user for space deletion
List<Integer> reduceAdminUsers = ListUtil.getReduceList(updateReq.getSpaceAdminUsers(), oldAdminUsers);
log.debug("Reduce admin users {}", reduceAdminUsers);
for (Integer adminUserId : reduceAdminUsers) {
if (adminUserId < 0) {
continue;
}
// Delete the user from the space administrator role
membershipRepository.deleteByUserIdAndGroupId(clusterInfo.getAdminGroupId(), adminUserId);
// also delete the user form all user role and cluster space
membershipRepository.deleteByUserIdAndGroupId(clusterInfo.getAllUserGroupId(), adminUserId);
clusterUserMembershipRepository.deleteByUserIdAndClusterId(adminUserId, clusterInfo.getId());
}
}
ClusterInfoEntity clusterInfoSave = clusterInfoRepository.save(clusterInfo);
NewUserSpaceInfo userSpaceInfo = clusterInfoSave.transToNewModel();
getAdminGroupUserList(userSpaceInfo, clusterInfo.getAdminGroupId());
return userSpaceInfo;
}