Commit 1eaf94e20adefaa5da237d869a5f4f87df6b39f3

Authored by xp.Huang
2 parents b4250d85 70869fde

Merge branch '20220829' into 'master'

feat: 默认密码是否需要重置

See merge request huang/thingsboard3.3.2!125
... ... @@ -54,12 +54,12 @@ public class YtTenantController extends AbstractUserAccount {
54 54 SendResetPasswordEmailMsg msg = new SendResetPasswordEmailMsg();
55 55 msg.setUserId(userId);
56 56 msg.setMessageTypeEnum(MessageTypeEnum.PHONE_MESSAGE);
57   - userService.sendRestPasswordMsg(msg);
  57 + userService.sendRestPasswordMsg(getCurrentUser().getCurrentTenantId(),msg);
58 58 }
59 59
60 60
61 61 @PostMapping("/sendRestPasswordMsg")
62   - public void resetPassword(@RequestBody SendResetPasswordEmailMsg msg) {
63   - userService.sendRestPasswordMsg(msg);
  62 + public void resetPassword(@RequestBody SendResetPasswordEmailMsg msg) throws ThingsboardException {
  63 + userService.sendRestPasswordMsg(getCurrentUser().getCurrentTenantId(),msg);
64 64 }
65 65 }
... ...
... ... @@ -1154,6 +1154,7 @@ account:
1154 1154 emailSuffix: ${ACCOUNT_EMAIL_SUFFIX:yunteng.com}
1155 1155 # emailSuffix: thingskit.com
1156 1156 defaultPassword: 123456
  1157 + reset: ${ACCOUNT_PASSWORD_FORCE_RESET:true}
1157 1158 third:
1158 1159 wechat:
1159 1160 url: https://api.weixin.qq.com
... ...
... ... @@ -10,6 +10,7 @@ import org.aspectj.lang.ProceedingJoinPoint;
10 10 import org.aspectj.lang.annotation.Around;
11 11 import org.aspectj.lang.annotation.Aspect;
12 12 import org.aspectj.lang.annotation.Pointcut;
  13 +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
13 14 import org.springframework.stereotype.Component;
14 15 import org.thingsboard.server.common.data.yunteng.common.YtCommonService;
15 16 import org.thingsboard.server.common.data.yunteng.common.aspect.annotation.AutoDict;
... ... @@ -27,6 +28,7 @@ import java.util.List;
27 28 @Component
28 29 @Slf4j
29 30 @RequiredArgsConstructor
  31 +@ConditionalOnExpression("('${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core') ")
