Merge pull request #9491 from thingsboard/fix/notification-center
Fix 'Device created' notification when creating alarm using REST API
This commit is contained in:
commit
d8d61b1ff5
@ -271,6 +271,7 @@ public class NotificationController extends BaseController {
|
||||
@ApiParam(value = "Amount of the recipients to show in preview")
|
||||
@RequestParam(defaultValue = "20") int recipientsPreviewSize,
|
||||
@AuthenticationPrincipal SecurityUser user) throws ThingsboardException {
|
||||
// PE: generic permission
|
||||
NotificationTemplate template;
|
||||
if (request.getTemplateId() != null) {
|
||||
template = checkEntityId(request.getTemplateId(), notificationTemplateService::findNotificationTemplateById, Operation.READ);
|
||||
@ -386,7 +387,7 @@ public class NotificationController extends BaseController {
|
||||
@ApiParam(value = SORT_ORDER_DESCRIPTION)
|
||||
@RequestParam(required = false) String sortOrder,
|
||||
@AuthenticationPrincipal SecurityUser user) throws ThingsboardException {
|
||||
// generic permission
|
||||
// PE: generic permission
|
||||
PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
|
||||
return notificationRequestService.findNotificationRequestsInfosByTenantIdAndOriginatorType(user.getTenantId(), EntityType.USER, pageLink);
|
||||
}
|
||||
|
||||
@ -161,7 +161,7 @@ public class NotificationRuleController extends BaseController {
|
||||
@ApiParam(value = SORT_ORDER_DESCRIPTION)
|
||||
@RequestParam(required = false) String sortOrder,
|
||||
@AuthenticationPrincipal SecurityUser user) throws ThingsboardException {
|
||||
// generic permission
|
||||
// PE: generic permission
|
||||
PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
|
||||
return notificationRuleService.findNotificationRulesInfosByTenantId(user.getTenantId(), pageLink);
|
||||
}
|
||||
|
||||
@ -139,7 +139,7 @@ public class NotificationTargetController extends BaseController {
|
||||
@ApiParam(value = PAGE_NUMBER_DESCRIPTION, required = true)
|
||||
@RequestParam int page,
|
||||
@AuthenticationPrincipal SecurityUser user) throws ThingsboardException {
|
||||
// generic permission
|
||||
// PE: generic permission
|
||||
NotificationTargetConfig targetConfig = notificationTarget.getConfiguration();
|
||||
if (targetConfig.getType() == NotificationTargetType.PLATFORM_USERS) {
|
||||
checkTargetUsers(user, targetConfig);
|
||||
@ -159,7 +159,7 @@ public class NotificationTargetController extends BaseController {
|
||||
public List<NotificationTarget> getNotificationTargetsByIds(@ApiParam(value = "Comma-separated list of uuids representing targets ids", required = true)
|
||||
@RequestParam("ids") UUID[] ids,
|
||||
@AuthenticationPrincipal SecurityUser user) {
|
||||
// generic permission
|
||||
// PE: generic permission
|
||||
List<NotificationTargetId> targetsIds = Arrays.stream(ids).map(NotificationTargetId::new).collect(Collectors.toList());
|
||||
return notificationTargetService.findNotificationTargetsByTenantIdAndIds(user.getTenantId(), targetsIds);
|
||||
}
|
||||
@ -181,7 +181,7 @@ public class NotificationTargetController extends BaseController {
|
||||
@ApiParam(value = SORT_ORDER_DESCRIPTION)
|
||||
@RequestParam(required = false) String sortOrder,
|
||||
@AuthenticationPrincipal SecurityUser user) throws ThingsboardException {
|
||||
// generic permission
|
||||
// PE: generic permission
|
||||
PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
|
||||
return notificationTargetService.findNotificationTargetsByTenantId(user.getTenantId(), pageLink);
|
||||
}
|
||||
@ -199,6 +199,7 @@ public class NotificationTargetController extends BaseController {
|
||||
@RequestParam(required = false) String sortOrder,
|
||||
@RequestParam(required = false) NotificationType notificationType,
|
||||
@AuthenticationPrincipal SecurityUser user) throws ThingsboardException {
|
||||
// PE: generic permission
|
||||
PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
|
||||
return notificationTargetService.findNotificationTargetsByTenantIdAndSupportedNotificationType(user.getTenantId(), notificationType, pageLink);
|
||||
}
|
||||
@ -219,7 +220,7 @@ public class NotificationTargetController extends BaseController {
|
||||
if (user.isSystemAdmin()) {
|
||||
return;
|
||||
}
|
||||
// generic permission for users
|
||||
// PE: generic permission for users
|
||||
UsersFilter usersFilter = ((PlatformUsersNotificationTargetConfig) targetConfig).getUsersFilter();
|
||||
switch (usersFilter.getType()) {
|
||||
case USER_LIST:
|
||||
|
||||
@ -150,7 +150,7 @@ public class NotificationTemplateController extends BaseController {
|
||||
@ApiParam(value = "Comma-separated list of notification types to filter the templates")
|
||||
@RequestParam(required = false) NotificationType[] notificationTypes,
|
||||
@AuthenticationPrincipal SecurityUser user) throws ThingsboardException {
|
||||
// generic permission
|
||||
// PE: generic permission
|
||||
PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
|
||||
if (notificationTypes == null || notificationTypes.length == 0) {
|
||||
notificationTypes = NotificationType.values();
|
||||
@ -180,7 +180,7 @@ public class NotificationTemplateController extends BaseController {
|
||||
@ApiParam(value = "Slack bot token. If absent - system Slack settings will be used")
|
||||
@RequestParam(required = false) String token,
|
||||
@AuthenticationPrincipal SecurityUser user) {
|
||||
// generic permission
|
||||
// PE: generic permission
|
||||
if (StringUtils.isEmpty(token)) {
|
||||
NotificationSettings settings = notificationSettingsService.findNotificationSettings(user.getTenantId());
|
||||
SlackNotificationDeliveryMethodConfig slackConfig = (SlackNotificationDeliveryMethodConfig)
|
||||
|
||||
@ -31,9 +31,9 @@ import org.thingsboard.server.common.data.alarm.Alarm;
|
||||
import org.thingsboard.server.common.data.alarm.AlarmComment;
|
||||
import org.thingsboard.server.common.data.alarm.AlarmInfo;
|
||||
import org.thingsboard.server.common.data.audit.ActionType;
|
||||
import org.thingsboard.server.common.data.edge.EdgeEventActionType;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.HasId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
|
||||
import org.thingsboard.server.common.data.kv.TsKvEntry;
|
||||
@ -179,7 +179,8 @@ public class EntityActionService {
|
||||
}
|
||||
}
|
||||
|
||||
private void processNotificationRules(TenantId tenantId, EntityId entityId, HasName entity, ActionType actionType, User user, Object... additionalInfo) {
|
||||
private void processNotificationRules(TenantId tenantId, EntityId originatorId, HasName entity, ActionType actionType, User user, Object... additionalInfo) {
|
||||
EntityId entityId = entity instanceof HasId ? ((HasId<? extends EntityId>) entity).getId() : originatorId;
|
||||
switch (actionType) {
|
||||
case ADDED:
|
||||
notificationRuleProcessor.process(EntitiesLimitTrigger.builder()
|
||||
|
||||
@ -269,6 +269,31 @@ public class NotificationRuleApiTest extends AbstractNotificationApiTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotificationRuleProcessing_alarmTrigger_createViaRestApi() throws Exception {
|
||||
Device device = createDevice("Device with alarm", "233");
|
||||
NotificationTarget target = createNotificationTarget(tenantAdminUserId);
|
||||
defaultNotifications.create(tenantId, DefaultNotifications.newAlarm, target.getId());
|
||||
defaultNotifications.create(tenantId, DefaultNotifications.entityAction, target.getId());
|
||||
notificationRulesCache.evict(tenantId);
|
||||
|
||||
Alarm alarm = new Alarm();
|
||||
alarm.setSeverity(AlarmSeverity.CRITICAL);
|
||||
alarm.setType("testAlarm");
|
||||
alarm.setOriginator(device.getId());
|
||||
alarm = doPost("/api/alarm", alarm, Alarm.class);
|
||||
|
||||
await().atMost(15, TimeUnit.SECONDS)
|
||||
.pollDelay(2, TimeUnit.SECONDS)
|
||||
.untilAsserted(() -> {
|
||||
List<Notification> notifications = getMyNotifications(false, 10);
|
||||
assertThat(notifications).hasSize(1).first().matches(notification -> {
|
||||
return notification.getType() == NotificationType.ALARM &&
|
||||
notification.getSubject().equals("New alarm 'testAlarm'");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotificationRuleProcessing_alarmTrigger_clearRule() throws Exception {
|
||||
String notificationSubject = "${alarmSeverity} alarm '${alarmType}' is ${alarmStatus}";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user