Skip to content

Commit

Permalink
fix: CARITAS-243
Browse files Browse the repository at this point in the history
* remove uploadFileToFeedbackRoom api
  • Loading branch information
Leandro13Silva13 committed Aug 9, 2024
1 parent dd26e6c commit 8903590
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 269 deletions.
76 changes: 0 additions & 76 deletions api/uploadservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -105,54 +101,4 @@ public ResponseEntity<Void> 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<Void> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,6 @@ public void sendEmailNotificationViaUserService(
sendEmailNotificationCallingMethod(rcGroupId, userControllerApi::sendNewMessageNotification);
}

@Async
public void sendEmailFeedbackNotificationViaUserService(
String rcGroupId, String accessToken,
Optional<Long> currentTenant) {
var userControllerApi = userServiceApiControllerFactory.createControllerApi();
addDefaultHeaders(userControllerApi.getApiClient(), accessToken, currentTenant);
sendEmailNotificationCallingMethod(rcGroupId,
userControllerApi::sendNewFeedbackMessageNotification);
}

private void sendEmailNotificationCallingMethod(String rcGroupId, Consumer<NewMessageNotificationDTO> newMessageNotificationConsumerMethod) {
try {
NewMessageNotificationDTO notificationDto = new NewMessageNotificationDTO().rcGroupId(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 8903590

Please sign in to comment.