|
6 | 6 | import invite.config.HashGenerator; |
7 | 7 | import invite.exception.InvalidInputException; |
8 | 8 | import invite.exception.NotFoundException; |
| 9 | +import invite.logging.AccessLogger; |
| 10 | +import invite.logging.Event; |
9 | 11 | import invite.mail.MailBox; |
10 | 12 | import invite.manage.EntityType; |
11 | 13 | import invite.manage.Manage; |
|
50 | 52 | import org.springframework.web.bind.annotation.RestController; |
51 | 53 |
|
52 | 54 | import java.io.IOException; |
| 55 | +import java.time.Instant; |
| 56 | +import java.time.LocalDateTime; |
| 57 | +import java.time.Period; |
| 58 | +import java.time.format.DateTimeFormatter; |
53 | 59 | import java.util.Collections; |
54 | 60 | import java.util.List; |
55 | 61 | import java.util.Map; |
@@ -276,6 +282,34 @@ public ResponseEntity<Map<String, ConnectionStatusResponse>> connectionStatus(@R |
276 | 282 | } |
277 | 283 | } |
278 | 284 |
|
| 285 | + @PostMapping(value = "/crm/api/v1/invite/resend", produces = MediaType.APPLICATION_JSON_VALUE) |
| 286 | + @Operation(summary = "Resend an invitation", |
| 287 | + description = "Resend an invitation based on the CRM OrganisationID and CRM ContactID") |
| 288 | + @SecurityRequirement(name = API_HEADER_SCHEME_NAME) |
| 289 | + @PreAuthorize("hasRole('CRM')") |
| 290 | + public ResponseEntity<ResendInvitationResponse> resendInvitation(@RequestBody ResendInvitation resendInvitation) { |
| 291 | + List<Invitation> invitations = invitationRepository.findByCrmContactIdAndCrmOrganisationId(resendInvitation.crmContatcId(), |
| 292 | + resendInvitation.crmOrganisationId()); |
| 293 | + invitations.forEach(invitation -> { |
| 294 | + List<Role> requestedRoles = invitation.getRoles().stream() |
| 295 | + .map(InvitationRole::getRole).toList(); |
| 296 | + List<GroupedProviders> groupedProviders = manage.getGroupedProviders(requestedRoles); |
| 297 | + |
| 298 | + mailBox.sendInviteMail(provisionable, |
| 299 | + invitation, |
| 300 | + groupedProviders, |
| 301 | + invitation.getLanguage(), |
| 302 | + Optional.empty()); |
| 303 | + invitation.setExpiryDate(Instant.now().plus(Period.ofDays(14))); |
| 304 | + invitationRepository.save(invitation); |
| 305 | + |
| 306 | + AccessLogger.invitation(LOG, Event.Resend, invitation); |
| 307 | + |
| 308 | + }); |
| 309 | + String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")); |
| 310 | + return ResponseEntity.ok(new ResendInvitationResponse(timestamp, 200, "ok", "Resend invitation")); |
| 311 | + } |
| 312 | + |
279 | 313 | private ProfileResponse crmUserNotFoundOrNoRoles() { |
280 | 314 | return new ProfileResponse("Could not find any profiles with the given search parameters", 50, List.of()); |
281 | 315 | } |
|
0 commit comments