Skip to content

Commit 5f878a8

Browse files
committed
Fixes #747
1 parent 13d919c commit 5f878a8

8 files changed

Lines changed: 74 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## 1.1.14
9+
10+
- Only delete User in CRM Delete endpoint, if there are no native Invite roles anymore for this user
11+
812
## 1.1.13
913

1014
- Added SuperUser endpoint to fix the missing landing pages in Application Usages

client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.openconext</groupId>
66
<artifactId>invite</artifactId>
7-
<version>1.1.14-SNAPSHOT</version>
7+
<version>1.1.15-SNAPSHOT</version>
88
<relativePath>../pom.xml</relativePath>
99
</parent>
1010
<artifactId>invite-client</artifactId>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.openconext</groupId>
55
<artifactId>invite</artifactId>
6-
<version>1.1.14-SNAPSHOT</version>
6+
<version>1.1.15-SNAPSHOT</version>
77
<packaging>pom</packaging>
88
<name>invite</name>
99
<description>SURFconext Invite</description>

provisioning-mock/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.openconext</groupId>
66
<artifactId>invite</artifactId>
7-
<version>1.1.14-SNAPSHOT</version>
7+
<version>1.1.15-SNAPSHOT</version>
88
<relativePath>../pom.xml</relativePath>
99
</parent>
1010
<artifactId>provisioning-mock</artifactId>

server/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.openconext</groupId>
66
<artifactId>invite</artifactId>
7-
<version>1.1.14-SNAPSHOT</version>
7+
<version>1.1.15-SNAPSHOT</version>
88
<relativePath>../pom.xml</relativePath>
99
</parent>
1010
<artifactId>invite-server</artifactId>

server/src/main/java/invite/crm/CRMController.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,27 @@ public ResponseEntity<String> delete(@RequestBody CRMContact crmContact) {
182182
optionalOrganisation
183183
.flatMap(organisation -> userRepository.findByCrmContactIdAndOrganisation(crmContact.getContactId(), organisation))
184184
.ifPresent(user -> {
185-
LOG.debug("Deleting CRM user: " + user.getEmail());
186-
this.provisioningService.deleteUserRequest(user);
187-
this.userRepository.delete(user);
185+
long inviteNativeUserRolesCount = user.getUserRoles().stream()
186+
.filter(userRole -> !StringUtils.hasText(userRole.getRole().getCrmRoleId()))
187+
.count();
188+
if (inviteNativeUserRolesCount == 0L) {
189+
LOG.debug("Deleting CRM user: " + user.getEmail());
190+
this.provisioningService.deleteUserRequest(user);
191+
this.userRepository.delete(user);
192+
} else {
193+
List<UserRole> crmUserRoles = user.getUserRoles().stream()
194+
.filter(userRole -> StringUtils.hasText(userRole.getRole().getCrmRoleId()))
195+
.toList();
196+
197+
LOG.debug("Deleting all CRM roles (but not deleting the user) for user: " + user.getEmail());
198+
crmUserRoles.forEach(crmUserRole -> {
199+
this.userRoleAuditService.logAction(crmUserRole, UserRoleAudit.ActionType.DELETE);
200+
this.provisioningService.deleteUserRoleRequest(crmUserRole);
201+
});
202+
user.getUserRoles().removeIf(userRole -> StringUtils.hasText(userRole.getRole().getCrmRoleId()));
203+
this.userRepository.save(user);
204+
}
205+
188206
});
189207
return ResponseEntity.ok().body("deleted");
190208
}

server/src/test/java/invite/crm/CRMControllerTest.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,9 @@ void deleteUser() throws JsonProcessingException {
445445
super.remoteProvisionedGroupRepository.save(remoteProvisionedGroup);
446446

447447
User user = userRepository.findBySubIgnoreCase(KB_USER_SUB).get();
448+
user.getUserRoles().removeIf(userRole -> !StringUtils.hasText(userRole.getRole().getCrmRoleId()));
449+
userRepository.save(user);
450+
448451
RemoteProvisionedUser remoteProvisionedUser = new RemoteProvisionedUser(user, UUID.randomUUID().toString(), "7");
449452
super.remoteProvisionedUserRepository.save(remoteProvisionedUser);
450453
//Because of the PUT request of the change in the group, all users are fetched and checked if they exists in the remote SCIM
@@ -473,6 +476,47 @@ void deleteUser() throws JsonProcessingException {
473476
assertTrue(optionalUser.isEmpty());
474477
}
475478

479+
@Test
480+
void deleteUserWithNativeInviteRoles() throws JsonProcessingException {
481+
CRMContact crmContact = new CRMContact();
482+
crmContact.setContactId(CRM_CONTACT_ID);
483+
crmContact.setOrganisation(new CRMOrganisation(CRM_ORGANIZATION_ID, "abbr", "name"));
484+
485+
stubForManageProvisioning(List.of("5"));
486+
Role role = roleRepository.findByName("Research").get();
487+
RemoteProvisionedGroup remoteProvisionedGroup = new RemoteProvisionedGroup(role, UUID.randomUUID().toString(), "7");
488+
super.remoteProvisionedGroupRepository.save(remoteProvisionedGroup);
489+
490+
User user = userRepository.findBySubIgnoreCase(KB_USER_SUB).get();
491+
RemoteProvisionedUser remoteProvisionedUser = new RemoteProvisionedUser(user, UUID.randomUUID().toString(), "7");
492+
super.remoteProvisionedUserRepository.save(remoteProvisionedUser);
493+
//Because of the PUT request of the change in the group, all users are fetched and checked if they exists in the remote SCIM
494+
User guestUser = userRepository.findBySubIgnoreCase(GUEST_SUB).get();
495+
RemoteProvisionedUser remoteProvisionedUserGuest = new RemoteProvisionedUser(guestUser, UUID.randomUUID().toString(), "7");
496+
super.remoteProvisionedUserRepository.save(remoteProvisionedUserGuest);
497+
498+
stubForUpdateScimRole();
499+
stubForDeleteScimUser();
500+
501+
String response = given()
502+
.when()
503+
.accept(ContentType.JSON)
504+
.header(API_KEY_HEADER, "secret")
505+
.contentType(ContentType.JSON)
506+
.body(crmContact)
507+
.delete("/crm/profile")
508+
.then()
509+
.extract()
510+
.asString();
511+
assertEquals("deleted", response);
512+
513+
Organisation organisation = organisationRepository.findByCrmOrganisationId(CRM_ORGANIZATION_ID)
514+
.orElseThrow(() -> new NotFoundException("Organisation not found: " + CRM_ORGANIZATION_ID));
515+
Optional<User> optionalUser = userRepository.findByCrmContactIdAndOrganisation(CRM_CONTACT_ID, organisation);
516+
assertFalse(optionalUser.isEmpty());
517+
assertEquals(1, optionalUser.get().getUserRoles().size());
518+
}
519+
476520
@Test
477521
void scopeInviteRoleToUniqueCRMRoleIdAndOrganizationId() throws JsonProcessingException {
478522
String converRoleId = "92b2b379-07e4-e811-8100-005056956c1a";

welcome/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.openconext</groupId>
66
<artifactId>invite</artifactId>
7-
<version>1.1.14-SNAPSHOT</version>
7+
<version>1.1.15-SNAPSHOT</version>
88
<relativePath>../pom.xml</relativePath>
99
</parent>
1010
<artifactId>invite-welcome</artifactId>

0 commit comments

Comments
 (0)