Skip to content

Commit

Permalink
Avoid dublicate roles correct update user email
Browse files Browse the repository at this point in the history
  • Loading branch information
cgeorgilakis-grnet committed Feb 17, 2025
1 parent b3145ab commit a476f1b
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 66 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes in keycloak-group-management will be documented in this file
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.5.2] - 2025-02-17

### Fixed
- Avoid dublicate roles
- Correct update user email

## [1.5.1] - 2025-02-14

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<quarkus.version>3.2.7.Final</quarkus.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<agm-version>1.5.1</agm-version>
<agm-version>1.5.2</agm-version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -181,7 +182,7 @@ public void sendAcceptRejectEnrollmentAdminInfoEmail(boolean isAccepted, UserMod
send(isAccepted ? "acceptEnrollmentAdminInfoSubject" : "rejectEnrollmentAdminInfoSubject", Stream.of(groupPath).collect(Collectors.toList()), "accept-reject-enrollment-admin-info.ftl", attributes);
}

public void sendGroupAdminEnrollmentCreationEmail(UserModel userRequest, String groupPath, List<String> groupRoles, String reason, String enrollmentId) throws EmailException {
public void sendGroupAdminEnrollmentCreationEmail(UserModel userRequest, String groupPath, Set<String> groupRoles, String reason, String enrollmentId) throws EmailException {
attributes.put("fullname", user.getFirstName() + " " + user.getLastName());
attributes.put("userName", userRequest.getFirstName() + " " + userRequest.getLastName());
if (groupRoles != null && !groupRoles.isEmpty()) {
Expand Down Expand Up @@ -233,7 +234,7 @@ public void sendExpiredGroupMembershipNotification(String groupPath, String date
send("groupMembershipExpirationNotificationSubject", Stream.of(groupPath).collect(Collectors.toList()), "group-membership-expiration-notification.ftl", attributes);
}

public void sendGroupInvitationEmail(UserModel groupadmin, String groupName, String groupPath, String description, List<String> groupRoles, String id, Long invitationExpirationHour) throws EmailException {
public void sendGroupInvitationEmail(UserModel groupadmin, String groupName, String groupPath, String description, Set<String> groupRoles, String id, Long invitationExpirationHour) throws EmailException {
attributes.put("groupadmin", groupadmin.getFirstName() + " " + groupadmin.getLastName());
attributes.put("groupName", groupName);
attributes.put("groupPath", groupPath);
Expand All @@ -260,7 +261,7 @@ public void sendGroupInvitationEmail(UserModel groupadmin, String groupName, Str
send("groupInvitationSubject", Stream.of(groupPath).collect(Collectors.toList()), "user-group-invitation.ftl", attributes);
}

public void sendAcceptInvitationEmail(UserModel userModel, String groupPath, String groupId, boolean forMember, List<String> groupRoles) throws EmailException {
public void sendAcceptInvitationEmail(UserModel userModel, String groupPath, String groupId, boolean forMember, Set<String> groupRoles) throws EmailException {
attributes.put("fullname", user.getFirstName() + " " + user.getLastName());
attributes.put("userfullname", userModel.getFirstName() + " " + userModel.getLastName());
attributes.put("email", userModel.getEmail());
Expand All @@ -287,7 +288,7 @@ public void sendAcceptInvitationEmail(UserModel userModel, String groupPath, Str
send("groupAcceptInvitationSubject", Stream.of(titleType, groupPath).collect(Collectors.toList()), "accept-invitation.ftl", attributes);
}

public void sendRejectionInvitationEmail(UserModel userModel, String groupPath, String groupId, boolean forMember, List<String> groupRoles) throws EmailException {
public void sendRejectionInvitationEmail(UserModel userModel, String groupPath, String groupId, boolean forMember, Set<String> groupRoles) throws EmailException {
attributes.put("fullname", user.getFirstName() + " " + user.getLastName());
attributes.put("userfullname", userModel.getFirstName() + " " + userModel.getLastName());
attributes.put("email", userModel.getEmail());
Expand All @@ -314,7 +315,7 @@ 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 groupPath, UserModel admin, List<String> groupRoles) throws EmailException {
public void sendInvitionAdminInformationEmail(String email, boolean forMember, String groupPath, UserModel admin, Set<String> groupRoles) throws EmailException {
attributes.put("fullname", user.getFirstName() + " " + user.getLastName());
attributes.put("email", email);
attributes.put("type", forMember ? "a member" : "an administrator");
Expand Down Expand Up @@ -342,7 +343,7 @@ public void sendAddRemoveAdminAdminInformationEmail(boolean added, String groupP
send(added ? "addGroupAdminAdminInformationSubject" : "removeGroupAdminAdminInformationSubject", Stream.of(groupPath).collect(Collectors.toList()), "add-remove-groupadmin-admin-inform.ftl", attributes);
}

public void sendMemberUpdateAdminInformEmail(String groupPath, UserModel userChanged, UserModel admin, LocalDate validFrom, LocalDate membershipExpiresAt, List<String> roles) throws EmailException {
public void sendMemberUpdateAdminInformEmail(String groupPath, UserModel userChanged, UserModel admin, LocalDate validFrom, LocalDate membershipExpiresAt, Set<String> roles) throws EmailException {
attributes.put("fullname", user.getFirstName() + " " + user.getLastName());
attributes.put("groupPath", groupPath);
attributes.put("userFullName", userChanged.getFirstName() + " " + userChanged.getLastName());
Expand All @@ -354,7 +355,7 @@ public void sendMemberUpdateAdminInformEmail(String groupPath, UserModel userCha
send("memberUpdateAdminInformSubject", Stream.of(groupPath).collect(Collectors.toList()),"member-update-admin-inform.ftl", attributes);
}

public void sendMemberUpdateUserInformEmail(String groupPath, UserModel admin, LocalDate validFrom, LocalDate membershipExpiresAt, List<String> roles) throws EmailException {
public void sendMemberUpdateUserInformEmail(String groupPath, UserModel admin, LocalDate validFrom, LocalDate membershipExpiresAt, Set<String> roles) throws EmailException {
attributes.put("fullname", user.getFirstName() + " " + user.getLastName());
attributes.put("groupPath", groupPath);
attributes.put("adminFullName", admin.getFirstName() + " " + admin.getLastName());
Expand All @@ -376,7 +377,7 @@ public void sendMemberCreateAdminInformEmail(String groupId, String groupPath, U
send("memberCreateAdminInformSubject", Stream.of(groupPath).collect(Collectors.toList()),"member-create-admin-inform.ftl", attributes);
}

public void sendMemberCreateUserInformEmail(String groupId, String groupPath, UserModel admin, LocalDate validFrom, LocalDate membershipExpiresAt, List<String> roles) throws EmailException {
public void sendMemberCreateUserInformEmail(String groupId, String groupPath, UserModel admin, LocalDate validFrom, LocalDate membershipExpiresAt, Set<String> roles) throws EmailException {
attributes.put("fullname", user.getFirstName() + " " + user.getLastName());
attributes.put("groupPath", groupPath);
attributes.put("adminFullName", admin.getFirstName() + " " + admin.getLastName());
Expand All @@ -397,7 +398,7 @@ public void sendDeleteGroupAdminInformationEmail(String groupPath, UserModel adm
send("deleteGroupAdminInformationSubject", Stream.of(groupPath).collect(Collectors.toList()), "delete-group-admin-inform.ftl", attributes);
}

public void sendRolesChangesUserEmail(String groupPath, List<String> roles) throws EmailException {
public void sendRolesChangesUserEmail(String groupPath, Set<String> roles) throws EmailException {
attributes.put("fullname", user.getFirstName() + " " + user.getLastName());
attributes.put("groupPath", groupPath);
attributes.put("roles", roles.stream().collect(Collectors.joining(",")));
Expand All @@ -406,7 +407,7 @@ public void sendRolesChangesUserEmail(String groupPath, List<String> roles) thro
send("rolesChangesUserSubject", "roles-changes-user.ftl", attributes);
}

public void sendRolesChangesGroupAdminEmail(String groupPath, List<String> roles, UserModel admin, UserModel userChanged) throws EmailException {
public void sendRolesChangesGroupAdminEmail(String groupPath, Set<String> roles, UserModel admin, UserModel userChanged) throws EmailException {
attributes.put("fullname", user.getFirstName() + " " + user.getLastName());
attributes.put("groupPath", groupPath);
attributes.put("roles", roles.stream().collect(Collectors.joining(",")));
Expand Down Expand Up @@ -468,7 +469,7 @@ private String subgroupsStrCalculation(List<String> subgroupsPaths) {
return StringUtils.removeEnd(sb.toString(), comma);
}

private String rolesHtmlStrCalculation(List<String> roles) {
private String rolesHtmlStrCalculation(Set<String> roles) {
if (roles.isEmpty())
return "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static GroupEnrollmentConfigurationRepresentation toRepresentation(GroupE
if (entity.getAupEntity() != null)
rep.setAup(toRepresentation(entity.getAupEntity()));
if (entity.getGroupRoles() != null)
rep.setGroupRoles(entity.getGroupRoles().stream().map(GroupRolesEntity::getName).collect(Collectors.toList()));
rep.setGroupRoles(entity.getGroupRoles().stream().map(GroupRolesEntity::getName).collect(Collectors.toSet()));
rep.setCommentsNeeded(entity.getCommentsNeeded());
if (rep.getCommentsNeeded()) {
rep.setCommentsLabel(entity.getCommentsLabel());
Expand Down Expand Up @@ -78,7 +78,7 @@ public static UserGroupMembershipExtensionRepresentation toRepresentation(UserGr
rep.setValidFrom(entity.getValidFrom());
rep.setStatus(entity.getStatus());
if (entity.getGroupRoles() != null)
rep.setGroupRoles(entity.getGroupRoles().stream().map(GroupRolesEntity::getName).collect(Collectors.toList()));
rep.setGroupRoles(entity.getGroupRoles().stream().map(GroupRolesEntity::getName).collect(Collectors.toSet()));
return rep;
}

Expand Down Expand Up @@ -116,7 +116,7 @@ public static GroupEnrollmentRequestRepresentation toRepresentation(GroupEnrollm
rep.setSubmittedDate(entity.getSubmittedDate());
rep.setApprovedDate(entity.getApprovedDate());
if (entity.getGroupRoles() != null)
rep.setGroupRoles(entity.getGroupRoles().stream().map(GroupRolesEntity::getName).collect(Collectors.toList()));
rep.setGroupRoles(entity.getGroupRoles().stream().map(GroupRolesEntity::getName).collect(Collectors.toSet()));
return rep;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.rciam.plugins.groups.helpers;

import java.time.LocalDate;
import java.util.List;
import java.util.Set;

import org.keycloak.common.ClientConnection;
import org.keycloak.events.EventBuilder;
Expand All @@ -13,7 +13,7 @@

public class LoginEventHelper {

public static void createGroupEvent(RealmModel realm, KeycloakSession session, ClientConnection clientConnection, UserModel user, String actionUserId, String eventType, String groupPath, List<String> groupRolesNames, LocalDate expirationDate){
public static void createGroupEvent(RealmModel realm, KeycloakSession session, ClientConnection clientConnection, UserModel user, String actionUserId, String eventType, String groupPath, Set<String> groupRolesNames, LocalDate expirationDate){
EventBuilder event = new EventBuilder(realm, session, clientConnection)
.event(EventType.valueOf(eventType))
.user(user)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.rciam.plugins.groups.jpa.entities;

import java.time.LocalDate;
import java.util.List;
import java.util.Set;

import jakarta.persistence.*;
import org.keycloak.models.jpa.entities.GroupEntity;
Expand Down Expand Up @@ -79,7 +79,7 @@ public class GroupEnrollmentConfigurationEntity {

@ManyToMany
@JoinTable(name = "GROUP_ENROLLMENT_CONFIGURATION_ROLES", joinColumns = @JoinColumn(name = "GROUP_ENROLLMENT_CONFIGURATION_ID"), inverseJoinColumns = @JoinColumn(name = "GROUP_ROLES_ID"))
private List<GroupRolesEntity> groupRoles;
private Set<GroupRolesEntity> groupRoles;

public String getName() {
return name;
Expand Down Expand Up @@ -193,11 +193,11 @@ public void setVisibleToNotMembers(Boolean visibleToNotMembers) {
this.visibleToNotMembers = visibleToNotMembers;
}

public List<GroupRolesEntity> getGroupRoles() {
public Set<GroupRolesEntity> getGroupRoles() {
return groupRoles;
}

public void setGroupRoles(List<GroupRolesEntity> groupRoles) {
public void setGroupRoles(Set<GroupRolesEntity> groupRoles) {
this.groupRoles = groupRoles;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.rciam.plugins.groups.jpa.entities;

import java.time.LocalDate;
import java.util.List;
import java.util.Set;

import org.keycloak.models.jpa.entities.GroupEntity;
import org.keycloak.models.jpa.entities.UserEntity;
Expand Down Expand Up @@ -85,7 +85,7 @@ public class UserGroupMembershipExtensionEntity {

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "GROUP_MEMBERSHIP_ROLES", joinColumns = @JoinColumn(name = "USER_GROUP_MEMBERSHIP_EXTENSION_ID"), inverseJoinColumns = @JoinColumn(name = "GROUP_ROLES_ID"))
private List<GroupRolesEntity> groupRoles;
private Set<GroupRolesEntity> groupRoles;

public String getId() {
return id;
Expand Down Expand Up @@ -175,11 +175,11 @@ public void setGroupEnrollmentConfigurationId(String groupEnrollmentConfiguratio
this.groupEnrollmentConfigurationId = groupEnrollmentConfigurationId;
}

public List<GroupRolesEntity> getGroupRoles() {
public Set<GroupRolesEntity> getGroupRoles() {
return groupRoles;
}

public void setGroupRoles(List<GroupRolesEntity> groupRoles) {
public void setGroupRoles(Set<GroupRolesEntity> groupRoles) {
this.groupRoles = groupRoles;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void createDefault(GroupModel group, String groupName, String realmId) {
r.setGroup(x.getGroup());
r.setName(x.getName());
return r;
}).collect(Collectors.toList()));
}).collect(Collectors.toSet()));
entity.setCommentsNeeded(configurationRulesList.stream().noneMatch(x -> "commentsNeeded".equals(x.getField()) && "false".equals(x.getDefaultValue())) );
if (entity.getCommentsNeeded()) {
String label = configurationRulesList.stream().filter(x -> "commentsLabel".equals(x.getField())).findAny().orElse(new GroupEnrollmentConfigurationRulesEntity()).getDefaultValue();
Expand Down Expand Up @@ -142,7 +142,7 @@ private void toEntity(GroupEnrollmentConfigurationEntity entity, GroupEnrollment
} else {
return null;
}
}).filter(Objects::nonNull).collect(Collectors.toList()));
}).filter(Objects::nonNull).collect(Collectors.toSet()));
} else {
entity.setGroupRoles(null);
}
Expand Down
Loading

0 comments on commit a476f1b

Please sign in to comment.