Skip to content

Commit 58fba77

Browse files
committed
Fixes #561
1 parent 35b1b9a commit 58fba77

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

server/src/main/java/invite/config/HashGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static String generateRandomHash() {
2323
}
2424

2525
public static String generateToken() {
26-
return RandomStringUtils.random(36, true, true);
26+
return RandomStringUtils.secure().random(36, true, true);
2727
}
2828

2929
public static String hashToken(String token) {

server/src/main/java/invite/cron/RoleExpirationNotifier.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public List<String> doSweep() {
5858
List<GroupedProviders> groupedProviders = manage.getGroupedProviders(List.of(userRole.getRole()));
5959
GroupedProviders groupedProvider = groupedProviders.isEmpty() ? null : groupedProviders.get(0);
6060
Instant endDate = userRole.getEndDate();
61-
long daysBetween = ChronoUnit.DAYS.between(endDate, instant);
62-
String mail = mailBox.sendUserRoleExpirationNotificationMail(userRole, groupedProvider, roleExpirationNotificationDays);
61+
long daysBetween = Math.min(ChronoUnit.DAYS.between(endDate, instant) - roleExpirationNotificationDays, roleExpirationNotificationDays) ;
62+
String mail = mailBox.sendUserRoleExpirationNotificationMail(userRole, groupedProvider, (int) daysBetween);
6363
//https://stackoverflow.com/a/75121707
6464
userRoleRepository.updateExpiryNotifications(1, userRole.getId());
6565

server/src/main/resources/templates/role_expiration_en.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
</p>
1313
{{/environment}}
1414
<p class="title" style="font-weight: 600;font-size: 38px;line-height: 38px; margin: 0;margin-bottom: 10px;">Your
15-
{{userRole.role.name}} role will expire in {{nbrOfDays}} days.</p>
15+
{{userRole.role.name}} role will expire in {{nbrOfDays}} day(s).</p>
1616
</div>
1717
<div class="middle" style="padding: 20px 0 40px 60px;max-width: 600px;">
1818
<p>Hi, {{userRole.user.name}}</p>
1919
<p>Your {{authority}} role {{userRole.role.name}}{{#groupedProvider}} at the application
2020
{{groupedProvider.name}}{{/groupedProvider}} will expire in {{nbrOfDays}} days.
21-
If you think this is a mistake you can reach out to your contactperson at your institution for
21+
If you think this is a mistake, you can reach out to your contactperson at your institution for
2222
a renewal of your {{authority}} role.
2323
{{#groupedProvider}}
2424
<table>

server/src/test/java/invite/cron/RoleExpirationNotifierTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class RoleExpirationNotifierTest extends AbstractMailTest {
2323
@Test
2424
void sweep() {
2525
UserRole userRole = userRoleRepository.findByRoleName("Mail").get(0);
26-
userRole.setEndDate(Instant.now().minus(7, ChronoUnit.DAYS));
26+
userRole.setEndDate(Instant.now().minus(1, ChronoUnit.DAYS));
2727
super.stubForManageProviderById(EntityType.OIDC10_RP, "5");
2828

2929
userRoleRepository.save(userRole);
@@ -33,8 +33,9 @@ void sweep() {
3333
MimeMessageParser messageParser = super.mailMessage();
3434
String htmlContent = messageParser.getHtmlContent();
3535
//Due to HTML formatting, we can't be sure of the line breaks
36-
Stream.of("Your Inviter role Mail at the application Calendar EN will expire in 5 days".split(" "))
36+
Stream.of("Your Inviter role Mail at the application Calendar EN will expire".split(" "))
3737
.forEach(s -> assertTrue(htmlContent.contains(s)));
38+
assertTrue(htmlContent.contains("1 day(s)"));
3839

3940
userRole = userRoleRepository.findByRoleName("Mail").get(0);
4041
assertEquals(1, userRole.getExpiryNotifications());

0 commit comments

Comments
 (0)