Skip to content

Commit 4fc6e78

Browse files
committed
Fixes #747
1 parent 4b5b125 commit 4fc6e78

8 files changed

Lines changed: 79 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ 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+
12+
## 1.1.13
13+
14+
- Added SuperUser endpoint to fix the missing landing pages in Application Usages
15+
816
## 1.1.12
917

1018
- Fix: Add CRM info to existing Invite users

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.13</version>
7+
<version>1.1.14</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.13</version>
6+
<version>1.1.14</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.13</version>
7+
<version>1.1.14</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.13</version>
7+
<version>1.1.14</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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import jakarta.mail.Address;
2020
import org.junit.jupiter.api.Test;
2121
import org.springframework.http.HttpStatus;
22+
import org.springframework.util.StringUtils;
2223

2324
import java.time.Instant;
2425
import java.time.temporal.ChronoUnit;
@@ -439,6 +440,9 @@ void deleteUser() throws JsonProcessingException {
439440
super.remoteProvisionedGroupRepository.save(remoteProvisionedGroup);
440441

441442
User user = userRepository.findBySubIgnoreCase(KB_USER_SUB).get();
443+
user.getUserRoles().removeIf(userRole -> !StringUtils.hasText(userRole.getRole().getCrmRoleId()));
444+
userRepository.save(user);
445+
442446
RemoteProvisionedUser remoteProvisionedUser = new RemoteProvisionedUser(user, UUID.randomUUID().toString(), "7");
443447
super.remoteProvisionedUserRepository.save(remoteProvisionedUser);
444448
//Because of the PUT request of the change in the group, all users are fetched and checked if they exists in the remote SCIM
@@ -467,6 +471,47 @@ void deleteUser() throws JsonProcessingException {
467471
assertTrue(optionalUser.isEmpty());
468472
}
469473

474+
@Test
475+
void deleteUserWithNativeInviteRoles() throws JsonProcessingException {
476+
CRMContact crmContact = new CRMContact();
477+
crmContact.setContactId(CRM_CONTACT_ID);
478+
crmContact.setOrganisation(new CRMOrganisation(CRM_ORGANIZATION_ID, "abbr", "name"));
479+
480+
stubForManageProvisioning(List.of("5"));
481+
Role role = roleRepository.findByName("Research").get();
482+
RemoteProvisionedGroup remoteProvisionedGroup = new RemoteProvisionedGroup(role, UUID.randomUUID().toString(), "7");
483+
super.remoteProvisionedGroupRepository.save(remoteProvisionedGroup);
484+
485+
User user = userRepository.findBySubIgnoreCase(KB_USER_SUB).get();
486+
RemoteProvisionedUser remoteProvisionedUser = new RemoteProvisionedUser(user, UUID.randomUUID().toString(), "7");
487+
super.remoteProvisionedUserRepository.save(remoteProvisionedUser);
488+
//Because of the PUT request of the change in the group, all users are fetched and checked if they exists in the remote SCIM
489+
User guestUser = userRepository.findBySubIgnoreCase(GUEST_SUB).get();
490+
RemoteProvisionedUser remoteProvisionedUserGuest = new RemoteProvisionedUser(guestUser, UUID.randomUUID().toString(), "7");
491+
super.remoteProvisionedUserRepository.save(remoteProvisionedUserGuest);
492+
493+
stubForUpdateScimRole();
494+
stubForDeleteScimUser();
495+
496+
String response = given()
497+
.when()
498+
.accept(ContentType.JSON)
499+
.header(API_KEY_HEADER, "secret")
500+
.contentType(ContentType.JSON)
501+
.body(crmContact)
502+
.delete("/crm/profile")
503+
.then()
504+
.extract()
505+
.asString();
506+
assertEquals("deleted", response);
507+
508+
Organisation organisation = organisationRepository.findByCrmOrganisationId(CRM_ORGANIZATION_ID)
509+
.orElseThrow(() -> new NotFoundException("Organisation not found: " + CRM_ORGANIZATION_ID));
510+
Optional<User> optionalUser = userRepository.findByCrmContactIdAndOrganisation(CRM_CONTACT_ID, organisation);
511+
assertFalse(optionalUser.isEmpty());
512+
assertEquals(1, optionalUser.get().getUserRoles().size());
513+
}
514+
470515
@Test
471516
void scopeInviteRoleToUniqueCRMRoleIdAndOrganizationId() throws JsonProcessingException {
472517
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.13</version>
7+
<version>1.1.14</version>
88
<relativePath>../pom.xml</relativePath>
99
</parent>
1010
<artifactId>invite-welcome</artifactId>

0 commit comments

Comments
 (0)