From 485062c56ba685ed770ad050b7f291e231dc416f Mon Sep 17 00:00:00 2001 From: Okke Harsta Date: Wed, 15 May 2024 10:30:14 +0200 Subject: [PATCH] Show results of notifications emails --- client/src/locale/en.js | 4 ++-- client/src/locale/nl.js | 3 ++- client/src/tabs/Cron.js | 7 +++++-- .../main/java/access/api/SystemController.java | 4 ++-- .../java/access/api/SystemControllerTest.java | 18 ++++++++++++++++++ 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/client/src/locale/en.js b/client/src/locale/en.js index 6ab74bad..5553cc42 100644 --- a/client/src/locale/en.js +++ b/client/src/locale/en.js @@ -450,8 +450,8 @@ const en = { trigger: "Trigger", clear: "Clear", cronInfo: "Trigger the cron job to cleanup resources like expired user-roles, orphaned users and in-active users", - cronNotificationsInfo: "Trigger the cron job to send notification mails for user-roles thaat will expire in X days" - + cronNotificationsInfo: "Trigger the cron job to send notification mails for user-roles that will expire in X days", + noMails: "No notification mails for user-role expirations were send" }, unknownRoles: { title: "Roles linked to applications unknown in Manage", diff --git a/client/src/locale/nl.js b/client/src/locale/nl.js index 6f1104ca..759482b3 100644 --- a/client/src/locale/nl.js +++ b/client/src/locale/nl.js @@ -450,7 +450,8 @@ const nl = { trigger: "Trigger", clear: "Clear", cronInfo: "Roep de cron job aan die resources opruimt, zoals verlopen gebruikersrollen, verweesde gebruikers en inactieve gebruikers", - cronNotificationsInfo: "Roep de cron job aan die notificatie mails verstuurd voor gebruikersrollen die verlopen in X dagen" + cronNotificationsInfo: "Roep de cron job aan die notificatie mails verstuurd voor gebruikersrollen die verlopen in X dagen", + noMails: "Geen notificatie mails zijn vertstuurd voor bijna verlopen gebruikersrollen" }, unknownRoles: { title: "Rollen gekoppeld aan applicaties die verwijderd zijn in Manage", diff --git a/client/src/tabs/Cron.js b/client/src/tabs/Cron.js index a9f6c3ec..22d74b56 100644 --- a/client/src/tabs/Cron.js +++ b/client/src/tabs/Cron.js @@ -33,7 +33,7 @@ export const Cron = () => { const expiredNotificationsCron = () => { return
- {I18n.t("system.cronInfo")} + {I18n.t("system.cronNotificationsInfo")} {isEmpty(mailResults) &&
{!isEmpty(mailResults) &&
- {mailResults.map(mail =>
+ {mailResults["mails"].map(mail =>

)} + {isEmpty(mailResults["mails"]) &&

+ {I18n.t("system.noMails")} +

}
}
; } diff --git a/server/src/main/java/access/api/SystemController.java b/server/src/main/java/access/api/SystemController.java index 451c5733..2f16c271 100644 --- a/server/src/main/java/access/api/SystemController.java +++ b/server/src/main/java/access/api/SystemController.java @@ -66,10 +66,10 @@ public ResponseEntity>> cronCleanup(@Pa } @GetMapping("/cron/expiry-notifications") - public ResponseEntity> expiryNotifications(@Parameter(hidden = true) User user) { + public ResponseEntity>> expiryNotifications(@Parameter(hidden = true) User user) { LOG.debug("/cron/expiry-notifications"); UserPermissions.assertSuperUser(user); - return ResponseEntity.ok(roleExpirationNotifier.doSweep()); + return ResponseEntity.ok(Map.of("mails", roleExpirationNotifier.doSweep())); } @GetMapping("/expiry-user-roles") diff --git a/server/src/test/java/access/api/SystemControllerTest.java b/server/src/test/java/access/api/SystemControllerTest.java index e84d99b3..2fb43e6f 100644 --- a/server/src/test/java/access/api/SystemControllerTest.java +++ b/server/src/test/java/access/api/SystemControllerTest.java @@ -3,6 +3,7 @@ import access.AbstractTest; import access.AccessCookieFilter; import io.restassured.http.ContentType; +import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; import static access.AbstractTest.SUPER_SUB; @@ -39,4 +40,21 @@ void expiryUserRoles() throws Exception { .statusCode(200); } + @Test + void expiryNotifications() throws Exception { + AccessCookieFilter accessCookieFilter = openIDConnectFlow("/api/v1/users/login", SUPER_SUB); + given() + .when() + .filter(accessCookieFilter.cookieFilter()) + .accept(ContentType.JSON) + .header(accessCookieFilter.csrfToken().getHeaderName(), accessCookieFilter.csrfToken().getToken()) + .contentType(ContentType.JSON) + .get("/api/v1/system/cron/expiry-notifications") + .then() + .body("mails", Matchers.hasSize(0)) + .statusCode(200); + + } + + } \ No newline at end of file