Merge pull request #11469 from thingsboard/fix/notification-unknown-recipient

Ignore unknown notification recipient groups
This commit is contained in:
Viacheslav Klimov 2024-08-22 14:41:32 +03:00 committed by GitHub
commit f30cee2f12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 6 deletions

View File

@ -300,9 +300,15 @@ public class NotificationController extends BaseController {
request.setOriginatorEntityId(user.getId());
List<NotificationTarget> targets = request.getTargets().stream()
.map(NotificationTargetId::new)
.map(targetId -> notificationTargetService.findNotificationTargetById(user.getTenantId(), targetId))
.map(targetId -> {
NotificationTarget target = notificationTargetService.findNotificationTargetById(user.getTenantId(), targetId);
if (target == null) {
throw new IllegalArgumentException("Notification target for id " + targetId + " not found");
}
return target;
})
.sorted(Comparator.comparing(target -> target.getConfiguration().getType()))
.collect(Collectors.toList());
.toList();
NotificationRequestPreview preview = new NotificationRequestPreview();

View File

@ -73,6 +73,7 @@ import org.thingsboard.server.service.telemetry.AbstractSubscriptionService;
import org.thingsboard.server.service.ws.notification.sub.NotificationRequestUpdate;
import org.thingsboard.server.service.ws.notification.sub.NotificationUpdate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@ -115,12 +116,23 @@ public class DefaultNotificationCenter extends AbstractSubscriptionService imple
} else {
notificationTemplate = request.getTemplate();
}
if (notificationTemplate == null) throw new IllegalArgumentException("Template is missing");
if (notificationTemplate == null) {
throw new IllegalArgumentException("Template is missing");
}
Set<NotificationDeliveryMethod> deliveryMethods = new HashSet<>();
List<NotificationTarget> targets = request.getTargets().stream().map(NotificationTargetId::new)
.map(id -> notificationTargetService.findNotificationTargetById(tenantId, id))
.collect(Collectors.toList());
List<NotificationTarget> targets = new ArrayList<>();
for (UUID targetId : request.getTargets()) {
NotificationTarget target = notificationTargetService.findNotificationTargetById(tenantId, new NotificationTargetId(targetId));
if (target != null) {
targets.add(target);
} else {
log.debug("Unknown notification target {} in request {}", targetId, request);
}
}
if (targets.isEmpty()) {
throw new IllegalArgumentException("No recipients chosen");
}
NotificationRuleId ruleId = request.getRuleId();
notificationTemplate.getConfiguration().getDeliveryMethodsTemplates().forEach((deliveryMethod, template) -> {