diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/FullLmsIntegrationServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/FullLmsIntegrationServiceImpl.java index c0830352..0757eef4 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/FullLmsIntegrationServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/FullLmsIntegrationServiceImpl.java @@ -47,6 +47,7 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.exam.ExamTemplateChangeEven import ch.ethz.seb.sebserver.webservice.servicelayer.lms.FullLmsIntegrationService; import ch.ethz.seb.sebserver.webservice.servicelayer.lms.LmsAPITemplate; import ch.ethz.seb.sebserver.webservice.servicelayer.lms.LmsAPITemplateCacheService; +import ch.ethz.seb.sebserver.webservice.servicelayer.lms.SEBRestrictionService; import ch.ethz.seb.sebserver.webservice.servicelayer.lms.impl.moodle.MoodleUtils; import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.ConnectionConfigurationChangeEvent; import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.ConnectionConfigurationService; @@ -85,6 +86,7 @@ public class FullLmsIntegrationServiceImpl implements FullLmsIntegrationService private final String lmsAPIEndpoint; private final UserService userService; private final ClientCredentialsResourceDetails resource; + private final SEBRestrictionService sebRestrictionService; private final OAuth2RestTemplate restTemplate; public FullLmsIntegrationServiceImpl( @@ -105,6 +107,7 @@ public class FullLmsIntegrationServiceImpl implements FullLmsIntegrationService final UserService userService, final TeacherAccountServiceImpl teacherAccountServiceImpl, final LmsAPITemplateCacheService lmsAPITemplateCacheService, + final SEBRestrictionService sebRestrictionService, @Value("${sebserver.webservice.lms.api.endpoint}") final String lmsAPIEndpoint, @Value("${sebserver.webservice.lms.api.clientId}") final String clientId, @Value("${sebserver.webservice.api.admin.clientSecret}") final String clientSecret) { @@ -124,6 +127,7 @@ public class FullLmsIntegrationServiceImpl implements FullLmsIntegrationService this.examConfigurationValueService = examConfigurationValueService; this.examImportService = examImportService; this.clientConnectionDAO = clientConnectionDAO; + this.sebRestrictionService = sebRestrictionService; resource = new ClientCredentialsResourceDetails(); resource.setAccessTokenUri(webserviceInfo.getOAuthTokenURI()); @@ -317,6 +321,7 @@ public class FullLmsIntegrationServiceImpl implements FullLmsIntegrationService .map(template -> getQuizData(template, courseId, quizId, examData)) .map(createExam(examTemplateId, quitPassword)) .map(exam -> applyExamData(exam, false)) + .flatMap(sebRestrictionService::applySEBClientRestriction) .map(this::applyConnectionConfiguration); } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/SEBRestrictionServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/SEBRestrictionServiceImpl.java index 7ffae6c1..b26bd18d 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/SEBRestrictionServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/SEBRestrictionServiceImpl.java @@ -8,6 +8,8 @@ package ch.ethz.seb.sebserver.webservice.servicelayer.lms.impl; +import static ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.LmsSetupRecordDynamicSqlSupport.lmsType; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -103,7 +105,7 @@ public class SEBRestrictionServiceImpl implements SEBRestrictionService { public Result applyQuitPassword(final Exam exam) { return this.examConfigurationValueService .applyQuitPasswordToConfigs(exam.id, exam.quitPassword) - .map(id -> applySEBRestrictionIfExamRunning(exam)) + .map(id -> applyQuitPasswordWithRestrictionIfNeeded(exam)) .onError(t -> log.error("Failed to quit password for Exam: {}", exam, t)); } @@ -159,6 +161,19 @@ public class SEBRestrictionServiceImpl implements SEBRestrictionService { }); } + private Exam applyQuitPasswordWithRestrictionIfNeeded(final Exam exam) { + if (exam.status != Exam.ExamStatus.RUNNING) { + return exam; + } + + final LmsSetup lmsSetup = getLmsAPIService().getLmsSetup(exam.lmsSetupId).getOrThrow(); + if (!lmsSetup.lmsType.features.contains(Features.LMS_FULL_INTEGRATION)) { + applySEBRestrictionIfExamRunning(exam); + } + + return exam; + } + private Exam applySEBRestrictionIfExamRunning(final Exam exam) { if (exam.status != Exam.ExamStatus.RUNNING) { return exam;