Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caritas 243 remove legacy code #7

Merged
merged 11 commits into from
Sep 11, 2024
Merged
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
63 changes: 0 additions & 63 deletions services/userservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -538,33 +538,6 @@ paths:
description: INTERNAL SERVER ERROR - server encountered unexpected condition
security:
- Bearer: [ ]
/users/mails/messages/feedback/new:
post:
tags:
- user-controller
summary: 'Sends a notification e-mail that a new feedback message/answer has
been written [Authorization: Role: consultant with authority for feedback
chat]'
operationId: sendNewFeedbackMessageNotification
requestBody:
content:
'application/json':
schema:
$ref: '#/components/schemas/NewMessageNotificationDTO'
required: true
responses:
200:
description: successful operation
400:
description: BAD REQUEST - invalid/incomplete request or body object
401:
description: UNAUTHORIZED - invalid token
409:
description: CONFLICT - no user e-mail address in db given
500:
description: INTERNAL SERVER ERROR - server encountered unexpected condition
security:
- Bearer: [ ]
/users/consultants:
get:
tags:
Expand Down Expand Up @@ -1180,10 +1153,6 @@ components:
type: string
example: xGklslk2JJKK
description: Rocket.Chat room ID
feedbackGroupId:
type: string
example: 8ertjlasdKJA
description: Rocket.Chat feedback room ID
askerRcId:
type: string
example: 8ertjlasdKJA
Expand All @@ -1198,9 +1167,6 @@ components:
messagesRead:
type: boolean
example: false
feedbackRead:
type: boolean
example: true
isTeamSession:
type: boolean
example: false
Expand Down Expand Up @@ -1231,35 +1197,11 @@ components:
AliasMessageDTO:
type: object
properties:
forwardMessageDTO:
$ref: '#/components/schemas/ForwardMessageDTO'
videoCallMessageDTO:
$ref: '#/components/schemas/VideoCallMessageDTO'
messageType:
$ref: '#/components/schemas/MessageType'

ForwardMessageDTO:
type: object
required:
- message
- timestamp
- username
- rcUserId
properties:
message:
type: string
example: "Lorem ipsum dolor sit amet, consetetur..."
timestamp:
type: string
description: "Full qualified timestamp"
example: "2018-11-15T09:33:00.057Z"
username:
type: string
example: "asker23"
rcUserId:
type: string
example: "ag89h3tjkerg94t"

VideoCallMessageDTO:
type: object
required:
Expand All @@ -1283,7 +1225,6 @@ components:
enum:
- "FURTHER_STEPS"
- "UPDATE_SESSION_DATA"
- "FORWARD"
- "VIDEOCALL"

ConsultantSessionDTO:
Expand Down Expand Up @@ -1312,10 +1253,6 @@ components:
type: string
example: xGklslk2JJKK
description: Rocket.Chat room ID
feedbackGroupId:
type: string
example: 8ertjlasdKJA
description: Rocket.Chat feedback room ID
consultantId:
type: string
example: 926b9777-4eef-443d-925a-4aa534797bd7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static de.caritas.cob.uploadservice.api.authorization.Authority.AuthorityValue.CONSULTANT_DEFAULT;
import static de.caritas.cob.uploadservice.api.authorization.Authority.AuthorityValue.TECHNICAL_DEFAULT;
import static de.caritas.cob.uploadservice.api.authorization.Authority.AuthorityValue.USER_DEFAULT;
import static de.caritas.cob.uploadservice.api.authorization.Authority.AuthorityValue.USE_FEEDBACK;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;

Expand All @@ -23,7 +22,6 @@ public enum Authority {

USER(UserRole.USER, singletonList(USER_DEFAULT)),
CONSULTANT(UserRole.CONSULTANT, singletonList(CONSULTANT_DEFAULT)),
U25_CONSULTANT(UserRole.PEER_CONSULTANT, singletonList(USE_FEEDBACK)),
TECHNICAL(UserRole.TECHNICAL, singletonList(TECHNICAL_DEFAULT)),
ANONYMOUS(UserRole.ANONYMOUS, singletonList(ANONYMOUS_DEFAULT));

Expand Down Expand Up @@ -54,7 +52,6 @@ private AuthorityValue() {

public static final String CONSULTANT_DEFAULT = PREFIX + "CONSULTANT_DEFAULT";
public static final String USER_DEFAULT = PREFIX + "USER_DEFAULT";
public static final String USE_FEEDBACK = PREFIX + "USE_FEEDBACK";
public static final String TECHNICAL_DEFAULT = PREFIX + "TECHNICAL_DEFAULT";
public static final String ANONYMOUS_DEFAULT = PREFIX + "ANONYMOUS_DEFAULT";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public enum UserRole {
USER("user"),
CONSULTANT("consultant"),
TECHNICAL("technical"),
PEER_CONSULTANT("peer-consultant"),
ANONYMOUS("anonymous");

private final String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
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 +102,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 @@ -20,9 +20,6 @@ public class EmailNotificationFacade {
@Value("${user.service.api.new.message.notification}")
private String userServiceApiSendNewMessageNotificationUrl;

@Value("${user.service.api.new.feedback.message.notification}")
private String userServiceApiSendNewFeedbackMessageNotificationUrl;

@Autowired
public EmailNotificationFacade(
EmailNotificationHelper emailNotificationHelper, AuthenticatedUser authenticatedUser) {
Expand All @@ -42,16 +39,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
Loading
Loading