Fixing action token lifespan information in the invitation email

Closes #34049

Signed-off-by: Pedro Igor <pigor.craveiro@gmail.com>
This commit is contained in:
Pedro Igor 2024-10-17 19:02:44 -03:00 committed by Alexander Schwartz
parent d1dba15964
commit 3a9bab35b6
2 changed files with 7 additions and 2 deletions

View file

@ -111,7 +111,7 @@ public class OrganizationInvitationResource {
session.getProvider(EmailTemplateProvider.class) session.getProvider(EmailTemplateProvider.class)
.setRealm(realm) .setRealm(realm)
.setUser(user) .setUser(user)
.sendOrgInviteEmail(organization, link, TimeUnit.SECONDS.toMinutes(tokenExpiration)); .sendOrgInviteEmail(organization, link, TimeUnit.SECONDS.toMinutes(getActionTokenLifespan()));
} catch (EmailException e) { } catch (EmailException e) {
ServicesLogger.LOGGER.failedToSendEmail(e); ServicesLogger.LOGGER.failedToSendEmail(e);
throw ErrorResponse.error("Failed to send invite email", Status.INTERNAL_SERVER_ERROR); throw ErrorResponse.error("Failed to send invite email", Status.INTERNAL_SERVER_ERROR);
@ -123,7 +123,11 @@ public class OrganizationInvitationResource {
} }
private int getTokenExpiration() { private int getTokenExpiration() {
return Time.currentTime() + realm.getActionTokenGeneratedByAdminLifespan(); return Time.currentTime() + getActionTokenLifespan();
}
private int getActionTokenLifespan() {
return realm.getActionTokenGeneratedByAdminLifespan();
} }
private String createInvitationLink(UserModel user) { private String createInvitationLink(UserModel user) {

View file

@ -256,6 +256,7 @@ public class OrganizationInvitationLinkTest extends AbstractOrganizationTest {
assertThat(text, Matchers.containsString(("You were invited to join the " + organizationName + " organization. Click the link below to join. </p>"))); assertThat(text, Matchers.containsString(("You were invited to join the " + organizationName + " organization. Click the link below to join. </p>")));
assertThat(text, Matchers.containsString(("<a href=\"" + link + "\" rel=\"nofollow\">Link to join the organization</a></p>"))); assertThat(text, Matchers.containsString(("<a href=\"" + link + "\" rel=\"nofollow\">Link to join the organization</a></p>")));
assertThat(text, Matchers.containsString(("Link to join the organization"))); assertThat(text, Matchers.containsString(("Link to join the organization")));
assertThat(text, Matchers.containsString(("This link will expire within 12 hours")));
assertThat(text, Matchers.containsString(("<p>If you dont want to join the organization, just ignore this message.</p>"))); assertThat(text, Matchers.containsString(("<p>If you dont want to join the organization, just ignore this message.</p>")));
String orgToken = UriUtils.parseQueryParameters(link, false).values().stream().map(strings -> strings.get(0)).findFirst().orElse(null); String orgToken = UriUtils.parseQueryParameters(link, false).values().stream().map(strings -> strings.get(0)).findFirst().orElse(null);