30 32 public class SysDictAspect {
31 33
32 34 private final YtCommonService commonService;
... ...
... ... @@ -36,7 +36,7 @@ public enum ErrorMessage {
36 36 USERNAME_IS_IMMUTABLE(400017,"用户账号不可变"),
37 37 CONFIG_IS_DISABLE(400018,"配置未启用"),
38 38 IT_CANT_EQUAL_ITSELF(400019,"父级组织不可以为本身"),
39   - TARGET_TEMPLATE_NOT_EXISTS(400020,"目标模板不存在"),
  39 + TARGET_TEMPLATE_NOT_EXISTS(400020,"不存在可用的消息模板"),
40 40 DEVICE_NOT_EXISTENCE_IN_TENANT(400021,"当前租户下不存在该设备"),
41 41 DEVICE_RELATION_IS_ABSENT(400022,"设备关联关系已不存在"),
42 42 DATA_IS_DELETED(400023,"数据已经删除"),
... ... @@ -59,7 +59,7 @@ public enum ErrorMessage {
59 59 DEVICE_LOSED(400039,"设备相关参数丢失"),
60 60 SCENE_REACT_NOT_EXTIED(400040,"场景联动不存在"),
61 61 DEVICE_USED_SCENE_REACT(400041,"场景联动【%s】正在使用该设备"),
62   - SCENE_REACT_USED_ALARM_PROFILE(400042,"场景联动正在使用该告警配置"),
  62 + SCENE_REACT_USED_ALARM_PROFILE(400042,"场景联动【%s】正在使用该告警配置"),
63 63 APP_USER_BINDED(400043,"平台用户【%s】已被其它账号绑定"),
64 64 THIRD_PLATFORM_EXCEPTION(400044,"【%s】,第三方异常【%s】"),
65 65 DEVICE_NOT_EXTIED(400045,"设备不存在"),
... ...
... ... @@ -10,4 +10,5 @@ import org.springframework.stereotype.Component;
10 10 public class AccountProperties {
11 11 private String emailSuffix;
12 12 private String defaultPassword;
  13 + private Boolean reset;
13 14 }
... ...
1 1 package org.thingsboard.server.dao.yunteng.impl;
2 2
3 3 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4 +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 5 import com.baomidou.mybatisplus.core.metadata.IPage;
5 6 import lombok.RequiredArgsConstructor;
6 7 import lombok.extern.slf4j.Slf4j;
... ... @@ -15,8 +16,10 @@ import org.thingsboard.server.common.data.yunteng.dto.*;
15 16 import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils;
16 17 import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData;
17 18 import org.thingsboard.server.dao.yunteng.entities.AlarmProfile;
  19 +import org.thingsboard.server.dao.yunteng.entities.SceneLinkage;
18 20 import org.thingsboard.server.dao.yunteng.mapper.AlarmProfileMapper;
19 21 import org.thingsboard.server.dao.yunteng.mapper.OrganizationMapper;
  22 +import org.thingsboard.server.dao.yunteng.mapper.SceneLinkageMapper;
20 23 import org.thingsboard.server.dao.yunteng.service.AbstractBaseService;
21 24 import org.thingsboard.server.dao.yunteng.service.AlarmProfileService;
22 25 import org.thingsboard.server.dao.yunteng.service.DoActionService;
... ... @@ -35,6 +38,7 @@ public class AlarmProfileServiceImpl extends AbstractBaseService<AlarmProfileMap
35 38 private final UserOrganizationMappingServiceImpl userOrganizationMappingService;
36 39
37 40 private final OrganizationMapper ytOrganizationMapper;
  41 + private final SceneLinkageMapper sceneLinkageMapper;
38 42
39 43 @Override
40 44 public YtPageData<AlarmProfileDTO> page(
... ... @@ -74,10 +78,9 @@ public class AlarmProfileServiceImpl extends AbstractBaseService<AlarmProfileMap
74 78 if (!alarmProfile.getOrganizationId().equals(alarmProfileDTO.getOrganizationId())) {
75 79 Set<String> profiles = new HashSet<>();
76 80 profiles.add(alarmProfileDTO.getId());
77   - List<DoActionDTO> list =
78   - doActionService.findDoActionByAlarmProfileIds(alarmProfileDTO.getTenantId(), profiles);
79   - if (list.size() > FastIotConstants.MagicNumber.ZERO) {
80   - throw new YtDataValidationException(ErrorMessage.SCENE_REACT_USED_ALARM_PROFILE.getMessage());
  81 + Set<String>names = alarmProfileUsed(alarmProfileDTO.getTenantId(), profiles);
  82 + if(!names.isEmpty()){
  83 + throw new YtDataValidationException(String.format(ErrorMessage.SCENE_REACT_USED_ALARM_PROFILE.getMessage(), names));
81 84 }
82 85 }
83 86 baseMapper.updateById(alarmProfileDTO.getEntity(AlarmProfile.class));
... ... @@ -106,13 +109,32 @@ public class AlarmProfileServiceImpl extends AbstractBaseService<AlarmProfileMap
106 109 @Override
107 110 @Transactional
108 111 public boolean deleteAlarmProFile(DeleteDTO deleteDTO) {
  112 + Set<String>names = alarmProfileUsed(deleteDTO.getTenantId(), deleteDTO.getIds());
  113 + if(!names.isEmpty()){
  114 + throw new YtDataValidationException(String.format(ErrorMessage.SCENE_REACT_USED_ALARM_PROFILE.getMessage(), names));
  115 + }
  116 + return baseMapper.deleteBatchIds(deleteDTO.getIds()) > 0;
  117 + }
  118 +
  119 + private Set<String> alarmProfileUsed(String tenantId, Set<String> profileIds) {
  120 +
  121 + Set<String> sceneNames = new HashSet<>();
109 122 // 如果有场景联动使用告警配置,则不能删除
110 123 List<DoActionDTO> list =
111   - doActionService.findDoActionByAlarmProfileIds(deleteDTO.getTenantId(), deleteDTO.getIds());
  124 + doActionService.findDoActionByAlarmProfileIds(tenantId, profileIds);
112 125 if (list.size() > FastIotConstants.MagicNumber.ZERO) {
113   - throw new YtDataValidationException(ErrorMessage.EXIST_LEADER_MEMBER_RELATION.getMessage());
  126 + Set<String> sceneIds = new HashSet<>();
  127 + for(DoActionDTO action:list){
  128 + sceneIds.add(action.getSceneLinkageId());
  129 + }
  130 + List<SceneLinkage> scenes = sceneLinkageMapper.selectList(new QueryWrapper<SceneLinkage>().lambda()
  131 + .eq(SceneLinkage::getId, sceneIds)
  132 + );
  133 + for(SceneLinkage item: scenes){
  134 + sceneNames.add(item.getName());
  135 + }
114 136 }
115   - return baseMapper.deleteBatchIds(deleteDTO.getIds()) > 0;
  137 + return sceneNames;
116 138 }
117 139
118 140 @Override
... ...
... ... @@ -6,10 +6,7 @@ import org.springframework.stereotype.Service;
6 6 import org.thingsboard.server.common.data.yunteng.dto.AlarmInfoDTO;
7 7 import org.thingsboard.server.common.data.yunteng.dto.request.EmailReqDTO;
8 8 import org.thingsboard.server.common.data.yunteng.dto.request.SmsReqDTO;
9   -import org.thingsboard.server.common.data.yunteng.enums.AssetStatusEnum;
10   -import org.thingsboard.server.common.data.yunteng.enums.EmailFormatEnum;
11   -import org.thingsboard.server.common.data.yunteng.enums.MessageTypeEnum;
12   -import org.thingsboard.server.common.data.yunteng.enums.MsgTemplatePurposeEnum;
  9 +import org.thingsboard.server.common.data.yunteng.enums.*;
13 10 import org.thingsboard.server.common.data.yunteng.utils.YtDateTimeUtils;
14 11 import org.thingsboard.server.dao.yunteng.entities.*;
15 12 import org.thingsboard.server.dao.yunteng.mapper.*;
... ... @@ -65,8 +62,10 @@ public class YtNoticeServiceImpl implements YtNoticeService {
65 62 .eq(Organization::getId, device.getOrganizationId());
66 63 Organization organization = organizationMapper.selectOne(organizationQueryWrapper);
67 64
68   -
69   - AlarmProfile alarmProfile = alarmProfileMapper.selectById(profileId);
  65 + QueryWrapper<AlarmProfile> profileQueryWrapper = new QueryWrapper<AlarmProfile>();
  66 + profileQueryWrapper.lambda()
  67 + .eq(AlarmProfile::getId, profileId).eq(AlarmProfile::getStatus, StatusEnum.ENABLE.ordinal());
  68 + AlarmProfile alarmProfile = alarmProfileMapper.selectOne(profileQueryWrapper);
70 69
71 70
72 71 if (alarmProfile == null || alarmProfile.getAlarmContactId().isEmpty() || alarmProfile.getMessageMode().isEmpty()) {
... ...
... ... @@ -145,7 +145,7 @@ public class YtSmsServiceImpl implements YtSmsService {
145 145 .eq(MessageTemplate::getTemplatePurpose, purpose.name())
146 146 .eq(MessageTemplate::getMessageType, MessageTypeEnum.PHONE_MESSAGE.name()));
147 147 if (messageTemplates.isEmpty()) {
148   - throw new YtDataValidationException("no sms provider config");
  148 + throw new YtDataValidationException(ErrorMessage.TARGET_TEMPLATE_NOT_EXISTS.getMessage());
149 149 }
150 150 String code = RandomStringUtils.randomNumeric(6);
151 151 LinkedHashMap<String, String> params = new LinkedHashMap<>();
... ...
... ... @@ -233,7 +233,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User>
233 233 public UserInfoDTO me(String userId, String tenantId, Set<String> currentRoles) {
234 234 User user = baseMapper.selectById(userId);
235 235 UserInfoDTO userInfoDTO = new UserInfoDTO();
236   - if (!StringUtils.isEmpty(user.getActivateToken())) {
  236 + if (!accountProperties.getReset() || !StringUtils.isEmpty(user.getActivateToken())) {
237 237 userInfoDTO.setNeedSetPwd(false);
238 238 }
239 239 AtomicReference<LocalDateTime> expireTime = new AtomicReference<>(user.getAccountExpireTime());
... ... @@ -510,7 +510,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User>
510 510 }
511 511
512 512 @Override
513   - public void sendRestPasswordMsg(SendResetPasswordEmailMsg msg) {
  513 + public void sendRestPasswordMsg(String tenantId,SendResetPasswordEmailMsg msg) {
514 514 // 通过用户ID查询用户信息
515 515 User user = baseMapper.selectById(msg.getUserId());
516 516 if (null == user) {
... ... @@ -522,6 +522,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User>
522 522 String messageType = msg.getMessageTypeEnum().name();
523 523 messageTemplateDTO.setMessageType(messageType);
524 524 messageTemplateDTO.setTemplatePurpose(MsgTemplatePurposeEnum.FOR_SET_PASSWORD.name());
  525 + messageTemplateDTO.setTenantId(tenantId);
525 526 messageTemplateDTO.setStatus(1);
526 527 List<MessageTemplateDTO> templateDTOList =
527 528 messageTemplateService.findMessageTemplate(messageTemplateDTO);
... ...
... ... @@ -54,7 +54,7 @@ public interface YtUserService {
54 54 *
55 55 * @param msg 请求信息
56 56 */
57   - void sendRestPasswordMsg(SendResetPasswordEmailMsg msg);
  57 + void sendRestPasswordMsg(String tenantId,SendResetPasswordEmailMsg msg);
58 58
59 59 /**
60 60 * 判断账号是否注册过
... ...