Skip to content

Commit

Permalink
Emails when removing user from group
Browse files Browse the repository at this point in the history
  • Loading branch information
cgeorgilakis-grnet committed Dec 24, 2024
1 parent e39ab36 commit c31c9dc
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Rules for user manage-groups-extended for update membership

### Added
- Emails when removing user from group

## [1.1.1] - 2024-12-20

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class CustomFreeMarkerEmailTemplateProvider extends FreeMarkerEmailTempla

//must be changed to a ui ( account console url)
private static final String enrollmentUrl = "realms/{realmName}/account/#/groups/groupenrollments?id={id}";
private static final String SHOW_GROUPS_URL = "realms/{realmName}/account/#/groups/showgroups";
private static final String MEMBER_URL = "realms/{realmName}/account/#/groups/showgroups/{id}";
private static final String enrollmentStartUrl = "/realms/{realmName}/account/#/enroll?groupPath={path}";
private static final String finishGroupInvitation = "realms/{realmName}/account/#/invitation/{id}";
Expand Down Expand Up @@ -416,6 +417,27 @@ public void sendRolesChangesGroupAdminEmail(String groupPath, List<String> roles
send("rolesChangesGroupAdminSubject", Stream.of(groupPath).collect(Collectors.toList()), "roles-changes-group-admin.ftl", attributes);
}

public void sendRemoveMemberEmail(String groupPath, UserModel admin) throws EmailException {
attributes.put("fullname", user.getFirstName() + " " + user.getLastName());
attributes.put("groupPath", groupPath);
attributes.put("adminFullName", admin.getFirstName() + " " + admin.getLastName());
String groupUrl = session.getContext().getUri().getBaseUri().toString() + SHOW_GROUPS_URL ;
attributes.put("groupsUrl", groupUrl.replace("{realmName}", realm.getName()));
attributes.put("signatureMessage", signatureMessage);
send("removeMemberSubject", Stream.of(groupPath).collect(Collectors.toList()),"remove-member-inform.ftl", attributes);
}

public void sendRemoveMemberAdminInformationEmail(String groupId, String groupPath, UserModel admin, UserModel userChanged) throws EmailException {
attributes.put("fullname", user.getFirstName() + " " + user.getLastName());
attributes.put("groupPath", groupPath);
attributes.put("userFullName", userChanged.getFirstName() + " " + userChanged.getLastName());
attributes.put("adminFullName", admin.getFirstName() + " " + admin.getLastName());
String memberUrl = session.getContext().getUri().getBaseUri().toString() + membersGroupPageUrl ;
attributes.put("groupUrl", memberUrl.replace("{realmName}", realm.getName()).replace("{id}", groupId));
attributes.put("signatureMessage", signatureMessage);
send("removeMemberAdminInformationSubject", Stream.of(groupPath).collect(Collectors.toList()), "remove-member-admin-inform.ftl", attributes);
}

private String subgroupsHtmlStrCalculation(List<String> subgroupsPaths) {
if (subgroupsPaths.isEmpty())
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,25 @@ public Response updateMember(UserGroupMembershipExtensionRepresentation rep) thr
public Response deleteMember() {
UserModel user = session.users().getUserById(realm, member.getUser().getId());
MemberUserAttributeConfigurationEntity memberUserAttribute = memberUserAttributeConfigurationRepository.getByRealm(realm.getId());
String groupPath = ModelToRepresentation.buildGroupPath(group);
userGroupMembershipExtensionRepository.deleteMember(member, group, user, clientConnection, groupAdmin.getAttributeStream(Utils.VO_PERSON_ID).findAny().orElse(groupAdmin.getId()), memberUserAttribute, false);

try {
customFreeMarkerEmailTemplateProvider.setUser(user);
customFreeMarkerEmailTemplateProvider.sendRemoveMemberEmail(groupPath, groupAdmin);

groupAdminRepository.getAllAdminIdsGroupUsers(group).filter(x -> !groupAdmin.getId().equals(x)).map(id -> session.users().getUserById(realm, id)).forEach(admin -> {
try {
customFreeMarkerEmailTemplateProvider.setUser(admin);
customFreeMarkerEmailTemplateProvider.sendRemoveMemberAdminInformationEmail(group.getId(), groupPath, groupAdmin, user);
} catch (EmailException e) {
ServicesLogger.LOGGER.failedToSendEmail(e);
}
});
} catch (EmailException e) {
ServicesLogger.LOGGER.failedToSendEmail(e);
}

return Response.noContent().build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
${kcSanitize(msg("removeMemberAdminInformationBodyHtml", fullname, adminFullName, userFullName, groupPath, groupUrl, signatureMessage))?no_esc}
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
${kcSanitize(msg("removeMemberBodyHtml", fullname, groupPath, adminFullName, groupsUrl, signatureMessage))?no_esc}
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,9 @@ rolesChangesUserBodyHtml=<p>Dear {0},</p><p>Your roles in the {1} group has been
rolesChangesGroupAdminSubject= Group Admin Notification for {0}: Roles Updated
rolesChangesGroupAdminBody=Dear {0},\n\nThis is to inform you that the group administrator,{1}, has updated the roles of member {2} in the {3} group. The new roles assigned are: {4}\n\nThank you,\n{5}
rolesChangesGroupAdminBodyHtml=<p>Dear {0},</p><p>This is to inform you that the group administrator,<b>{1}</b>, has updated the roles of member {2} in the {3} group. The new roles assigned are: {4}</p><p>Thank you,<br>{5}</p>
removeMemberBody= Dear {0},\n\nThis is to inform you that you have been removed from the {1} group by {2}.\n\nYou can still access your account and review your other group memberships here::\n {3}\n\nThank you,\n{4}
removeMemberBodyHtml= <p>Dear {0},</p><p>This is to inform you that you have been removed from the <b>{1}</b> group by {2}.</p><p>You can still access your account and review your other group memberships here: <br>{3}</p><p>Thank you,<br>{4}</p>
removeMemberSubject= Notification of Removal from the {0}: Group
removeMemberAdminInformationBody= Dear {0},\n\nThis is to inform you that {1}, the group administrator, has removed {2} from the {3} group.\n\nFor more information about the group, please visit the following link:\n {5}\n\nThank you,\n{6}
removeMemberAdminInformationBodyHtml= <p>Dear {0},</p><p>This is to inform you that <b>{1}</b>, the group administrator, has removed <b>{2}</b> from the <b>{3}</b> group.</p><p>For more information about the group, please visit the following link: <br>{4}</p><p>Thank you,<br>{5}</p>
removeMemberAdminInformationSubject= Member Remove from the {0}: Group
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<#ftl output_format="plainText">
${msg("removeMemberBody", fullname, groupPath, adminFullName, groupsUrl, signatureMessage)}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<#ftl output_format="plainText">
${msg("removeMemberAdminInformationBody", fullname, adminFullName, userFullName, groupPath, groupUrl, signatureMessage)}

0 comments on commit c31c9dc

Please sign in to comment.