Skip to content

Commit

Permalink
generate notifications 3 days before expiry (#2586)
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Avetisyan <[email protected]>
Co-authored-by: Henry Avetisyan <[email protected]>
  • Loading branch information
havetisyan and havetisyan authored Apr 16, 2024
1 parent 666b4f3 commit 489cad3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public class JDBCConnection implements ObjectStoreConnection {
+ "WHERE DAYOFWEEK(req_time)=DAYOFWEEK(?) AND (last_notified_time IS NULL || last_notified_time < (CURRENT_TIME - INTERVAL ? DAY));";
private static final String SQL_UPDATE_ROLE_MEMBERS_EXPIRY_NOTIFICATION_TIMESTAMP =
"UPDATE role_member SET last_notified_time=?, server=? "
+ "WHERE expiration > CURRENT_TIME AND DATEDIFF(expiration, CURRENT_TIME) IN (0,1,7,14,21,28);";
+ "WHERE expiration > CURRENT_TIME AND DATEDIFF(expiration, CURRENT_TIME) IN (0,1,3,7,14,21,28);";
private static final String SQL_LIST_NOTIFY_TEMPORARY_ROLE_MEMBERS = "SELECT domain.name AS domain_name, role.name AS role_name, "
+ "principal.name AS principal_name, role_member.expiration, role_member.review_reminder FROM role_member "
+ "JOIN role ON role.role_id=role_member.role_id "
Expand All @@ -393,7 +393,7 @@ public class JDBCConnection implements ObjectStoreConnection {
+ "WHERE role_member.last_notified_time=? AND role_member.server=?;";
private static final String SQL_UPDATE_ROLE_MEMBERS_REVIEW_NOTIFICATION_TIMESTAMP =
"UPDATE role_member SET review_last_notified_time=?, review_server=? "
+ "WHERE review_reminder > CURRENT_TIME AND expiration IS NULL AND DATEDIFF(review_reminder, CURRENT_TIME) IN (0,1,7,14,21,28);";
+ "WHERE review_reminder > CURRENT_TIME AND expiration IS NULL AND DATEDIFF(review_reminder, CURRENT_TIME) IN (0,1,3,7,14,21,28);";
private static final String SQL_LIST_NOTIFY_REVIEW_ROLE_MEMBERS = "SELECT domain.name AS domain_name, role.name AS role_name, "
+ "principal.name AS principal_name, role_member.expiration, role_member.review_reminder FROM role_member "
+ "JOIN role ON role.role_id=role_member.role_id "
Expand Down Expand Up @@ -541,7 +541,7 @@ public class JDBCConnection implements ObjectStoreConnection {
+ "WHERE grp.self_serve=true AND pgm.last_notified_time=? AND pgm.server=?;";
private static final String SQL_UPDATE_GROUP_MEMBERS_EXPIRY_NOTIFICATION_TIMESTAMP =
"UPDATE principal_group_member SET last_notified_time=?, server=? "
+ "WHERE expiration > CURRENT_TIME AND DATEDIFF(expiration, CURRENT_TIME) IN (0,1,7,14,21,28);";
+ "WHERE expiration > CURRENT_TIME AND DATEDIFF(expiration, CURRENT_TIME) IN (0,1,3,7,14,21,28);";
private static final String SQL_LIST_NOTIFY_TEMPORARY_GROUP_MEMBERS = "SELECT domain.name AS domain_name, principal_group.name AS group_name, "
+ "principal.name AS principal_name, principal_group_member.expiration FROM principal_group_member "
+ "JOIN principal_group ON principal_group.group_id=principal_group_member.group_id "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@ public void testRoleExpiryNotification() {
notificationToEmailConverterCommon, false);
List<Notification> notifications = roleMemberExpiryNotificationTask.getNotifications();

// Email notifications should be sent every 7 days while metrics should be recorded every day
Set<String> emailNotificationMembers = new HashSet<>(Arrays.asList("user.expireddays0",
// Email notifications should be sent 0,1,3,7,14,21,28 days
// while metrics should be recorded every day
Set<String> emailNotificationMembers = new HashSet<>(Arrays.asList(
"user.expireddays0",
"user.expireddays1",
"user.expireddays3",
"user.expireddays7",
"user.expireddays14",
"user.expireddays21",
Expand Down Expand Up @@ -148,14 +151,16 @@ public void testGroupExpiryNotification() {
zmsImpl.notificationToEmailConverterCommon, false);
List<Notification> notifications = groupMemberExpiryNotificationTask.getNotifications();

// Email notifications should be sent every 7 days
Set<String> emailNotificationMembers = new HashSet<>(Arrays.asList("user.expireddays0",
// Email notifications are generated based 0,1,3,7,14,21,28 days schedule
Set<String> emailNotificationMembers = new HashSet<>(Arrays.asList(
"user.expireddays0",
"user.expireddays1",
"user.expireddays3",
"user.expireddays7",
"user.expireddays14",
"user.expireddays21",
"user.expireddays28"));
assertEquals(notifications.size(), 7, "notificationRecipients: " + notificationsToRecipientString(notifications));
assertEquals(notifications.size(), 8, "notificationRecipients: " + notificationsToRecipientString(notifications));
for (Notification notification : notifications) {
String recipient = notification.getRecipients().stream().findFirst().get();
if (recipient.equals("user.testadminuser")) {
Expand Down Expand Up @@ -204,10 +209,11 @@ public void testDisableUserGroupExpiryNotification() {
zmsImpl.notificationToEmailConverterCommon, false);
List<Notification> notifications = groupMemberExpiryNotificationTask.getNotifications();

// Email notifications should be sent every 7 days
// Email notifications are generated based 0,1,3,7,14,21,28 days schedule
Set<String> emailNotificationMembers = new HashSet<>(Arrays.asList(
"user.expireddays0",
"user.expireddays1",
"user.expireddays3",
"user.expireddays7",
"user.expireddays14",
"user.expireddays21",
Expand Down Expand Up @@ -258,14 +264,16 @@ public void testDisableAdminGroupExpiryNotification() {
zmsImpl.notificationToEmailConverterCommon, false);
List<Notification> notifications = groupMemberExpiryNotificationTask.getNotifications();

// Email notifications should be sent every 7 days
Set<String> emailNotificationMembers = new HashSet<>(Arrays.asList("user.expireddays0",
// Email notifications are generated based 0,1,3,7,14,21,28 days schedule
Set<String> emailNotificationMembers = new HashSet<>(Arrays.asList(
"user.expireddays0",
"user.expireddays1",
"user.expireddays3",
"user.expireddays7",
"user.expireddays14",
"user.expireddays21",
"user.expireddays28"));
assertEquals(notifications.size(), 6, "notificationRecipients: " + notificationsToRecipientString(notifications));
assertEquals(notifications.size(), 7, "notificationRecipients: " + notificationsToRecipientString(notifications));
for (Notification notification : notifications) {
assertEquals(notification.getRecipients().size(), 1, "notificationRecipients: "
+ notificationsToRecipientString(notifications));
Expand Down

0 comments on commit 489cad3

Please sign in to comment.