From 6e55ffe1e44ce5e7a518bc66f9320428c85a9abf Mon Sep 17 00:00:00 2001 From: cgeorgilakis-grnet Date: Fri, 15 Nov 2024 14:34:35 +0200 Subject: [PATCH] Change invitation emails for group admins --- CHANGELOG.md | 1 + .../CustomFreeMarkerEmailTemplateProvider.java | 14 ++++++++------ .../plugins/groups/services/GroupAdminGroup.java | 2 +- .../groups/services/GroupAdminGroupMembers.java | 2 +- .../email/html/invitation-admin-inform.ftl | 2 +- .../email/messages/messages_en.properties | 6 +++--- .../email/text/invitation-admin-inform.ftl | 2 +- 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d9008f4..78ae7e5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Change suspend and reactivate email - Change group membership update email +- Change invitation emails for group admins ### Fixed - General email fixes diff --git a/src/main/java/org/rciam/plugins/groups/email/CustomFreeMarkerEmailTemplateProvider.java b/src/main/java/org/rciam/plugins/groups/email/CustomFreeMarkerEmailTemplateProvider.java index 0256c83f..4585d00d 100644 --- a/src/main/java/org/rciam/plugins/groups/email/CustomFreeMarkerEmailTemplateProvider.java +++ b/src/main/java/org/rciam/plugins/groups/email/CustomFreeMarkerEmailTemplateProvider.java @@ -287,19 +287,21 @@ public void sendRejectionInvitationEmail(UserModel userModel, String groupPath, send("groupRejectionInvitationSubject", Stream.of(titleType, groupPath).collect(Collectors.toList()), "reject-invitation.ftl", attributes); } - public void sendInvitionAdminInformationEmail(String email, boolean forMember, String groupname, UserModel admin, List groupRoles) throws EmailException { + public void sendInvitionAdminInformationEmail(String email, boolean forMember, String groupPath, UserModel admin, List groupRoles) throws EmailException { attributes.put("fullname", user.getFirstName() + " " + user.getLastName()); attributes.put("email", email); - attributes.put("type", forMember ? "member" : "admin"); + attributes.put("type", forMember ? "a member" : "an administrator"); if (forMember && groupRoles != null && !groupRoles.isEmpty()) { - StringBuilder sb2 = new StringBuilder(groupname).append(" with roles : "); + StringBuilder sb2 = new StringBuilder(groupPath).append(" with roles: "); groupRoles.stream().forEach(role -> sb2.append(role).append(", ")); - groupname = StringUtils.removeEnd(sb2.toString(), ", "); + String groupPathEnchance = StringUtils.removeEnd(sb2.toString(), ", "); + attributes.put("groupPath", groupPathEnchance); + } else { + attributes.put("groupPath", groupPath); } - attributes.put("groupname", groupname); attributes.put("adminFullName", admin.getFirstName() + " " + admin.getLastName()); attributes.put("signatureMessage", signatureMessage); - send(forMember ? "groupInvitationSubject" : "groupInvitationAdminInformSubject", "invitation-admin-inform.ftl", attributes); + send(forMember ? "groupInvitationSubject" : "groupInvitationAdminInformSubject", Stream.of(groupPath).collect(Collectors.toList()), "invitation-admin-inform.ftl", attributes); } public void sendAddRemoveAdminAdminInformationEmail(boolean added, String groupPath, String groupId, UserModel adminAdded, UserModel adminAction) throws EmailException { diff --git a/src/main/java/org/rciam/plugins/groups/services/GroupAdminGroup.java b/src/main/java/org/rciam/plugins/groups/services/GroupAdminGroup.java index 2e6591f1..266f83c9 100644 --- a/src/main/java/org/rciam/plugins/groups/services/GroupAdminGroup.java +++ b/src/main/java/org/rciam/plugins/groups/services/GroupAdminGroup.java @@ -322,7 +322,7 @@ public Response inviteGroupAdmin(UserRepresentation userRep) throws EmailExcepti groupAdminRepository.getAllAdminIdsGroupUsers(group).filter(x -> !groupAdmin.getId().equals(x)).map(id -> session.users().getUserById(realm, id)).forEach(admin -> { try { customFreeMarkerEmailTemplateProvider.setUser(admin); - customFreeMarkerEmailTemplateProvider.sendInvitionAdminInformationEmail(userRep.getEmail(), false, group.getName(), groupAdmin, null); + customFreeMarkerEmailTemplateProvider.sendInvitionAdminInformationEmail(userRep.getEmail(), false, org.rciam.plugins.groups.helpers.ModelToRepresentation.buildGroupPath(group), groupAdmin, null); } catch (EmailException e) { throw new RuntimeException(e); } diff --git a/src/main/java/org/rciam/plugins/groups/services/GroupAdminGroupMembers.java b/src/main/java/org/rciam/plugins/groups/services/GroupAdminGroupMembers.java index dd588562..e41131d8 100644 --- a/src/main/java/org/rciam/plugins/groups/services/GroupAdminGroupMembers.java +++ b/src/main/java/org/rciam/plugins/groups/services/GroupAdminGroupMembers.java @@ -98,7 +98,7 @@ public Response inviteUser(GroupInvitationInitialRepresentation groupInvitationI groupAdminRepository.getAllAdminIdsGroupUsers(group).filter(x -> !groupAdmin.getId().equals(x)).map(id -> session.users().getUserById(realm, id)).forEach(admin -> { try { customFreeMarkerEmailTemplateProvider.setUser(admin); - customFreeMarkerEmailTemplateProvider.sendInvitionAdminInformationEmail(user.getEmail(), true, group.getName(), groupAdmin, groupInvitationInitialRep.getGroupRoles()); + customFreeMarkerEmailTemplateProvider.sendInvitionAdminInformationEmail(user.getEmail(), true, ModelToRepresentation.buildGroupPath(group), groupAdmin, groupInvitationInitialRep.getGroupRoles()); } catch (EmailException e) { throw new RuntimeException(e); } diff --git a/src/main/resources/theme/rciam-group/email/html/invitation-admin-inform.ftl b/src/main/resources/theme/rciam-group/email/html/invitation-admin-inform.ftl index e99fded9..6bde6e29 100644 --- a/src/main/resources/theme/rciam-group/email/html/invitation-admin-inform.ftl +++ b/src/main/resources/theme/rciam-group/email/html/invitation-admin-inform.ftl @@ -1,5 +1,5 @@ -${kcSanitize(msg("groupInvitationAdminInformBodyHtml", fullname, email, type, groupname, adminFullName, signatureMessage))?no_esc} +${kcSanitize(msg("groupInvitationAdminInformBodyHtml", fullname, adminFullName, email, type, groupPath, signatureMessage))?no_esc} \ No newline at end of file diff --git a/src/main/resources/theme/rciam-group/email/messages/messages_en.properties b/src/main/resources/theme/rciam-group/email/messages/messages_en.properties index 9652ea5b..7752c26a 100644 --- a/src/main/resources/theme/rciam-group/email/messages/messages_en.properties +++ b/src/main/resources/theme/rciam-group/email/messages/messages_en.properties @@ -27,9 +27,9 @@ groupadminEnrollmentRequestCreationSubject= New enrollment request for {0} group groupInvitationBody=You have been invited by {0} to join the {1} group.\n{2}\n{3}\nThe group path is {4}\nPlease follow the following link: {5}\n\nPlease note that this invitation will {6}.\n\nThank you,\n{7} groupInvitationBodyHtml=

