fix(消息通知): 修复除站内通知外其余方式发送通知禁用用户可以收到问题

--bug=1044171 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001044171
This commit is contained in:
guoyuqi 2024-07-19 17:11:03 +08:00 committed by 刘瑞斌
parent 26a39e3f24
commit 7f4983b72a
8 changed files with 42 additions and 7 deletions

View File

@ -35,6 +35,10 @@ public interface ExtSystemProjectMapper {
List<UserExtendDTO> getMemberByProjectId(@Param("projectId") String projectId, @Param("keyword") String keyword); List<UserExtendDTO> getMemberByProjectId(@Param("projectId") String projectId, @Param("keyword") String keyword);
List<User> getProjectMemberByUserId(@Param("projectId") String projectId, @Param("userIds") List<String> userIds); List<User> getProjectMemberByUserId(@Param("projectId") String projectId, @Param("userIds") List<String> userIds);
List<User> getEnableProjectMemberByUserId(@Param("projectId") String projectId, @Param("userIds") List<String> userIds);
List<OptionDTO> getSystemProject(@Param("keyword") String keyword); List<OptionDTO> getSystemProject(@Param("keyword") String keyword);
} }

View File

@ -224,6 +224,22 @@
</foreach> </foreach>
</if> </if>
</select> </select>
<select id="getEnableProjectMemberByUserId" resultType="io.metersphere.system.domain.User">
select distinct u.* from user_role_relation urr join `user` u on urr.user_id = u.id
where
u.deleted = 0 and u.enable = 1
<if test="projectId != null and projectId != ''">
and urr.source_id = #{projectId}
</if>
<if test="userIds != null and userIds.size > 0 ">
and u.id in
<foreach collection="userIds" item="userId" open="(" separator="," close=")">
#{userId}
</foreach>
</if>
</select>
<select id="getSystemProject" resultType="io.metersphere.system.dto.sdk.OptionDTO"> <select id="getSystemProject" resultType="io.metersphere.system.dto.sdk.OptionDTO">
select id, name select id, name
from project from project

View File

