Skip to content

Commit

Permalink
Resending an invite should use the language setting the original invi…
Browse files Browse the repository at this point in the history
…te was sent in
  • Loading branch information
oharsta committed May 2, 2024
1 parent 5daf214 commit 7e979b4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
3 changes: 2 additions & 1 deletion server/src/main/java/access/api/InvitationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public ResponseEntity<Map<String, Integer>> newInvitation(@Validated @RequestBod
invitationRequest.isEduIDOnly(),
invitationRequest.isGuestRoleIncluded(),
invitationRequest.getMessage(),
invitationRequest.getLanguage(),
user,
invitationRequest.getExpiryDate(),
invitationRequest.getRoleExpiryDate(),
Expand Down Expand Up @@ -162,7 +163,7 @@ public ResponseEntity<Map<String, Integer>> resendInvitation(@PathVariable("id")
UserPermissions.assertValidInvitation(user, intendedAuthority, requestedRoles);
List<GroupedProviders> 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);
Expand Down
5 changes: 5 additions & 0 deletions server/src/main/java/access/model/Invitation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -82,6 +85,7 @@ public Invitation(Authority intendedAuthority,
boolean eduIDOnly,
boolean guestRoleIncluded,
String message,
Language language,
User inviter,
Instant expiryDate,
Instant roleExpiryDate,
Expand All @@ -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<InvitationRole> roles, Instant roleExpiryDate, Authority intendedAuthority) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 6 additions & 6 deletions server/src/test/java/access/AbstractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -590,31 +590,31 @@ public void doSeed() {
Instant expiryDate = Instant.now().plus(14, ChronoUnit.DAYS);

Invitation superUserInvitation =
new Invitation(Authority.SUPER_USER, Authority.SUPER_USER.name(), "[email protected]", false, false, false, message,
new Invitation(Authority.SUPER_USER, Authority.SUPER_USER.name(), "[email protected]", false, false, false, message, Language.en,
inviter,expiryDate, roleExpiryDate, Set.of());
Invitation managerInvitation =
new Invitation(Authority.MANAGER, Authority.MANAGER.name(), "[email protected]", false, false, false, message,
new Invitation(Authority.MANAGER, Authority.MANAGER.name(), "[email protected]", false, false, false, message, Language.en,
inviter, expiryDate,roleExpiryDate, Set.of(new InvitationRole(research)));
Invitation inviterInvitation =
new Invitation(Authority.INVITER, Authority.INVITER.name(), "[email protected]", false, false, true, message,
new Invitation(Authority.INVITER, Authority.INVITER.name(), "[email protected]", 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(), "[email protected]",
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
guestInvitation.setSubInvitee(GUEST_SUB);

Invitation institutionAdminInvitation =
new Invitation(Authority.INSTITUTION_ADMIN, INSTITUTION_ADMIN_INVITATION_HASH, "[email protected]",
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, "[email protected]",
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);
Expand Down
1 change: 1 addition & 0 deletions server/src/test/java/access/mail/MailBoxTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
7 changes: 4 additions & 3 deletions server/src/test/java/access/model/InvitationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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", "[email protected]", false, false, false, "Please join..", new User(),
Invitation invitation = new Invitation(Authority.GUEST, "hash", "[email protected]", false, false, false, "Please join..", Language.en, new User(),
null, Instant.now().plus(30, ChronoUnit.DAYS),
Set.of(new InvitationRole(role)));

Expand All @@ -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", "[email protected]", false, false, false, "Please join..", new User(),
Invitation invitation = new Invitation(Authority.MANAGER, "hash", "[email protected]", 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());
Expand All @@ -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", "[email protected]", false, false, false, "Please join..", new User(),
Invitation invitation = new Invitation(Authority.GUEST, "hash", "[email protected]",
false, false, false, "Please join..", Language.en, new User(),
null, null,
Set.of(new InvitationRole(role)));

Expand Down

0 comments on commit 7e979b4

Please sign in to comment.