From 8c6ffee2a9c654395c80b448cb4782b4d6c69dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20B=C3=BCchel?= Date: Wed, 19 Jan 2022 12:01:12 +0100 Subject: [PATCH] SEBSERV-262: Implemented default settings for Zoom user. --- .../proctoring/ZoomProctoringService.java | 33 +++++++++++++++++++ .../proctoring/ZoomRoomRequestResponse.java | 20 +++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ZoomProctoringService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ZoomProctoringService.java index eed51752..c5ffd950 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ZoomProctoringService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ZoomProctoringService.java @@ -75,6 +75,7 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.dao.RemoteProctoringRoomDAO import ch.ethz.seb.sebserver.webservice.servicelayer.session.ExamProctoringService; import ch.ethz.seb.sebserver.webservice.servicelayer.session.ExamSessionService; import ch.ethz.seb.sebserver.webservice.servicelayer.session.SEBClientInstructionService; +import ch.ethz.seb.sebserver.webservice.servicelayer.session.impl.proctoring.ZoomRoomRequestResponse.ApplyUserSettingsRequest; import ch.ethz.seb.sebserver.webservice.servicelayer.session.impl.proctoring.ZoomRoomRequestResponse.CreateMeetingRequest; import ch.ethz.seb.sebserver.webservice.servicelayer.session.impl.proctoring.ZoomRoomRequestResponse.CreateUserRequest; import ch.ethz.seb.sebserver.webservice.servicelayer.session.impl.proctoring.ZoomRoomRequestResponse.MeetingResponse; @@ -553,6 +554,11 @@ public class ZoomProctoringService implements ExamProctoringService { createUser.getBody(), UserResponse.class); + this.zoomRestTemplate.applyUserSettings( + proctoringSettings.serverURL, + credentials, + userResponse.id); + // Then create new meeting with the ad-hoc user/host final CharSequence meetingPwd = UUID.randomUUID().toString().subSequence(0, 9); final ResponseEntity createMeeting = this.zoomRestTemplate.createMeeting( @@ -779,6 +785,7 @@ public class ZoomProctoringService implements ExamProctoringService { private static final int LIZENSED_USER = 2; private static final String API_TEST_ENDPOINT = "v2/users"; private static final String API_CREATE_USER_ENDPOINT = "v2/users"; + private static final String API_APPLY_USER_SETTINGS_ENDPOINT = "v2/users/{userId}/settings"; private static final String API_DELETE_USER_ENDPOINT = "v2/users/{userid}?action=delete"; private static final String API_USER_CUST_CREATE = "custCreate"; private static final String API_ZOOM_ROOM_USER = "SEBProctoringRoomUser"; @@ -856,6 +863,32 @@ public class ZoomProctoringService implements ExamProctoringService { } } + public ResponseEntity applyUserSettings( + final String zoomServerUrl, + final ClientCredentials credentials, + final String userId) { + try { + final String url = UriComponentsBuilder + .fromUriString(zoomServerUrl) + .path(API_APPLY_USER_SETTINGS_ENDPOINT) + .buildAndExpand(userId) + .normalize() + .toUriString(); + final String host = new URL(zoomServerUrl).getHost(); + final ApplyUserSettingsRequest applySettingsRequest = new ApplyUserSettingsRequest(); + final String body = this.zoomProctoringService.jsonMapper.writeValueAsString(applySettingsRequest); + final HttpHeaders headers = getHeaders(credentials); + + headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); + + return exchange(url, HttpMethod.PATCH, body, headers); + + } catch (final Exception e) { + log.error("Failed to apply user settings for Zoom user: {}", userId, e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + } + public ResponseEntity createMeeting( final String zoomServerUrl, final ClientCredentials credentials, diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ZoomRoomRequestResponse.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ZoomRoomRequestResponse.java index d822da64..57a02181 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ZoomRoomRequestResponse.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ZoomRoomRequestResponse.java @@ -87,6 +87,26 @@ public interface ZoomRoomRequestResponse { } } + @JsonIgnoreProperties(ignoreUnknown = true) + static class ApplyUserSettingsRequest { + @JsonProperty final InMeetingSettings in_meeting; + public ApplyUserSettingsRequest() { + this.in_meeting = new InMeetingSettings(true, 1); + } + public ApplyUserSettingsRequest(final InMeetingSettings in_meeting) { + this.in_meeting = in_meeting; + } + + static class InMeetingSettings { + @JsonProperty final boolean auto_saving_chat; + @JsonProperty final int allow_users_save_chats; + public InMeetingSettings(boolean auto_saving_chat, int allow_users_save_chats) { + this.auto_saving_chat = auto_saving_chat; + this.allow_users_save_chats = allow_users_save_chats; + } + } + } + @JsonIgnoreProperties(ignoreUnknown = true) static class UserResponse { final String id;