100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Notifications are checked on emailNotificationsEnabled and pushNotificationsEnabled before being sent
Michael Rademaker3f1434ca9efe
diff --git a/manager/src/main/java/org/openremote/manager/notification/EmailNotificationHandler.java b/manager/src/main/java/org/openremote/manager/notification/EmailNotificationHandler.javaindex a79902771..ed527f97f 100644--- a/manager/src/main/java/org/openremote/manager/notification/EmailNotificationHandler.java+++ b/manager/src/main/java/org/openremote/manager/notification/EmailNotificationHandler.java@@ -43,6 +43,7 @@ import org.simplejavamail.mailer.config.TransportStrategy;import java.util.ArrayList;import java.util.Arrays;+import java.util.Collections;import java.util.List;import java.util.logging.Level;import java.util.logging.Logger;@@ -50,6 +51,7 @@ import java.util.stream.Collectors;import static org.openremote.container.util.MapAccess.getBoolean;import static org.openremote.container.util.MapAccess.getInteger;+import static org.openremote.manager.security.ManagerKeycloakIdentityProvider.KEYCLOAK_USER_ATTRIBUTE_EMAIL_NOTIFICATIONS_ENABLED;import static org.openremote.model.Constants.*;public class EmailNotificationHandler implements NotificationHandler {@@ -169,11 +171,9 @@ public class EmailNotificationHandler implements NotificationHandler {mappedTargets.addAll(Arrays.stream(users)+ .filter(user -> Boolean.parseBoolean(user.getAttributes().getOrDefault(KEYCLOAK_USER_ATTRIBUTE_EMAIL_NOTIFICATIONS_ENABLED, Collections.singletonList("true")).get(0))).map(user -> {Notification.Target userAssetTarget = new Notification.Target(Notification.TargetType.USER, user.getId());---userAssetTarget.setData(new EmailNotificationMessage.Recipient(user.getFullName(), user.getEmail()));return userAssetTarget;})diff --git a/manager/src/main/java/org/openremote/manager/notification/PushNotificationHandler.java b/manager/src/main/java/org/openremote/manager/notification/PushNotificationHandler.javaindex bdb21e35e..2f9723a0c 100644--- a/manager/src/main/java/org/openremote/manager/notification/PushNotificationHandler.java+++ b/manager/src/main/java/org/openremote/manager/notification/PushNotificationHandler.java@@ -30,8 +30,11 @@ import org.openremote.container.message.MessageBrokerService;import org.openremote.container.persistence.PersistenceEvent;import org.openremote.manager.asset.AssetStorageService;import org.openremote.manager.gateway.GatewayService;+import org.openremote.manager.security.ManagerIdentityService;import org.openremote.model.Container;import org.openremote.model.ContainerService;+import org.openremote.model.asset.Asset;+import org.openremote.model.asset.UserAssetLink;import org.openremote.model.asset.impl.ConsoleAsset;import org.openremote.model.console.ConsoleProvider;import org.openremote.model.notification.AbstractNotificationMessage;@@ -39,7 +42,9 @@ import org.openremote.model.notification.Notification;import org.openremote.model.notification.NotificationSendResult;import org.openremote.model.notification.PushNotificationMessage;import org.openremote.model.query.AssetQuery;+import org.openremote.model.query.UserQuery;import org.openremote.model.query.filter.*;+import org.openremote.model.security.User;import org.openremote.model.util.TextUtil;import org.openremote.model.util.ValueUtil;@@ -50,11 +55,13 @@ import java.util.*;import java.util.logging.Level;import java.util.logging.Logger;import java.util.stream.Collectors;+import java.util.stream.Stream;import java.util.stream.StreamSupport;import static org.openremote.container.concurrent.GlobalLock.withLock;import static org.openremote.container.persistence.PersistenceEvent.*;import static org.openremote.manager.gateway.GatewayService.isNotForGateway;+import static org.openremote.manager.security.ManagerKeycloakIdentityProvider.KEYCLOAK_USER_ATTRIBUTE_PUSH_NOTIFICATIONS_ENABLED;import static org.openremote.model.notification.PushNotificationMessage.TargetType.*;@SuppressWarnings("deprecation")@@ -66,6 +73,7 @@ public class PushNotificationHandler extends RouteBuilder implements Notificatiopublic static final int READ_TIMEOUT_MILLIS = 3000;public static final String FCM_PROVIDER_NAME = "fcm";+ protected ManagerIdentityService managerIdentityService;protected AssetStorageService assetStorageService;protected GatewayService gatewayService;protected boolean valid;@@ -78,6 +86,7 @@ public class PushNotificationHandler extends RouteBuilder implements Notificatio}public void init(Container container) throws Exception {+ this.managerIdentityService = container.getService(ManagerIdentityService.class);this.assetStorageService = container.getService(AssetStorageService.class);this.gatewayService = container.getService(GatewayService.class);container.getService(MessageBrokerService.class).getContext().addRoutes(this);@@ -199,36 +208,63 @@ public class PushNotificationHandler extends RouteBuilder implements Notificatiocase TENANT:// Get all console assets with a push provider defined within the specified tenant- mappedTargets.addAll(- assetStorageService.findAll(+ List<Asset<?>> consoleAssets = assetStorageService.findAll(new AssetQuery()- .select(AssetQuery.Select.selectExcludeAll())- .tenant(new TenantPredicate(targetId))- .types(ConsoleAsset.class)- .attributes(new AttributePredicate(ConsoleAsset.CONSOLE_PROVIDERS, null, false, new NameValuePredicate.Path(PushNotificationMessage.TYPE))))- .stream()- .map(asset -> new Notification.Target(Notification.TargetType.ASSET, asset.getId()))- .collect(Collectors.toList()));+ .select(AssetQuery.Select.selectExcludeAll())+ .tenant(new TenantPredicate(targetId))+ .types(ConsoleAsset.class)+ .attributes(new AttributePredicate(ConsoleAsset.CONSOLE_PROVIDERS, null, false, new NameValuePredicate.Path(PushNotificationMessage.TYPE))));++ // Get all user ids which have pushNotificationsEnabled set to false+ String[] userIds = Arrays.stream(managerIdentityService+ .getIdentityProvider()+ .queryUsers(new UserQuery().tenant(new TenantPredicate((targetId))))+ )+ .filter(user -> !Boolean.parseBoolean(user.getAttributes().getOrDefault(KEYCLOAK_USER_ATTRIBUTE_PUSH_NOTIFICATIONS_ENABLED, Collections.singletonList("true")).get(0)))+ .map(User::getId)+ .toArray(String[]::new);++ String[] assetIds = assetStorageService.findUserAssetLinks(targetId, null, null).stream()+ .filter(userAssetLink -> Arrays.stream(userIds).anyMatch(userId->userId.equals(userAssetLink.getId().getUserId())))+ .map(userAssetLink -> userAssetLink.getId().getAssetId())+ .toArray(String[]::new);++ //Remove consoleAssets which are linked to an User which has pushNotificationsEnabled set to false+ consoleAssets = consoleAssets.stream()+ .filter(consoleAsset -> Arrays.stream(assetIds).noneMatch(assetId -> assetId.equals(consoleAsset.getId())))+ .collect(Collectors.toList());++ mappedTargets.addAll(+ consoleAssets+ .stream()+ .map(asset -> new Notification.Target(Notification.TargetType.ASSET, asset.getId()))+ .collect(Collectors.toList()));break;case USER:- // Get all console assets linked to the specified user- String[] ids = assetStorageService.findUserAssetLinks(null, targetId, null)- .stream()- .map(userAssetLink -> userAssetLink.getId().getAssetId()).toArray(String[]::new);+ Optional<User> user = Arrays.stream(managerIdentityService+ .getIdentityProvider()+ .queryUsers(new UserQuery().ids(targetId))).findFirst();- if (ids.length > 0) {+ if (user.isPresent() && Boolean.parseBoolean(user.get().getAttributes().getOrDefault(KEYCLOAK_USER_ATTRIBUTE_PUSH_NOTIFICATIONS_ENABLED, Collections.singletonList("true")).get(0))) {- mappedTargets.addAll(- assetStorageService.findAll(- new AssetQuery()- .select(AssetQuery.Select.selectExcludeAll())- .ids(ids)- .types(ConsoleAsset.class)- .attributes(new AttributePredicate(ConsoleAsset.CONSOLE_PROVIDERS, null, false, new NameValuePredicate.Path(PushNotificationMessage.TYPE))))+ // Get all console assets linked to the specified user+ String[] ids = assetStorageService.findUserAssetLinks(null, targetId, null).stream()- .map(asset -> new Notification.Target(Notification.TargetType.ASSET, asset.getId()))- .collect(Collectors.toList()));+ .map(userAssetLink -> userAssetLink.getId().getAssetId()).toArray(String[]::new);++ if (ids.length > 0) {+ mappedTargets.addAll(+ assetStorageService.findAll(+ new AssetQuery()+ .select(AssetQuery.Select.selectExcludeAll())+ .ids(ids)+ .types(ConsoleAsset.class)+ .attributes(new AttributePredicate(ConsoleAsset.CONSOLE_PROVIDERS, null, false, new NameValuePredicate.Path(PushNotificationMessage.TYPE))))+ .stream()+ .map(asset -> new Notification.Target(Notification.TargetType.ASSET, asset.getId()))+ .collect(Collectors.toList()));+ }} else {LOG.fine("No console assets linked to target user");return;@@ -238,16 +274,40 @@ public class PushNotificationHandler extends RouteBuilder implements Notificatiocase ASSET:// Find all console descendants of the specified asset+ consoleAssets = assetStorageService.findAll(new AssetQuery()+ .select(AssetQuery.Select.selectExcludeAll())+ .paths(new PathPredicate(targetId))+ .types(ConsoleAsset.class)+ .attributes(new AttributePredicate(ConsoleAsset.CONSOLE_PROVIDERS, null, false, new NameValuePredicate.Path(PushNotificationMessage.TYPE))));++ UserAssetLink[] userAssetLinks = consoleAssets.stream()+ .map(consoleAsset -> assetStorageService.findUserAssetLinks(null, null, consoleAsset.getId()))+ .flatMap(Collection::stream)+ .toArray(UserAssetLink[]::new);++ // Get all user ids which have pushNotificationsEnabled set to false+ assetIds = Arrays.stream(userAssetLinks)+ .filter(userAssetLink -> Arrays.stream(managerIdentityService+ .getIdentityProvider()+ .queryUsers(new UserQuery().asset(new UserAssetPredicate(userAssetLink.getId().getAssetId())))+ )+ .filter(user1 -> !Boolean.parseBoolean(user1.getAttributes().getOrDefault(KEYCLOAK_USER_ATTRIBUTE_PUSH_NOTIFICATIONS_ENABLED, Collections.singletonList("true")).get(0)))+ .map(User::getId)+ .anyMatch(userId -> userId.equals(userAssetLink.getId().getUserId()))+ ).map(userAssetLink -> userAssetLink.getId().getAssetId())+ .toArray(String[]::new);++ //Remove consoleAssets which are linked to an User which has pushNotificationsEnabled set to false+ consoleAssets = consoleAssets.stream()+ .filter(consoleAsset -> Arrays.stream(assetIds).noneMatch(assetId -> assetId.equals(consoleAsset.getId())))+ .collect(Collectors.toList());++mappedTargets.addAll(- assetStorageService.findAll(- new AssetQuery()- .select(AssetQuery.Select.selectExcludeAll())- .paths(new PathPredicate(targetId))- .types(ConsoleAsset.class)- .attributes(new AttributePredicate(ConsoleAsset.CONSOLE_PROVIDERS, null, false, new NameValuePredicate.Path(PushNotificationMessage.TYPE))))- .stream()- .map(asset -> new Notification.Target(Notification.TargetType.ASSET, asset.getId()))- .collect(Collectors.toList()));+ consoleAssets+ .stream()+ .map(asset -> new Notification.Target(Notification.TargetType.ASSET, asset.getId()))+ .collect(Collectors.toList()));break;}});diff --git a/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java b/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.javaindex 05268981f..4e1540f15 100644--- a/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java+++ b/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java@@ -238,11 +238,11 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider im}}- if (!user.getAttributes().containsKey(KEYCLOAK_USER_ATTRIBUTE_EMAIL_NOTIFICATIONS_ENABLED)) {+ if (!user.isServiceAccount() && !user.getAttributes().containsKey(KEYCLOAK_USER_ATTRIBUTE_EMAIL_NOTIFICATIONS_ENABLED)) {user.setAttribute(KEYCLOAK_USER_ATTRIBUTE_EMAIL_NOTIFICATIONS_ENABLED,"true");}- if (!user.getAttributes().containsKey(KEYCLOAK_USER_ATTRIBUTE_PUSH_NOTIFICATIONS_ENABLED)) {+ if (!user.isServiceAccount() && !user.getAttributes().containsKey(KEYCLOAK_USER_ATTRIBUTE_PUSH_NOTIFICATIONS_ENABLED)) {user.setAttribute(KEYCLOAK_USER_ATTRIBUTE_PUSH_NOTIFICATIONS_ENABLED, "true");}diff --git a/manager/src/main/java/org/openremote/manager/setup/AbstractKeycloakSetup.java b/manager/src/main/java/org/openremote/manager/setup/AbstractKeycloakSetup.javaindex cd05afb96..46a3ca2c6 100644--- a/manager/src/main/java/org/openremote/manager/setup/AbstractKeycloakSetup.java+++ b/manager/src/main/java/org/openremote/manager/setup/AbstractKeycloakSetup.java@@ -32,6 +32,8 @@ import org.openremote.model.security.User;import java.util.Arrays;import java.util.Collections;+import static org.openremote.manager.security.ManagerKeycloakIdentityProvider.KEYCLOAK_USER_ATTRIBUTE_EMAIL_NOTIFICATIONS_ENABLED;+import static org.openremote.manager.security.ManagerKeycloakIdentityProvider.KEYCLOAK_USER_ATTRIBUTE_PUSH_NOTIFICATIONS_ENABLED;import static org.openremote.model.Constants.KEYCLOAK_CLIENT_ID;public abstract class AbstractKeycloakSetup implements Setup {@@ -81,12 +83,18 @@ public abstract class AbstractKeycloakSetup implements Setup {}protected User createUser(String realm, String username, String password, String firstName, String lastName, String email, boolean enabled, ClientRole[] roles) {+ return createUser(realm, username, password, firstName, lastName, email, enabled, true, true, roles);+ }++ protected User createUser(String realm, String username, String password, String firstName, String lastName, String email, boolean enabled, boolean emailNotificationsEnabled, boolean pushNotificationsEnabled, ClientRole[] roles) {User user = new User();user.setUsername(username);user.setFirstName(firstName);user.setLastName(lastName);user.setEmail(email);user.setEnabled(enabled);+ user.setAttribute(KEYCLOAK_USER_ATTRIBUTE_EMAIL_NOTIFICATIONS_ENABLED, Boolean.toString(emailNotificationsEnabled));+ user.setAttribute(KEYCLOAK_USER_ATTRIBUTE_PUSH_NOTIFICATIONS_ENABLED, Boolean.toString(pushNotificationsEnabled));user = keycloakProvider.createUpdateUser(realm, user, password);if (user == null) {return null;diff --git a/test/src/main/java/org/openremote/test/setup/KeycloakTestSetup.java b/test/src/main/java/org/openremote/test/setup/KeycloakTestSetup.javaindex 0e738d5c6..dc704dabd 100644--- a/test/src/main/java/org/openremote/test/setup/KeycloakTestSetup.java+++ b/test/src/main/java/org/openremote/test/setup/KeycloakTestSetup.java@@ -84,14 +84,14 @@ public class KeycloakTestSetup extends AbstractKeycloakSetup {User testuser1 = createUser(MASTER_REALM, "testuser1", "testuser1", "DemoMaster", "DemoLast", null, true, container.isDevMode() ? REGULAR_USER_ROLES : demoUserRoles);this.testuser1Id = testuser1.getId();keycloakProvider.updateUserRoles(MASTER_REALM, testuser1Id, "account"); // Remove all roles for account client- User testuser2 = createUser(tenantBuilding.getRealm(), "testuser2", "testuser2", "DemoA2", "DemoLast", "[email protected]", true, new ClientRole[] {+ User testuser2 = createUser(tenantBuilding.getRealm(), "testuser2", "testuser2", "DemoA2", "DemoLast", "[email protected]", true, true, false, new ClientRole[] {ClientRole.WRITE_USER,ClientRole.READ_MAP,ClientRole.READ_ASSETS});this.testuser2Id = testuser2.getId();keycloakProvider.updateUserRoles(tenantBuilding.getRealm(), testuser2Id, "account"); // Remove all roles for account client- User testuser3 = createUser(tenantBuilding.getRealm(), "testuser3", "testuser3", "DemoA3", "DemoLast", "[email protected]", true, container.isDevMode() ? REGULAR_USER_ROLES : demoUserRoles);+ User testuser3 = createUser(tenantBuilding.getRealm(), "testuser3", "testuser3", "DemoA3", "DemoLast", "[email protected]", true, false, true, container.isDevMode() ? REGULAR_USER_ROLES : demoUserRoles);this.testuser3Id = testuser3.getId();keycloakProvider.updateUserRoles(tenantBuilding.getRealm(), testuser3Id, "account"); // Remove all roles for account clientUser buildingUser = createUser(tenantBuilding.getRealm(), "building", "building", "Building", "User", "[email protected]", true, demoUserRoles);diff --git a/test/src/test/groovy/org/openremote/test/notification/NotificationTest.groovy b/test/src/test/groovy/org/openremote/test/notification/NotificationTest.groovyindex f0eea0b43..20c32460b 100644--- a/test/src/test/groovy/org/openremote/test/notification/NotificationTest.groovy+++ b/test/src/test/groovy/org/openremote/test/notification/NotificationTest.groovy@@ -180,13 +180,13 @@ class NotificationTest extends Specification implements ManagerContainerTrait {adminNotificationResource.sendNotification(null, notification)then: "all consoles in that realm should have been sent a notification"- assert notificationIds.size() == 4- assert notificationTargetTypes.count {t -> t == Notification.TargetType.ASSET} == 4- assert notificationTargetIds.contains(testuser2Console.id)+ assert notificationIds.size() == 3+ assert notificationTargetTypes.count {t -> t == Notification.TargetType.ASSET} == 3+ assert !notificationTargetIds.contains(testuser2Console.id)assert notificationTargetIds.contains(testuser3Console1.id)assert notificationTargetIds.contains(testuser3Console2.id)assert notificationTargetIds.contains(anonymousConsole.id)- assert notificationMessages.count {m -> m instanceof PushNotificationMessage && m.title == "Test Action" && m.body == "Click to cancel" && m.action != null} == 4+ assert notificationMessages.count {m -> m instanceof PushNotificationMessage && m.title == "Test Action" && m.body == "Click to cancel" && m.action != null} == 3when: "a regular user sends a push notification to an entire realm"testuser2NotificationResource.sendNotification(null, notification)@@ -195,11 +195,21 @@ class NotificationTest extends Specification implements ManagerContainerTrait {WebApplicationException ex = thrown()ex.response.status == 403- when: "the admin user sends a notification to a user in a different realm"+ when: "the admin user sends a notification to a user in a different realm with emailNotificationsEnabled set to false"notification.targets = [new Notification.Target(Notification.TargetType.USER, keycloakTestSetup.testuser2Id)]advancePseudoClock(1, TimeUnit.HOURS, container)adminNotificationResource.sendNotification(null, notification)+ then: "no notification should have been sent"+ ex = thrown()+ ex.response.status == 400+ notificationIds.size() == 3++ when: "the admin user sends a notification to a user in a different realm with emailNotificationsEnabled set to true"+ notification.targets = [new Notification.Target(Notification.TargetType.USER, keycloakTestSetup.testuser3Id)]+ advancePseudoClock(1, TimeUnit.HOURS, container)+ adminNotificationResource.sendNotification(null, notification)+then: "the notification should have been sent"notificationIds.size() == 5@@ -235,7 +245,7 @@ class NotificationTest extends Specification implements ManagerContainerTrait {adminNotificationResource.sendNotification(null, notification)then: "the notification should have been sent"- notificationIds.size() == 9+ notificationIds.size() == 8when: "a regular user sends a push notification to the console assets in a different realm"testuser1NotificationResource.sendNotification(null, notification)@@ -249,14 +259,14 @@ class NotificationTest extends Specification implements ManagerContainerTrait {testuser2NotificationResource.sendNotification(null, notification)then: "the notification should have been sent"- notificationIds.size() == 13+ notificationIds.size() == 11when: "a notification is sent using the same mechanism as an asset ruleset"notificationService.sendNotification(notification, Notification.Source.ASSET_RULESET, consoleResource.getConsoleParentAssetId(realm))then: "the notification should have been sent"new PollingConditions(timeout: 10, delay: 0.2).eventually {- assert notificationIds.size() == 17+ assert notificationIds.size() == 14}when: "a restricted user sends a push notification to the console assets in the same realm"@@ -278,7 +288,7 @@ class NotificationTest extends Specification implements ManagerContainerTrait {ex.response.status == 403and: "no new notifications should have been sent"- notificationIds.size() == 17+ notificationIds.size() == 14when: "a restricted user sends a push notification to some consoles linked to them"advancePseudoClock(1, TimeUnit.HOURS, container)@@ -287,7 +297,7 @@ class NotificationTest extends Specification implements ManagerContainerTrait {testuser3NotificationResource.sendNotification(null, notification)then: "the notifications should have been sent"- notificationIds.size() == 19+ notificationIds.size() == 16// -----------------------------------------------// Check notification resource@@ -301,7 +311,7 @@ class NotificationTest extends Specification implements ManagerContainerTrait {notifications.addAll(adminNotificationResource.getNotifications(null, null, null, null, null, null, null, anonymousConsole.id))then: "all notifications sent to these consoles should be returned"- assert notifications.size() == 19+ assert notifications.size() == 16assert notifications.count {n ->PushNotificationMessage pushMessage = n.message as PushNotificationMessagepushMessage.getTitle() == "Test Action" &&@@ -309,10 +319,10 @@ class NotificationTest extends Specification implements ManagerContainerTrait {pushMessage.getAction() != null &&n.deliveredOn == null &&n.acknowledgedOn == null- } == 19+ } == 16when: "the admin user marks a Building console notification as delivered and requests the notifications for Building consoles"- adminNotificationResource.notificationDelivered(null, testuser2Console.id, notifications.find {n -> n.targetId == testuser2Console.id}.id)+ adminNotificationResource.notificationDelivered(null, testuser3Console1.id, notifications.find {n -> n.targetId == testuser3Console1.id}.id)notifications = []notifications.addAll(adminNotificationResource.getNotifications(null, null, null, null, null, null, null, testuser2Console.id))notifications.addAll(adminNotificationResource.getNotifications(null, null, null, null, null, null, null, testuser3Console1.id))@@ -320,11 +330,11 @@ class NotificationTest extends Specification implements ManagerContainerTrait {notifications.addAll(adminNotificationResource.getNotifications(null, null, null, null, null, null, null, anonymousConsole.id))then: "the notification should have been updated"- assert notifications.size() == 19+ assert notifications.size() == 16assert notifications.count {n -> n.deliveredOn != null} == 1when: "the admin user marks a Building console notification as delivered and requests the notifications for Building consoles"- adminNotificationResource.notificationAcknowledged(null, testuser2Console.id, notifications.find {n -> n.targetId == testuser2Console.id && n.deliveredOn != null}.id, new TextNode("dismissed"))+ adminNotificationResource.notificationAcknowledged(null, testuser3Console1.id, notifications.find {n -> n.targetId == testuser3Console1.id && n.deliveredOn != null}.id, new TextNode("dismissed"))notifications = []notifications.addAll(adminNotificationResource.getNotifications(null, null, null, null, null, null, null, testuser2Console.id))notifications.addAll(adminNotificationResource.getNotifications(null, null, null, null, null, null, null, testuser3Console1.id))@@ -332,7 +342,7 @@ class NotificationTest extends Specification implements ManagerContainerTrait {notifications.addAll(adminNotificationResource.getNotifications(null, null, null, null, null, null, null, anonymousConsole.id))then: "the notification should have been updated"- assert notifications.size() == 19+ assert notifications.size() == 16assert notifications.count {n -> n.deliveredOn != null && n.acknowledgedOn != null && n.acknowledgement == "\"dismissed\""} == 1when: "a regular user marks a console notification from another realm as delivered"@@ -351,8 +361,8 @@ class NotificationTest extends Specification implements ManagerContainerTrait {notifications.addAll(adminNotificationResource.getNotifications(null, null, null, null, null, null, null, anonymousConsole.id))then: "the notification should have been updated"- assert notifications.size() == 19- assert notifications.count {n -> n.targetId == testuser3Console1.id && n.deliveredOn != null} == 1+ assert notifications.size() == 16+ assert notifications.count {n -> n.targetId == testuser3Console1.id && n.deliveredOn != null} == 2// TODO: Update once console permissions model finalised// when: "an anonymous user marks a console notification from another console as delivered"@@ -371,7 +381,7 @@ class NotificationTest extends Specification implements ManagerContainerTrait {notifications.addAll(adminNotificationResource.getNotifications(null, null, null, null, null, null, null, anonymousConsole.id))then: "the notification should have been updated"- assert notifications.size() == 19+ assert notifications.size() == 16assert notifications.count {n -> n.targetId == anonymousConsole.id && n.deliveredOn != null} == 1when: "a regular user tries to remove notifications"@@ -398,7 +408,7 @@ class NotificationTest extends Specification implements ManagerContainerTrait {notifications.addAll(adminNotificationResource.getNotifications(null, null, null, null, null, null, null, anonymousConsole.id))then: "notifications sent after or at that time should have been removed"- assert notifications.size() == 17+ assert notifications.size() == 14when: "the admin user removes notifications sent to specific console assets without other constraints and the notifications are retrieved again"adminNotificationResource.removeNotifications(null, null, null, null, null, null, null, testuser3Console1.id)@@ -410,7 +420,7 @@ class NotificationTest extends Specification implements ManagerContainerTrait {notifications.addAll(adminNotificationResource.getNotifications(null, null, null, null, null, null, null, anonymousConsole.id))then: "all notifications sent to those consoles should have been removed"- assert notifications.size() == 9+ assert notifications.size() == 4assert notifications.count {n -> n.targetId == testuser3Console1.id || n.targetId == testuser3Console2.id} == 0when: "the admin user removes notifications by type and the notifications are retrieved again"@@ -573,11 +583,11 @@ class NotificationTest extends Specification implements ManagerContainerTrait {then: "the email should have been sent to the tenant users"conditions.eventually {- assert sentEmails.size() >= 3+ assert sentEmails.size() >= 2assert sentEmails.every {it.getPlainText() == "Hello world!"}assert sentEmails.every {it.getSubject() == "Test"}assert sentEmails.any { it.getRecipients().size() == 1 && it.getRecipients().get(0).address == "[email protected]"}- assert sentEmails.any { it.getRecipients().size() == 1 && it.getRecipients().get(0).address == "[email protected]"}+ assert !sentEmails.any { it.getRecipients().size() == 1 && it.getRecipients().get(0).address == "[email protected]"}assert sentEmails.any { it.getRecipients().size() == 1 && it.getRecipients().get(0).address == "[email protected]"}}@@ -593,7 +603,7 @@ class NotificationTest extends Specification implements ManagerContainerTrait {then: "the child asset with the email attribute should have been sent an email"conditions.eventually {- assert sentEmails.size() >= 4+ assert sentEmails.size() >= 3assert sentEmails.any { it.getSubject() == "Test 2"}assert sentEmails.any { it.getRecipients().size() == 1 && it.getRecipients().get(0).address == "[email protected]"}}@@ -605,7 +615,7 @@ class NotificationTest extends Specification implements ManagerContainerTrait {then: "the email should have been sent to all custom recipients"conditions.eventually {- assert sentEmails.size() >= 5+ assert sentEmails.size() >= 4assert sentEmails.any { it.getSubject() == "Test Custom" && it.getRecipients().size() == 4}assert sentEmails.any { it.getSubject() == "Test Custom" && it.getRecipients().any{it.type == javax.mail.Message.RecipientType.TO && it.address == "[email protected]"}}assert sentEmails.any { it.getSubject() == "Test Custom" && it.getRecipients().any{it.type == javax.mail.Message.RecipientType.TO && it.address == "[email protected]"}}