diff --git a/api/uploadservice.yaml b/api/uploadservice.yaml index 9142714..a80d69f 100644 --- a/api/uploadservice.yaml +++ b/api/uploadservice.yaml @@ -105,82 +105,6 @@ paths: description: INTERNAL SERVER ERROR - server encountered unexpected condition security: - Bearer: [] - /uploads/feedback/new/{feedbackRoomId}: - post: - tags: - - upload-controller - summary: 'Upload a file and send a message to to a Rocket.Chat feedback room - [Authorization: authority for feedback chat]' - operationId: uploadFileToFeedbackRoom - parameters: - - name: feedbackRoomId - in: path - description: Rocket.Chat room id - required: true - schema: - type: string - - name: RCToken - in: header - required: true - schema: - type: string - - name: RCUserId - in: header - required: true - schema: - type: string - requestBody: - content: - multipart/form-data: - schema: - required: - - file - - sendNotification - properties: - msg: - type: string - description: A text message - description: - type: string - description: A description of the file - tmId: - type: string - description: The thread message id (if you want upload a file to - a thread) - fileHeader: - type: string - description: Starting bytes of file which includes mimetype for verification - t: - type: string - description: Type of message - example: "e2e" - file: - type: string - description: File to upload - format: binary - sendNotification: - type: string - description: Flag, whether an email notification should be sent - or not (true/false) - required: true - responses: - 201: - description: CREATED - upload was successfully performed - 400: - description: BAD REQUEST - invalid/incomplete request or body object - 401: - description: UNAUTHORIZED - no/invalid Keycloak token - 403: - description: FORBIDDEN - no/invalid role/authorization - 413: - description: REQUEST ENTITY TOO LARGE - Maximum upload size exceeded - 415: - description: UNSUPPORTED MEDIA TYPE - Type of uploaded file is not allowed - 500: - description: INTERNAL SERVER ERROR - server encountered unexpected condition - security: - - Bearer: [] - components: schemas: MasterKeyDto: diff --git a/src/main/java/de/caritas/cob/uploadservice/api/controller/UploadController.java b/src/main/java/de/caritas/cob/uploadservice/api/controller/UploadController.java index 4dd630c..fe5c992 100644 --- a/src/main/java/de/caritas/cob/uploadservice/api/controller/UploadController.java +++ b/src/main/java/de/caritas/cob/uploadservice/api/controller/UploadController.java @@ -10,11 +10,7 @@ import de.caritas.cob.uploadservice.api.service.EncryptionService; import de.caritas.cob.uploadservice.api.service.LogService; import de.caritas.cob.uploadservice.generated.api.controller.UploadsApi; -import io.swagger.annotations.Api; -import java.util.Objects; import javax.validation.Valid; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -105,54 +101,4 @@ public ResponseEntity uploadFileToRoom( return new ResponseEntity<>(HttpStatus.CREATED); } - - /** - * Upload a file to a Rocket.Chat feedback room with a text message. - * - * @param feedbackRoomId Rocket.Chat feedback room id - * @param rcToken Rocket.Chat token - * @param rcUserId Rocket.Chat user id - * @param file The file object as {@link MultipartFile} - * @param sendNotification Flag, whether an email notification should be sent or not - * @param msg The message - * @param description The description - * @param tmId Rocket.Chat thread message id - * @return a ResponseEntity instance - */ - @TempCleanup - @Override - public ResponseEntity uploadFileToFeedbackRoom( - @PathVariable("feedbackRoomId") String feedbackRoomId, - @RequestHeader String rcToken, - @RequestHeader String rcUserId, - @RequestPart MultipartFile file, - @RequestParam String sendNotification, - @RequestPart(required = false) String t, - @RequestPart(required = false) String fileHeader, - @RequestParam(required = false) String msg, - @RequestParam(required = false) String description, - @RequestParam(required = false) String tmId) { - - RocketChatCredentials rocketChatCredentials = - RocketChatCredentials.builder().rocketChatUserId(rcUserId).rocketChatToken(rcToken).build(); - - RocketChatUploadParameter rocketChatUploadParameter = - RocketChatUploadParameter.builder() - .roomId(feedbackRoomId) - .description(description) - .message(msg) - .file(file) - .tmId(tmId) - .build(); - - uploadFacade.uploadFileToFeedbackRoom( - rocketChatCredentials, - rocketChatUploadParameter, - parseBoolean(sendNotification), - t, - fileHeader - ); - - return new ResponseEntity<>(HttpStatus.CREATED); - } } diff --git a/src/main/java/de/caritas/cob/uploadservice/api/facade/EmailNotificationFacade.java b/src/main/java/de/caritas/cob/uploadservice/api/facade/EmailNotificationFacade.java index 1528485..bc8d9b0 100644 --- a/src/main/java/de/caritas/cob/uploadservice/api/facade/EmailNotificationFacade.java +++ b/src/main/java/de/caritas/cob/uploadservice/api/facade/EmailNotificationFacade.java @@ -42,16 +42,4 @@ public void sendEmailNotification(String rcGroupId) { authenticatedUser.getAccessToken(), Optional.ofNullable(TenantContext.getCurrentTenant())); } - - /** - * Sends a new feedback message notification via the UserService (user data needed for sending the - * mail will be read by the UserService, which in turn calls the UploadService). - * - * @param rcGroupId - */ - public void sendFeedbackEmailNotification(String rcGroupId) { - emailNotificationHelper.sendEmailFeedbackNotificationViaUserService( - rcGroupId, - authenticatedUser.getAccessToken(), Optional.ofNullable(TenantContext.getCurrentTenant())); - } } diff --git a/src/main/java/de/caritas/cob/uploadservice/api/facade/UploadFacade.java b/src/main/java/de/caritas/cob/uploadservice/api/facade/UploadFacade.java index 7dbbf78..daf6cb8 100644 --- a/src/main/java/de/caritas/cob/uploadservice/api/facade/UploadFacade.java +++ b/src/main/java/de/caritas/cob/uploadservice/api/facade/UploadFacade.java @@ -88,31 +88,6 @@ private UserRole resolveUserRole(AuthenticatedUser authenticatedUser) { : UserRole.ASKER; } - /** - * Upload a file with a message to a Rocket.Chat feedback room. The message and the description - * are encrypted before it is sent to Rocket.Chat. - * - * @param rocketChatCredentials {@link RocketChatCredentials} container - * @param rocketChatUploadParameter {@link RocketChatUploadParameter} container - */ - public void uploadFileToFeedbackRoom( - RocketChatCredentials rocketChatCredentials, - RocketChatUploadParameter rocketChatUploadParameter, - boolean sendNotification, String type, String fileHeader) { - - this.uploadTrackingService.validateUploadLimit(rocketChatUploadParameter.getRoomId()); - - sanitizeAndEncryptParametersAndUploadToRocketChatRoom( - rocketChatCredentials, rocketChatUploadParameter, type, fileHeader); - this.liveEventNotificationService.sendLiveEvent(rocketChatUploadParameter.getRoomId(), - authenticatedUser.getAccessToken(), TenantContext.getCurrentTenantOption()); - this.uploadTrackingService.trackUploadedFileForUser(rocketChatUploadParameter.getRoomId()); - - if (sendNotification) { - emailNotificationFacade.sendFeedbackEmailNotification(rocketChatUploadParameter.getRoomId()); - } - } - private void sanitizeAndEncryptParametersAndUploadToRocketChatRoom( RocketChatCredentials rocketChatCredentials, RocketChatUploadParameter rocketChatUploadParameter, String type, String fileHeader) { diff --git a/src/main/java/de/caritas/cob/uploadservice/api/helper/EmailNotificationHelper.java b/src/main/java/de/caritas/cob/uploadservice/api/helper/EmailNotificationHelper.java index e426d13..c7f6b87 100644 --- a/src/main/java/de/caritas/cob/uploadservice/api/helper/EmailNotificationHelper.java +++ b/src/main/java/de/caritas/cob/uploadservice/api/helper/EmailNotificationHelper.java @@ -49,16 +49,6 @@ public void sendEmailNotificationViaUserService( sendEmailNotificationCallingMethod(rcGroupId, userControllerApi::sendNewMessageNotification); } - @Async - public void sendEmailFeedbackNotificationViaUserService( - String rcGroupId, String accessToken, - Optional currentTenant) { - var userControllerApi = userServiceApiControllerFactory.createControllerApi(); - addDefaultHeaders(userControllerApi.getApiClient(), accessToken, currentTenant); - sendEmailNotificationCallingMethod(rcGroupId, - userControllerApi::sendNewFeedbackMessageNotification); - } - private void sendEmailNotificationCallingMethod(String rcGroupId, Consumer newMessageNotificationConsumerMethod) { try { NewMessageNotificationDTO notificationDto = new NewMessageNotificationDTO().rcGroupId( diff --git a/src/test/java/de/caritas/cob/uploadservice/api/facade/EmailNotificationFacadeTest.java b/src/test/java/de/caritas/cob/uploadservice/api/facade/EmailNotificationFacadeTest.java index 403cce0..72b0888 100644 --- a/src/test/java/de/caritas/cob/uploadservice/api/facade/EmailNotificationFacadeTest.java +++ b/src/test/java/de/caritas/cob/uploadservice/api/facade/EmailNotificationFacadeTest.java @@ -51,17 +51,4 @@ public void sendEmailNotification_Should_PassSendNewMessageNotificationUrl2Notif .sendEmailNotificationViaUserService( RC_GROUP_ID, KEYCLOAK_ACCESS_TOKEN, Optional.ofNullable((TenantContext.getCurrentTenant()))); } - - @Test - public void - sendFeedbackEmailNotification_Should_PassNewFeedbMsgNotificationUrl2NotificationHelper() { - - when(authenticatedUser.getAccessToken()).thenReturn(KEYCLOAK_ACCESS_TOKEN); - - emailNotificationFacade.sendFeedbackEmailNotification(RC_GROUP_ID); - - verify(emailNotificationHelper, times(1)) - .sendEmailFeedbackNotificationViaUserService( - RC_GROUP_ID, KEYCLOAK_ACCESS_TOKEN, Optional.ofNullable(TenantContext.getCurrentTenant())); - } } diff --git a/src/test/java/de/caritas/cob/uploadservice/api/facade/UploadFacadeTest.java b/src/test/java/de/caritas/cob/uploadservice/api/facade/UploadFacadeTest.java index 5fb6bd7..9c82b61 100644 --- a/src/test/java/de/caritas/cob/uploadservice/api/facade/UploadFacadeTest.java +++ b/src/test/java/de/caritas/cob/uploadservice/api/facade/UploadFacadeTest.java @@ -214,83 +214,4 @@ public void uploadFileToRoom_Should_ThrowInternalServerErrorException_WheRocketC uploadFacade.uploadFileToRoom(rocketChatCredentials, rocketChatUploadParameter, false, null, null); } - - /** - * Method: uploadFileToFeedbackRoom - */ - @Test - public void uploadFileToFeedbackRoom_Should_CallServicesCorrectly_WhenNoExceptionIsThrown() - throws Exception { - - uploadFacade.uploadFileToFeedbackRoom( - rocketChatCredentials, rocketChatUploadParameter, false, null, null); - - verify(rocketChatUploadParameterSanitizer, times(1)).sanitize(rocketChatUploadParameter); - verify(rocketChatUploadParameterEncrypter, times(1)).encrypt(rocketChatUploadParameter); - verify(rocketChatService, times(1)).roomsUpload(rocketChatCredentials, - rocketChatUploadParameter); - verify(rocketChatService, times(1)).markGroupAsReadForSystemUser( - rocketChatUploadParameter.getRoomId()); - verify(uploadTrackingService, times(1)).validateUploadLimit(any()); - verify(uploadTrackingService, times(1)).trackUploadedFileForUser(any()); - verify(fileService).verifyMimeType(multipartFile); - } - - @Test - public void uploadFileToFeedbackRoom_Should_sendEmailNotification_WhenParamIsTrue() { - - uploadFacade.uploadFileToFeedbackRoom( - rocketChatCredentials, rocketChatUploadParameter, true, null, null); - - verify(emailNotificationFacade, times(1)).sendFeedbackEmailNotification(RC_ROOM_ID); - } - - @Test - public void uploadFileToFeedbackRoom_Should_markGroupAsReadForSystemUser() - throws RocketChatPostMarkGroupAsReadException { - - uploadFacade.uploadFileToFeedbackRoom( - rocketChatCredentials, rocketChatUploadParameter, false, null, null); - - verify(rocketChatService, times(1)).markGroupAsReadForSystemUser(RC_ROOM_ID); - } - - @Test - public void uploadFileToFeedbackRoom_Should_uploadToRocketChat() { - - uploadFacade.uploadFileToFeedbackRoom( - rocketChatCredentials, rocketChatUploadParameter, false, null, null); - - verify(rocketChatService, times(1)) - .roomsUpload( - Mockito.any(RocketChatCredentials.class), Mockito.any(RocketChatUploadParameter.class)); - } - - @Test - public void uploadFileToFeedbackRoom_Should_EncryptRocketChatParameter() - throws CustomCryptoException { - - uploadFacade.uploadFileToFeedbackRoom( - rocketChatCredentials, rocketChatUploadParameter, false, null, null); - - verify(rocketChatUploadParameterEncrypter, times(1)).encrypt(rocketChatUploadParameter); - } - - @Test - public void uploadFileToFeedbackRoom_Should_SanitizeRocketChatParameter() { - - uploadFacade.uploadFileToFeedbackRoom( - rocketChatCredentials, rocketChatUploadParameter, false, null, null); - - verify(rocketChatUploadParameterSanitizer, times(1)).sanitize(rocketChatUploadParameter); - } - - @Test - public void uploadFileToFeedbackRoom_Should_sendLiveNotification_When_UploadSucceeds() { - - uploadFacade.uploadFileToFeedbackRoom(rocketChatCredentials, rocketChatUploadParameter, false, null, null); - - verify(this.liveEventNotificationService, times(1)) - .sendLiveEvent(eq(rocketChatUploadParameter.getRoomId()), any(), any()); - } }