1.修复租户管理客户端登录权限修改的错误
This commit is contained in:
@@ -193,4 +193,13 @@ public class UserController {
|
||||
return success(userService.getTenantUserById(tenantId));
|
||||
}
|
||||
|
||||
|
||||
@TenantIgnore
|
||||
@PutMapping("update-client-role")
|
||||
@Operation(summary = "修改用户客户端使用权限")
|
||||
@PreAuthorize("@ss.hasPermission('system:user:update-client')")
|
||||
public CommonResult<Boolean> updateUserWithClientRole(@Valid @RequestBody UserSaveReqVO reqVO) {
|
||||
userService.updateUserWithClientRole(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,4 +82,7 @@ public class UserSaveReqVO {
|
||||
|
||||
@Schema(description = "是否允许登录大哥爬虫客户端", example = "0不允许,1允许")
|
||||
private Byte bigBrother;
|
||||
|
||||
@Schema(description = "租户 Id", example = "1")
|
||||
private Long tenantId;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,12 @@ public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {
|
||||
return selectOne(AdminUserDO::getUsername, username);
|
||||
}
|
||||
|
||||
default AdminUserDO selectByUsernameAndTenantId(String username,Long tenantId) {
|
||||
return selectOne(AdminUserDO::getUsername, username
|
||||
,AdminUserDO::getTenantId, tenantId);
|
||||
}
|
||||
|
||||
|
||||
default AdminUserDO selectByEmail(String email) {
|
||||
return selectOne(AdminUserDO::getEmail, email);
|
||||
}
|
||||
|
||||
@@ -207,4 +207,6 @@ public interface AdminUserService {
|
||||
List<AdminUserDO> getUserListByStatusAndDept(Integer status, Long deptId);
|
||||
|
||||
List<UserRespVO> getTenantUserById(Long tenantId);
|
||||
|
||||
void updateUserWithClientRole(@Valid UserSaveReqVO reqVO);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,9 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
@@ -394,6 +397,26 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void validateUsernameUnique(Long id, String username,Long tenantId) {
|
||||
if (StrUtil.isBlank(username)) {
|
||||
return;
|
||||
}
|
||||
AdminUserDO user = userMapper.selectByUsernameAndTenantId(username,tenantId);
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
// 如果 id 为空,说明不用比较是否为相同 id 的用户
|
||||
if (id == null) {
|
||||
throw exception(USER_USERNAME_EXISTS);
|
||||
}
|
||||
if (!user.getId().equals(id)) {
|
||||
throw exception(USER_USERNAME_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@VisibleForTesting
|
||||
void validateEmailUnique(Long id, String email) {
|
||||
if (StrUtil.isBlank(email)) {
|
||||
@@ -522,6 +545,35 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
return userMapper.selectTenantUserById(tenantId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserWithClientRole(UserSaveReqVO reqVO) {
|
||||
reqVO.setPassword(null); // 特殊:此处不更新密码
|
||||
// 1. 校验正确性
|
||||
AdminUserDO oldUser = validateUserForCreateOrUpdate(reqVO.getId(), reqVO.getUsername(),reqVO.getTenantId());
|
||||
|
||||
// 2.1 更新用户
|
||||
AdminUserDO updateObj = BeanUtils.toBean(reqVO, AdminUserDO.class);
|
||||
userMapper.updateById(updateObj);
|
||||
// 2.2 更新岗位
|
||||
updateUserPost(reqVO, updateObj);
|
||||
|
||||
// 3. 记录操作日志上下文
|
||||
LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldUser, UserSaveReqVO.class));
|
||||
LogRecordContext.putVariable("user", oldUser);
|
||||
}
|
||||
|
||||
|
||||
private AdminUserDO validateUserForCreateOrUpdate(Long id, String username,Long tenantId) {
|
||||
return DataPermissionUtils.executeIgnore(() -> {
|
||||
// 校验用户存在
|
||||
AdminUserDO user = validateUserExists(id);
|
||||
// 校验用户名唯一
|
||||
validateUsernameUnique(id, username,tenantId);
|
||||
return user;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 对密码进行加密
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user