SEBSERV-417 apply exam_data before SEB restriction

This commit is contained in:
anhefti 2024-06-19 12:17:12 +02:00
parent fbe7781be1
commit 8238361910
2 changed files with 21 additions and 1 deletions

View file

@ -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.FullLmsIntegrationService;
import ch.ethz.seb.sebserver.webservice.servicelayer.lms.LmsAPITemplate; 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.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.lms.impl.moodle.MoodleUtils;
import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.ConnectionConfigurationChangeEvent; import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.ConnectionConfigurationChangeEvent;
import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.ConnectionConfigurationService; import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.ConnectionConfigurationService;
@ -85,6 +86,7 @@ public class FullLmsIntegrationServiceImpl implements FullLmsIntegrationService
private final String lmsAPIEndpoint; private final String lmsAPIEndpoint;
private final UserService userService; private final UserService userService;
private final ClientCredentialsResourceDetails resource; private final ClientCredentialsResourceDetails resource;
private final SEBRestrictionService sebRestrictionService;
private final OAuth2RestTemplate restTemplate; private final OAuth2RestTemplate restTemplate;
public FullLmsIntegrationServiceImpl( public FullLmsIntegrationServiceImpl(
@ -105,6 +107,7 @@ public class FullLmsIntegrationServiceImpl implements FullLmsIntegrationService
final UserService userService, final UserService userService,
final TeacherAccountServiceImpl teacherAccountServiceImpl, final TeacherAccountServiceImpl teacherAccountServiceImpl,
final LmsAPITemplateCacheService lmsAPITemplateCacheService, final LmsAPITemplateCacheService lmsAPITemplateCacheService,
final SEBRestrictionService sebRestrictionService,
@Value("${sebserver.webservice.lms.api.endpoint}") final String lmsAPIEndpoint, @Value("${sebserver.webservice.lms.api.endpoint}") final String lmsAPIEndpoint,
@Value("${sebserver.webservice.lms.api.clientId}") final String clientId, @Value("${sebserver.webservice.lms.api.clientId}") final String clientId,
@Value("${sebserver.webservice.api.admin.clientSecret}") final String clientSecret) { @Value("${sebserver.webservice.api.admin.clientSecret}") final String clientSecret) {
@ -124,6 +127,7 @@ public class FullLmsIntegrationServiceImpl implements FullLmsIntegrationService
this.examConfigurationValueService = examConfigurationValueService; this.examConfigurationValueService = examConfigurationValueService;
this.examImportService = examImportService; this.examImportService = examImportService;
this.clientConnectionDAO = clientConnectionDAO; this.clientConnectionDAO = clientConnectionDAO;
this.sebRestrictionService = sebRestrictionService;
resource = new ClientCredentialsResourceDetails(); resource = new ClientCredentialsResourceDetails();
resource.setAccessTokenUri(webserviceInfo.getOAuthTokenURI()); resource.setAccessTokenUri(webserviceInfo.getOAuthTokenURI());
@ -317,6 +321,7 @@ public class FullLmsIntegrationServiceImpl implements FullLmsIntegrationService
.map(template -> getQuizData(template, courseId, quizId, examData)) .map(template -> getQuizData(template, courseId, quizId, examData))
.map(createExam(examTemplateId, quitPassword)) .map(createExam(examTemplateId, quitPassword))
.map(exam -> applyExamData(exam, false)) .map(exam -> applyExamData(exam, false))
.flatMap(sebRestrictionService::applySEBClientRestriction)
.map(this::applyConnectionConfiguration); .map(this::applyConnectionConfiguration);
} }

View file

@ -8,6 +8,8 @@
package ch.ethz.seb.sebserver.webservice.servicelayer.lms.impl; 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.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -103,7 +105,7 @@ public class SEBRestrictionServiceImpl implements SEBRestrictionService {
public Result<Exam> applyQuitPassword(final Exam exam) { public Result<Exam> applyQuitPassword(final Exam exam) {
return this.examConfigurationValueService return this.examConfigurationValueService
.applyQuitPasswordToConfigs(exam.id, exam.quitPassword) .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)); .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) { private Exam applySEBRestrictionIfExamRunning(final Exam exam) {
if (exam.status != Exam.ExamStatus.RUNNING) { if (exam.status != Exam.ExamStatus.RUNNING) {
return exam; return exam;