Skip to content

Commit

Permalink
Show results of notifications emails
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed May 15, 2024
1 parent 9593178 commit 485062c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
4 changes: 2 additions & 2 deletions client/src/locale/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion client/src/locale/nl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 5 additions & 2 deletions client/src/tabs/Cron.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const Cron = () => {
const expiredNotificationsCron = () => {
return <div className="mod-cron">
<div className="actions">
<span>{I18n.t("system.cronInfo")}</span>
<span>{I18n.t("system.cronNotificationsInfo")}</span>
{isEmpty(mailResults) &&
<Button onClick={() => cronExpiryNotifications().then(res => setMailResults(res))}
txt={I18n.t("system.trigger")}/>}
Expand All @@ -43,11 +43,14 @@ export const Cron = () => {
</div>
{!isEmpty(mailResults) &&
<div className="cron-results">
{mailResults.map(mail => <div className="mail-content">
{mailResults["mails"].map(mail => <div className="mail-content">
<p dangerouslySetInnerHTML={{
__html: DOMPurify.sanitize(mail)
}}/>
</div>)}
{isEmpty(mailResults["mails"]) && <p>
{I18n.t("system.noMails")}
</p>}
</div>}
</div>;
}
Expand Down
4 changes: 2 additions & 2 deletions server/src/main/java/access/api/SystemController.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public ResponseEntity<Map<String, List<? extends Serializable>>> cronCleanup(@Pa
}

@GetMapping("/cron/expiry-notifications")
public ResponseEntity<List<String>> expiryNotifications(@Parameter(hidden = true) User user) {
public ResponseEntity<Map<String, List<String>>> 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")
Expand Down
18 changes: 18 additions & 0 deletions server/src/test/java/access/api/SystemControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

}


}

0 comments on commit 485062c

Please sign in to comment.