Skip to content

Commit 3225573

Browse files
committed
Support for suppressInvitation in dry-run
1 parent 562a279 commit 3225573

File tree

2 files changed

+40
-28
lines changed

2 files changed

+40
-28
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,9 @@ public ResponseEntity<String> contact(@RequestBody CRMContact crmContact) {
121121

122122
boolean created;
123123

124-
if (crmContact.isSuppressInvitation()) {
125-
if (!StringUtils.hasText(crmContact.getSchacHomeOrganisation()) || !StringUtils.hasText(crmContact.getUid())) {
126-
throw new InvalidInputException(
127-
"Missing schacHomeOrganisation or uid in crmContact with isSuppressInvitation true: " + crmContact);
128-
}
129-
created = provisionUser(crmContact);
124+
if (crmContact.isSuppressInvitation() &&
125+
StringUtils.hasText(crmContact.getSchacHomeOrganisation()) && StringUtils.hasText(crmContact.getUid())) {
126+
created = provisionUser(crmContact);
130127
} else {
131128
created = sendInvitation(crmContact);
132129
}
@@ -251,11 +248,14 @@ private boolean sendInvitation(CRMContact crmContact) {
251248
Invitation invitation = createInvitation(crmContact, invitationRoles);
252249

253250
Optional<String> idpName = identityProviderName(manage, invitation);
254-
255-
LOG.debug(String.format("Sending invitation to user %s for roles %s",
256-
invitation.getEmail(), roles.stream().map(Role::getName).collect(Collectors.joining(","))));
257-
258-
mailBox.sendInviteMail(this.provisionable, invitation, groupedProviders, Language.en, idpName);
251+
if (crmContact.isSuppressInvitation()) {
252+
LOG.debug(String.format("Not actualy sending invitation to user %s for roles %s, because suppressInvitation is set to true",
253+
invitation.getEmail(), roles.stream().map(Role::getName).collect(Collectors.joining(","))));
254+
} else {
255+
LOG.debug(String.format("Sending invitation to user %s for roles %s",
256+
invitation.getEmail(), roles.stream().map(Role::getName).collect(Collectors.joining(","))));
257+
mailBox.sendInviteMail(this.provisionable, invitation, groupedProviders, Language.en, idpName);
258+
}
259259
}
260260
return optionalUser.isEmpty();
261261
}

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

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,6 @@ void contactProvisioningExistingUser() throws JsonProcessingException {
114114
assertEquals(Authority.GUEST, userRole.getAuthority());
115115
}
116116

117-
@Test
118-
void contactProvisioningMissingUID() {
119-
CRMRole crmRole = new CRMRole("roleId", "BVW", "Super");
120-
//Empty uid will force the InvalidInputException
121-
CRMContact crmContact = createCrmContact(CRM_CONTACT_ID, CRM_ORGANIZATION_ID, crmRole, "", "hardewijk.org", true);
122-
123-
given()
124-
.when()
125-
.accept(ContentType.JSON)
126-
.header(API_KEY_HEADER, "secret")
127-
.contentType(ContentType.JSON)
128-
.body(crmContact)
129-
.post("/api/internal/v1/crm")
130-
.then()
131-
.statusCode(HttpStatus.BAD_REQUEST.value());
132-
}
133-
134117
@Test
135118
void contactInviteNewUser() throws Exception {
136119
CRMRole crmRole = new CRMRole("roleId", "BVW", "Super");
@@ -187,6 +170,35 @@ void contactInviteNewUser() throws Exception {
187170
}
188171

189172
@Test
173+
void contactInviteNewUserSuppressEmail() throws Exception {
174+
CRMRole crmRole = new CRMRole("roleId", "BVW", "Super");
175+
String crmContactID = UUID.randomUUID().toString();
176+
String crmOrganisationID = UUID.randomUUID().toString();
177+
CRMContact crmContact = createCrmContact(crmContactID, crmOrganisationID, crmRole, null, null, true);
178+
//These two applications are linked to the 'BVW' CRM role
179+
super.stubForManageProviderByEntityID(EntityType.OIDC10_RP, "https://calendar");
180+
super.stubForManageProviderByEntityID(EntityType.SAML20_SP, "https://storage");
181+
182+
String response = given()
183+
.when()
184+
.accept(ContentType.JSON)
185+
.header(API_KEY_HEADER, "secret")
186+
.contentType(ContentType.JSON)
187+
.body(crmContact)
188+
.post("/api/internal/v1/crm")
189+
.then()
190+
.extract()
191+
.asString();
192+
assertEquals("created", response);
193+
194+
Optional<User> optionalUser = userRepository.findByCrmContactIdAndCrmOrganisationId(crmContactID,
195+
crmOrganisationID);
196+
assertTrue(optionalUser.isEmpty());
197+
198+
List<MimeMessageParser> allMailMessages = allMailMessages(0);
199+
assertEquals(0, allMailMessages.size());
200+
}
201+
@Test
190202
void contactProvisioningRemoveScimRole() throws JsonProcessingException {
191203
CRMRole crmRoleResearch = new CRMRole("5e17b508-08e4-e811-8100-005056956c1a", "CONBEH", "SURFconextbeheerder");
192204
CRMRole crmRoleCloud = new CRMRole("cf652619-08e4-e811-8100-005056956c1a", "CONVER", "SURFconextverantwoordelijke");

0 commit comments

Comments
 (0)