From 7e979b46bd415b45aa688d98c8ba29e96e40412e Mon Sep 17 00:00:00 2001 From: Okke Harsta Date: Thu, 2 May 2024 13:14:35 +0200 Subject: [PATCH] Resending an invite should use the language setting the original invite was sent in --- .../main/java/access/api/InvitationController.java | 3 ++- server/src/main/java/access/model/Invitation.java | 5 +++++ .../mysql/migration/V28_0__invitation_language.sql | 3 +++ server/src/test/java/access/AbstractTest.java | 12 ++++++------ server/src/test/java/access/mail/MailBoxTest.java | 1 + .../src/test/java/access/model/InvitationTest.java | 7 ++++--- 6 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 server/src/main/resources/db/mysql/migration/V28_0__invitation_language.sql diff --git a/server/src/main/java/access/api/InvitationController.java b/server/src/main/java/access/api/InvitationController.java index 6818d93a..2a85e130 100644 --- a/server/src/main/java/access/api/InvitationController.java +++ b/server/src/main/java/access/api/InvitationController.java @@ -118,6 +118,7 @@ public ResponseEntity> newInvitation(@Validated @RequestBod invitationRequest.isEduIDOnly(), invitationRequest.isGuestRoleIncluded(), invitationRequest.getMessage(), + invitationRequest.getLanguage(), user, invitationRequest.getExpiryDate(), invitationRequest.getRoleExpiryDate(), @@ -162,7 +163,7 @@ public ResponseEntity> resendInvitation(@PathVariable("id") UserPermissions.assertValidInvitation(user, intendedAuthority, requestedRoles); List groupedProviders = manage.getGroupedProviders(requestedRoles); - mailBox.sendInviteMail(user, invitation, groupedProviders, Language.en); + mailBox.sendInviteMail(user, invitation, groupedProviders, invitation.getLanguage()); if (invitation.getExpiryDate().isBefore(Instant.now())) { invitation.setExpiryDate(Instant.now().plus(Period.ofDays(14))); invitationRepository.save(invitation); diff --git a/server/src/main/java/access/model/Invitation.java b/server/src/main/java/access/model/Invitation.java index 7d8fc448..a8e46420 100644 --- a/server/src/main/java/access/model/Invitation.java +++ b/server/src/main/java/access/model/Invitation.java @@ -30,6 +30,9 @@ public class Invitation implements Serializable { @Column(name = "intended_authority") private Authority intendedAuthority; + @Enumerated(EnumType.STRING) + private Language language; + @Enumerated(EnumType.STRING) private Status status; @@ -82,6 +85,7 @@ public Invitation(Authority intendedAuthority, boolean eduIDOnly, boolean guestRoleIncluded, String message, + Language language, User inviter, Instant expiryDate, Instant roleExpiryDate, @@ -100,6 +104,7 @@ public Invitation(Authority intendedAuthority, this.roleExpiryDate = this.roleExpiryDate(roles, roleExpiryDate, intendedAuthority); this.createdAt = Instant.now(); roles.forEach(role -> role.setInvitation(this)); + this.language = language; } private Instant roleExpiryDate(@NotEmpty Set roles, Instant roleExpiryDate, Authority intendedAuthority) { diff --git a/server/src/main/resources/db/mysql/migration/V28_0__invitation_language.sql b/server/src/main/resources/db/mysql/migration/V28_0__invitation_language.sql new file mode 100644 index 00000000..0a09bf84 --- /dev/null +++ b/server/src/main/resources/db/mysql/migration/V28_0__invitation_language.sql @@ -0,0 +1,3 @@ +ALTER TABLE `invitations` ADD `language` VARCHAR(255) DEFAULT NULL; +UPDATE `invitations` SET `language` = 'en'; +ALTER TABLE `invitations` MODIFY `language` VARCHAR(255) NOT NULL; \ No newline at end of file diff --git a/server/src/test/java/access/AbstractTest.java b/server/src/test/java/access/AbstractTest.java index e52216bd..94a2cd55 100644 --- a/server/src/test/java/access/AbstractTest.java +++ b/server/src/test/java/access/AbstractTest.java @@ -590,18 +590,18 @@ public void doSeed() { Instant expiryDate = Instant.now().plus(14, ChronoUnit.DAYS); Invitation superUserInvitation = - new Invitation(Authority.SUPER_USER, Authority.SUPER_USER.name(), "super_user@new.com", false, false, false, message, + new Invitation(Authority.SUPER_USER, Authority.SUPER_USER.name(), "super_user@new.com", false, false, false, message, Language.en, inviter,expiryDate, roleExpiryDate, Set.of()); Invitation managerInvitation = - new Invitation(Authority.MANAGER, Authority.MANAGER.name(), "manager@new.com", false, false, false, message, + new Invitation(Authority.MANAGER, Authority.MANAGER.name(), "manager@new.com", false, false, false, message, Language.en, inviter, expiryDate,roleExpiryDate, Set.of(new InvitationRole(research))); Invitation inviterInvitation = - new Invitation(Authority.INVITER, Authority.INVITER.name(), "inviter@new.com", false, false, true, message, + new Invitation(Authority.INVITER, Authority.INVITER.name(), "inviter@new.com", false, false, true, message, Language.en, inviter, expiryDate,roleExpiryDate, Set.of(new InvitationRole(calendar), new InvitationRole(mail))); inviterInvitation.setEnforceEmailEquality(true); Invitation guestInvitation = new Invitation(Authority.GUEST, Authority.GUEST.name(), "guest@new.com", - false, false, false, message, + false, false, false, message, Language.en, inviter, expiryDate,roleExpiryDate, Set.of(new InvitationRole(mail))); guestInvitation.setEduIDOnly(true); //To test graph callback @@ -609,12 +609,12 @@ public void doSeed() { Invitation institutionAdminInvitation = new Invitation(Authority.INSTITUTION_ADMIN, INSTITUTION_ADMIN_INVITATION_HASH, "institutionh@admin.com", - false, false, false, message, + false, false, false, message, Language.en, institutionAdmin, expiryDate, roleExpiryDate, Set.of(new InvitationRole(network))); Invitation graphInvitation = new Invitation(Authority.GUEST, GRAPH_INVITATION_HASH, "graph@new.com", - false, false, false, message, + false, false, false, message, Language.en, inviter,expiryDate, roleExpiryDate, Set.of(new InvitationRole(network))); doSave(invitationRepository, superUserInvitation, managerInvitation, inviterInvitation, guestInvitation, institutionAdminInvitation, graphInvitation); diff --git a/server/src/test/java/access/mail/MailBoxTest.java b/server/src/test/java/access/mail/MailBoxTest.java index 43a6b41f..0c8951ef 100644 --- a/server/src/test/java/access/mail/MailBoxTest.java +++ b/server/src/test/java/access/mail/MailBoxTest.java @@ -49,6 +49,7 @@ private String doSendInviteMail(boolean eduIDOnly, Authority intendedAuthority) eduIDOnly, false, "Please join..", + Language.en, user, Instant.now().plus(30, ChronoUnit.DAYS), Instant.now().plus(365, ChronoUnit.DAYS), diff --git a/server/src/test/java/access/model/InvitationTest.java b/server/src/test/java/access/model/InvitationTest.java index 324c8956..f5c10b95 100644 --- a/server/src/test/java/access/model/InvitationTest.java +++ b/server/src/test/java/access/model/InvitationTest.java @@ -17,7 +17,7 @@ class InvitationTest extends WithApplicationTest { void constructorWithoutDefaults() { Role role = new Role("mail", "description", application( "1", EntityType.SAML20_SP), 30, false, false); - Invitation invitation = new Invitation(Authority.GUEST, "hash", "john@example.com", false, false, false, "Please join..", new User(), + Invitation invitation = new Invitation(Authority.GUEST, "hash", "john@example.com", false, false, false, "Please join..", Language.en, new User(), null, Instant.now().plus(30, ChronoUnit.DAYS), Set.of(new InvitationRole(role))); @@ -29,7 +29,7 @@ void constructorWithoutDefaults() { void constructorWithDefaults() { Role role = new Role("mail", "description", application( "1", EntityType.SAML20_SP), null, false, false); - Invitation invitation = new Invitation(Authority.MANAGER, "hash", "john@example.com", false, false, false, "Please join..", new User(), + Invitation invitation = new Invitation(Authority.MANAGER, "hash", "john@example.com", false, false, false, "Please join..", Language.en, new User(), null, null, Set.of(new InvitationRole(role))); assertEquals(13, Instant.now().until(invitation.getExpiryDate(), ChronoUnit.DAYS)); assertNull(invitation.getRoleExpiryDate()); @@ -39,7 +39,8 @@ void constructorWithDefaults() { void roleExpiryDate() { Role role = new Role("mail", "description", application("1", EntityType.SAML20_SP), 30, false, false); - Invitation invitation = new Invitation(Authority.GUEST, "hash", "john@example.com", false, false, false, "Please join..", new User(), + Invitation invitation = new Invitation(Authority.GUEST, "hash", "john@example.com", + false, false, false, "Please join..", Language.en, new User(), null, null, Set.of(new InvitationRole(role)));