Commit 76967eaa1bc180f7180a61eeceed12a214ade413

Authored by 黄 x
1 parent 46ab1034

fix: 租户下用户列表分页查询BUG,创建用户时应该使用用户输入的密码BUG

... ... @@ -159,14 +159,14 @@ public class YtUserController extends BaseController {
159 159 createTBUser(
160 160 tbUser, userDTO, customer.getTenantId(), customer.getId(), Authority.CUSTOMER_USER);
161 161 // 激活CUSTOMER_USER的管理员
162   - activeTBUser(tbUser.getId());
  162 + activeTBUser(tbUser.getId(),userDTO.getPassword());
163 163 }
164 164 return ResponseEntity.ok(
165 165 userService.saveAccount(
166 166 userDTO,
167 167 sendEmail,
168 168 sendMsg,
169   - getCurrentUser().isPtSysadmin(),
  169 + getCurrentUser().isPtTenantAdmin(),
170 170 getCurrentUser().getCurrentTenantId()));
171 171 }
172 172
... ... @@ -187,7 +187,7 @@ public class YtUserController extends BaseController {
187 187 if (null == userDTO.getId()) {
188 188 tbUser = createTBUser(tbUser, userDTO, tenantId, customerId, Authority.TENANT_ADMIN);
189 189 // 激活租户管理员
190   - activeTBUser(tbUser.getId());
  190 + activeTBUser(tbUser.getId(),FastIotConstants.DEFAULT_PWD);
191 191 }
192 192 } catch (Exception e) {
193 193 throw handleException(e);
... ... @@ -325,7 +325,7 @@ public class YtUserController extends BaseController {
325 325 * @param userId 用户ID
326 326 * @throws ThingsboardException tb运行异常
327 327 */
328   - private void activeTBUser(UserId userId) throws ThingsboardException {
  328 + private void activeTBUser(UserId userId,String password) throws ThingsboardException {
329 329 try {
330 330 // 1、获取UserCredentials 并获取activateToken
331 331 User user = checkUserId(userId, Operation.READ);
... ... @@ -333,7 +333,7 @@ public class YtUserController extends BaseController {
333 333 UserCredentials userCredentials =
334 334 tbUserService.findUserCredentialsByUserId(authUser.getTenantId(), user.getId());
335 335 // 2、进行激活
336   - String encodedPassword = passwordEncoder.encode(FastIotConstants.DEFAULT_PWD);
  336 + String encodedPassword = passwordEncoder.encode(password);
337 337 UserCredentials credentials =
338 338 tbUserService.activateUserCredentials(
339 339 TenantId.SYS_TENANT_ID, userCredentials.getActivateToken(), encodedPassword);
... ...
... ... @@ -92,6 +92,8 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User>
92 92 boolean userExist;
93 93 if (StringUtils.isNotBlank(userDTO.getPassword())) {
94 94 user.setPassword(passwordEncoder.encode(userDTO.getPassword()));
  95 + }else {
  96 + user.setPassword(passwordEncoder.encode(FastIotConstants.DEFAULT_PWD));
95 97 }
96 98 userExist =
97 99 baseMapper.selectCount(
... ... @@ -103,7 +105,6 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User>
103 105 if (userExist) {
104 106 throw new YtDataValidationException(ErrorMessage.NAME_ALREADY_EXISTS.getMessage());
105 107 } else {
106   - user.setPassword(passwordEncoder.encode(FastIotConstants.DEFAULT_PWD));
107 108 user.setTenantId(tenantId);
108 109 user.setLevel(
109 110 isTenantAdminOperate
... ... @@ -314,6 +315,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User>
314 315 if (null != organizationId && (userIds.size() == FastIotConstants.MagicNumber.ZERO)) {
315 316 userPage = new Page<>();
316 317 } else {
  318 + queryMap.put("isTenantAdmin",true);
317 319 userPage = baseMapper.getUserPage(userIPage, queryMap);
318 320 }
319 321 }
... ...
... ... @@ -99,6 +99,9 @@
99 99 <if test="queryMap.tenantId !=null and queryMap.tenantId!=''">
100 100 AND su.tenant_id=#{queryMap.tenantId}
101 101 </if>
  102 + <if test="queryMap.isTenantAdmin != null">
  103 + AND su.level =3
  104 + </if>
102 105 <if test="queryMap.userIds !=null">
103 106 AND su.id IN
104 107 <foreach collection="queryMap.userIds" item="userId" open="(" separator="," close=")">
... ...