@ -189,7 +189,7 @@ public abstract class AbstractNoticeSender implements NoticeSender {
// 去重复 // 去重复
List<String> userIds = toUsers.stream().map(Receiver::getUserId).toList(); List<String> userIds = toUsers.stream().map(Receiver::getUserId).toList();
LogUtils.info("userIds: ", JSON.toJSONString(userIds)); LogUtils.info("userIds: ", JSON.toJSONString(userIds));
List<User> users = getUsers(userIds, messageDetail.getProjectId()); List<User> users = getUsers(userIds, messageDetail.getProjectId(), false);
List<String> realUserIds = users.stream().map(User::getId).distinct().toList(); List<String> realUserIds = users.stream().map(User::getId).distinct().toList();
return toUsers.stream().filter(t -> realUserIds.contains(t.getUserId())).distinct().toList(); return toUsers.stream().filter(t -> realUserIds.contains(t.getUserId())).distinct().toList();
} }
@ -336,9 +336,13 @@ public abstract class AbstractNoticeSender implements NoticeSender {
return receivers; return receivers;
} }
protected List<User> getUsers(List<String> userIds, String projectId) { protected List<User> getUsers(List<String> userIds, String projectId, boolean enable) {
if (CollectionUtils.isNotEmpty(userIds)) { if (CollectionUtils.isNotEmpty(userIds)) {
if (enable) {
return extSystemProjectMapper.getEnableProjectMemberByUserId(projectId, userIds);
} else {
return extSystemProjectMapper.getProjectMemberByUserId(projectId, userIds); return extSystemProjectMapper.getProjectMemberByUserId(projectId, userIds);
}
} else { } else {
return new ArrayList<>(); return new ArrayList<>();
} }

View File

@ -25,7 +25,7 @@ public class DingCustomNoticeSender extends AbstractNoticeSender {
.map(Receiver::getUserId) .map(Receiver::getUserId)
.distinct() .distinct()
.collect(Collectors.toList()); .collect(Collectors.toList());
List<User> users = super.getUsers(userIds, messageDetail.getProjectId()); List<User> users = super.getUsers(userIds, messageDetail.getProjectId(), true);
List<String> mobileList = users.stream().map(User::getPhone).toList(); List<String> mobileList = users.stream().map(User::getPhone).toList();
LogUtils.info("钉钉自定义机器人收件人: {}", userIds); LogUtils.info("钉钉自定义机器人收件人: {}", userIds);

View File

@ -9,6 +9,7 @@ import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.Common; import com.aliyun.teautil.Common;
import com.aliyun.teautil.models.RuntimeOptions; import com.aliyun.teautil.models.RuntimeOptions;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;
import io.metersphere.system.domain.User;
import io.metersphere.system.notice.MessageDetail; import io.metersphere.system.notice.MessageDetail;
import io.metersphere.system.notice.NoticeModel; import io.metersphere.system.notice.NoticeModel;
import io.metersphere.system.notice.Receiver; import io.metersphere.system.notice.Receiver;
@ -17,6 +18,7 @@ import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@Component @Component
public class DingEnterPriseNoticeSender extends AbstractNoticeSender { public class DingEnterPriseNoticeSender extends AbstractNoticeSender {
@ -99,6 +101,15 @@ public class DingEnterPriseNoticeSender extends AbstractNoticeSender {
if (CollectionUtils.isEmpty(receivers)) { if (CollectionUtils.isEmpty(receivers)) {
return; return;
} }
List<String> userIds = receivers.stream()
.map(Receiver::getUserId)
.distinct()
.collect(Collectors.toList());
List<User> users = super.getUsers(userIds, messageDetail.getProjectId(), true);
if (CollectionUtils.isEmpty(users)) {
return;
}
try { try {
sendDing(messageDetail, context); sendDing(messageDetail, context);
LogUtils.debug("发送钉钉内部机器人结束"); LogUtils.debug("发送钉钉内部机器人结束");

View File

@ -27,7 +27,7 @@ public class LarkNoticeSender extends AbstractNoticeSender {
.distinct() .distinct()
.collect(Collectors.toList()); .collect(Collectors.toList());
List<User> users = super.getUsers(userIds, messageDetail.getProjectId()); List<User> users = super.getUsers(userIds, messageDetail.getProjectId(), true);
List<String> collect = users.stream() List<String> collect = users.stream()
.map(ud -> "<at email=\"" + ud.getEmail() + "\">" + ud.getName() + "</at>") .map(ud -> "<at email=\"" + ud.getEmail() + "\">" + ud.getName() + "</at>")
.toList(); .toList();

View File

@ -42,7 +42,7 @@ public class MailNoticeSender extends AbstractNoticeSender {
.map(Receiver::getUserId) .map(Receiver::getUserId)
.distinct() .distinct()
.collect(Collectors.toList()); .collect(Collectors.toList());
String[] users = super.getUsers(userIds, projectId).stream() String[] users = super.getUsers(userIds, projectId, true).stream()
.map(User::getEmail) .map(User::getEmail)
.distinct() .distinct()
.toArray(String[]::new); .toArray(String[]::new);

View File

@ -25,7 +25,7 @@ public class WeComNoticeSender extends AbstractNoticeSender {
.map(Receiver::getUserId) .map(Receiver::getUserId)
.distinct() .distinct()
.collect(Collectors.toList()); .collect(Collectors.toList());
List<User> users = super.getUsers(userIds, messageDetail.getProjectId()); List<User> users = super.getUsers(userIds, messageDetail.getProjectId(), true);
List<String> mobileList = users.stream().map(User::getPhone).toList(); List<String> mobileList = users.stream().map(User::getPhone).toList();
LogUtils.info("企业微信收件人: {}", userIds); LogUtils.info("企业微信收件人: {}", userIds);
WeComClient.send(messageDetail.getWebhook(), subjectText + ": \n" + context, mobileList); WeComClient.send(messageDetail.getWebhook(), subjectText + ": \n" + context, mobileList);