You have been invited by {0} to join the {1} group.

{2}

{3}

The group path is {4}

Join this group

You can also click the following link: {7}

Please note that this invitation will {8}.

Thank you,
{9}

groupInvitationSubject= Invitation to join group {0} -groupInvitationAdminInformBody=Dear {0},\n\n User with email {1} has been invited to become {2} of the group {3} by {4} group admin.\n\nThank you,\n{5} -groupInvitationAdminInformBodyHtml=

Dear {0},

User with email {1} has been invited to become {2} of the group {3} by {4} group admin.

Thank you,
{5}

-groupInvitationAdminInformSubject= Group admin invitation +groupInvitationAdminInformBody=Dear {0},\n\n User with email {1} has been invited by {2} to become {3} of the group {4}.\n\nThank you,\n{5} +groupInvitationAdminInformBodyHtml=

Dear {0},

User with email {1} has been invited by {2} to become {3} of the group {4}.

Thank you,
{5}

+groupInvitationAdminInformSubject= Administrator invitation for group {0} groupAcceptInvitationBody=Dear {0},\n\n {1} with email {2} has accepted an invitation to {3} the {4}.\n\nFor more information about the group, please visit the following link: \n{5}\n\nThank you,\n{6} groupAcceptInvitationBodyHtml=

Dear {0},

{1} with email {2} has accepted an invitation to {3} the {4}

For more information about the group, please visit the following link:
{5}

Thank you,
{6}

groupRejectionInvitationBody=Dear {0},\n\n {1} with email {2} has rejected an invitation to {3} the {4}.\n\nFor more information about the group, please visit the following link:\n {5}\n\nThank you,\n{6} diff --git a/src/main/resources/theme/rciam-group/email/text/invitation-admin-inform.ftl b/src/main/resources/theme/rciam-group/email/text/invitation-admin-inform.ftl index dd5bc528..a4dfa7bd 100644 --- a/src/main/resources/theme/rciam-group/email/text/invitation-admin-inform.ftl +++ b/src/main/resources/theme/rciam-group/email/text/invitation-admin-inform.ftl @@ -1,2 +1,2 @@ <#ftl output_format="plainText"> -${msg("groupInvitationAdminInformBody",fullname, email, type, groupname, adminFullName, signatureMessage)} \ No newline at end of file +${msg("groupInvitationAdminInformBody",fullname, email, adminFullName, type, groupPath, signatureMessage)} \ No newline at end of file