Commit 70920a4258a3fd9700e87543881c362336982313
Merge branch '20220906' into 'master'
fix: 租户角色不存在时,第二次提交表单提示用户名已经存在的问题 See merge request huang/thingsboard3.3.2!128
Showing
8 changed files
with
37 additions
and
16 deletions
... | ... | @@ -130,8 +130,6 @@ public class YtAdminController extends BaseController { |
130 | 130 | UserDTO userDTO = userService.findUserInfoById(strUserId); |
131 | 131 | if (null != userDTO && StringUtils.isNotBlank(userDTO.getTbUser())) { |
132 | 132 | deleteTenantAdmin(userDTO.getTbUser()); |
133 | - } else { | |
134 | - return ResponseEntity.ok(false); | |
135 | 133 | } |
136 | 134 | } |
137 | 135 | boolean result = | ... | ... |
... | ... | @@ -22,6 +22,9 @@ import org.thingsboard.server.common.data.id.TenantId; |
22 | 22 | import org.thingsboard.server.common.data.page.PageLink; |
23 | 23 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; |
24 | 24 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; |
25 | +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | |
26 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
27 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | |
25 | 28 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
26 | 29 | import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; |
27 | 30 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
... | ... | @@ -84,6 +87,9 @@ public class YtDeviceProfileController extends BaseController { |
84 | 87 | if (!Objects.equals(deviceProfile.getSoftwareId(), oldDeviceProfile.getSoftwareId())) { |
85 | 88 | isSoftwareChanged = true; |
86 | 89 | } |
90 | + if (FastIotConstants.ASSERT_DEFAULT_NAME.equals(oldDeviceProfile.getName()) && !Objects.equals(deviceProfile.getName(), oldDeviceProfile.getName())) { | |
91 | + throw new YtDataValidationException(ErrorMessage.ASSERT_DEFAULT_NAME_NO_CHANGED.getMessage()); | |
92 | + } | |
87 | 93 | } |
88 | 94 | |
89 | 95 | DeviceProfile savedDeviceProfile = checkNotNull(deviceProfileService.saveDeviceProfile(deviceProfile)); | ... | ... |
... | ... | @@ -185,9 +185,9 @@ public class YtUserController extends AbstractUserAccount { |
185 | 185 | throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); |
186 | 186 | } |
187 | 187 | userService.validateUserNameAndPhoneNumberAndEmail(userDTO); |
188 | + userService.validateTenantRole(userDTO.getTenantId()); | |
189 | + //租户角色不存在,会留存脏数据 | |
188 | 190 | TenantId tenantId = TenantId.fromUUID(UUID.fromString(userDTO.getTenantId())); |
189 | - UserDTO returnUser = userService.saveTenantAdmin( | |
190 | - userDTO, getCurrentUser().isPtSysadmin(), tenantId.getId().toString()); | |
191 | 191 | try { |
192 | 192 | // 创建TB的租户管理员 |
193 | 193 | CustomerId customerId = new CustomerId(EntityId.NULL_UUID); |
... | ... | @@ -202,7 +202,8 @@ public class YtUserController extends AbstractUserAccount { |
202 | 202 | throw handleException(e); |
203 | 203 | } |
204 | 204 | |
205 | - return returnUser; | |
205 | + return userService.saveTenantAdmin( | |
206 | + userDTO, getCurrentUser().isPtSysadmin(), tenantId.getId().toString()); | |
206 | 207 | } |
207 | 208 | |
208 | 209 | @DeleteMapping | ... | ... |
... | ... | @@ -11,6 +11,7 @@ public interface FastIotConstants { |
11 | 11 | String FIRST_PAGE_NAME = "第 1 页"; |
12 | 12 | String CHART_EXECUTE_CONDITION = "executeCondition"; |
13 | 13 | String CHART_EXECUTE_ATTRIBUTES = "executeAttributes"; |
14 | + String ASSERT_DEFAULT_NAME = "default"; | |
14 | 15 | class DefaultOrder { |
15 | 16 | public static final String CREATE_TIME="create_time"; |
16 | 17 | } | ... | ... |
... | ... | @@ -73,6 +73,8 @@ public enum ErrorMessage { |
73 | 73 | EXPORT_CONFIG_NON_EXISTENT(400053,"报表配置不存在或已被删除"), |
74 | 74 | START_TIME_NOT_MORE_THAN_END_TIME(400054,"开始时间不能大于结束时间"), |
75 | 75 | START_TIME_OR_END_TIME_EXCEPTION(400055,"开始时间或结束时间异常"), |
76 | + TARGET_TEMPLATE_NOT_EXISTS_SELF_NOTICE(400056,"密码重置成功,请自行通知用户!"), | |
77 | + ASSERT_DEFAULT_NAME_NO_CHANGED(400056,"系统预制资源,不能修改名称!"), | |
76 | 78 | HAVE_NO_PERMISSION(500002,"没有修改权限"); |
77 | 79 | private final int code; |
78 | 80 | private String message; | ... | ... |
... | ... | @@ -128,7 +128,7 @@ public class AlarmProfileServiceImpl extends AbstractBaseService<AlarmProfileMap |
128 | 128 | sceneIds.add(action.getSceneLinkageId()); |
129 | 129 | } |
130 | 130 | List<SceneLinkage> scenes = sceneLinkageMapper.selectList(new QueryWrapper<SceneLinkage>().lambda() |
131 | - .eq(SceneLinkage::getId, sceneIds) | |
131 | + .in(SceneLinkage::getId, sceneIds) | |
132 | 132 | ); |
133 | 133 | for(SceneLinkage item: scenes){ |
134 | 134 | sceneNames.add(item.getName()); | ... | ... |
... | ... | @@ -427,15 +427,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
427 | 427 | throw new YtDataValidationException("用户已存在"); |
428 | 428 | } |
429 | 429 | baseMapper.insert(user); |
430 | - List<TenantRole> tenantRoleList = | |
431 | - tenantRoleMapper.selectList( | |
432 | - new QueryWrapper<TenantRole>() | |
433 | - .lambda() | |
434 | - .eq(TenantRole::getTenantId, userDTO.getTenantId())); | |
435 | - // 保存用户与角色的映射信息 | |
436 | - if (null == tenantRoleList || tenantRoleList.size() == 0) { | |
437 | - throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
438 | - } | |
430 | + List<TenantRole> tenantRoleList =validateTenantRole(userDTO.getTenantId()) ; | |
439 | 431 | for (TenantRole tenantRole : tenantRoleList) { |
440 | 432 | roleMapper.saveUserRoleMapping(user.getId(), tenantRole.getRoleId()); |
441 | 433 | } |
... | ... | @@ -444,6 +436,20 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
444 | 436 | } |
445 | 437 | |
446 | 438 | @Override |
439 | + public List<TenantRole> validateTenantRole(String tenantId) { | |
440 | + List<TenantRole> tenantRoleList = | |
441 | + tenantRoleMapper.selectList( | |
442 | + new QueryWrapper<TenantRole>() | |
443 | + .lambda() | |
444 | + .eq(TenantRole::getTenantId, tenantId)); | |
445 | + // 保存用户与角色的映射信息 | |
446 | + if (null == tenantRoleList || tenantRoleList.size() == 0) { | |
447 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
448 | + } | |
449 | + return tenantRoleList; | |
450 | + } | |
451 | + | |
452 | + @Override | |
447 | 453 | @Transactional |
448 | 454 | public void resetPassword(String userId, String tenantId, String password) { |
449 | 455 | UserDTO userDTO = findUserInfoById(userId); |
... | ... | @@ -527,7 +533,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
527 | 533 | List<MessageTemplateDTO> templateDTOList = |
528 | 534 | messageTemplateService.findMessageTemplate(messageTemplateDTO); |
529 | 535 | if (null == templateDTOList || templateDTOList.size() < 1) { |
530 | - throw new YtDataValidationException(ErrorMessage.TARGET_TEMPLATE_NOT_EXISTS.getMessage()); | |
536 | + throw new YtDataValidationException(ErrorMessage.TARGET_TEMPLATE_NOT_EXISTS_SELF_NOTICE.getMessage()); | |
531 | 537 | } |
532 | 538 | if (messageType.equalsIgnoreCase(MessageTypeEnum.PHONE_MESSAGE.name())) { |
533 | 539 | SmsReqDTO smsReqDTO = new SmsReqDTO(); | ... | ... |
... | ... | @@ -8,6 +8,7 @@ import org.thingsboard.server.common.data.yunteng.dto.request.AccountReqDTO; |
8 | 8 | import org.thingsboard.server.common.data.yunteng.dto.request.RoleOrOrganizationReqDTO; |
9 | 9 | import org.thingsboard.server.common.data.yunteng.dto.request.SendResetPasswordEmailMsg; |
10 | 10 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
11 | +import org.thingsboard.server.dao.yunteng.entities.TenantRole; | |
11 | 12 | import org.thingsboard.server.dao.yunteng.entities.User; |
12 | 13 | |
13 | 14 | import java.time.LocalDateTime; |
... | ... | @@ -48,6 +49,12 @@ public interface YtUserService { |
48 | 49 | |
49 | 50 | void validateUserNameAndPhoneNumberAndEmail(UserDTO userDTO); |
50 | 51 | |
52 | + /** | |
53 | + * 验证租户角色是否有效 | |
54 | + * @param tenantId | |
55 | + */ | |
56 | + List<TenantRole> validateTenantRole(String tenantId); | |
57 | + | |
51 | 58 | UserDTO findUserInfoById(String id); |
52 | 59 | /** |
53 | 60 | * 发送密码重置新消息 | ... | ... |