From 675d2aad1925442624cd40935438b19c41ec66af Mon Sep 17 00:00:00 2001 From: anhefti Date: Mon, 5 Feb 2024 13:43:59 +0100 Subject: [PATCH] fixed quiz password update from Exam on LMS --- .../servicelayer/exam/ExamAdminService.java | 4 ++-- .../exam/impl/ExamAdminServiceImpl.java | 20 +++++++++++++------ .../api/ExamAdministrationController.java | 10 +++------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/ExamAdminService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/ExamAdminService.java index fe51b753..d848f93f 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/ExamAdminService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/ExamAdminService.java @@ -161,9 +161,9 @@ public interface ExamAdminService { /** Gets invoked after an exam has been changed and saved. * * @param exam the exam that has been changed and saved */ - void notifyExamSaved(Exam exam); + Result notifyExamSaved(Exam exam); - void applyQuitPassword(Exam entity); + Result applyQuitPassword(Exam exam); static void newExamFieldValidation(final POSTMapper postParams) { noLMSFieldValidation(new Exam(postParams)); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/impl/ExamAdminServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/impl/ExamAdminServiceImpl.java index 0f4cb7b8..a41e67f1 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/impl/ExamAdminServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/impl/ExamAdminServiceImpl.java @@ -69,6 +69,7 @@ public class ExamAdminServiceImpl implements ExamAdminService { private final boolean appSignatureKeyEnabled; private final int defaultNumericalTrustThreshold; private final ExamConfigurationValueService examConfigurationValueService; + private final SEBRestrictionService sebRestrictionService; protected ExamAdminServiceImpl( final ExamDAO examDAO, @@ -78,6 +79,7 @@ public class ExamAdminServiceImpl implements ExamAdminService { final ExamConfigurationMapDAO examConfigurationMapDAO, final LmsAPIService lmsAPIService, final ExamConfigurationValueService examConfigurationValueService, + final SEBRestrictionService sebRestrictionService, final @Value("${sebserver.webservice.api.admin.exam.app.signature.key.enabled:false}") boolean appSignatureKeyEnabled, final @Value("${sebserver.webservice.api.admin.exam.app.signature.key.numerical.threshold:2}") int defaultNumericalTrustThreshold) { @@ -90,6 +92,7 @@ public class ExamAdminServiceImpl implements ExamAdminService { this.examConfigurationValueService = examConfigurationValueService; this.appSignatureKeyEnabled = appSignatureKeyEnabled; this.defaultNumericalTrustThreshold = defaultNumericalTrustThreshold; + this.sebRestrictionService = sebRestrictionService; } @Override @@ -323,16 +326,21 @@ public class ExamAdminServiceImpl implements ExamAdminService { } @Override - public void notifyExamSaved(final Exam exam) { - updateAdditionalExamConfigAttributes(exam.id); - this.proctoringAdminService.notifyExamSaved(exam); + public Result notifyExamSaved(final Exam exam) { + return Result.tryCatch(() -> { + updateAdditionalExamConfigAttributes(exam.id); + this.proctoringAdminService.notifyExamSaved(exam); + return exam; + }); } @Override - public void applyQuitPassword(final Exam exam) { - this.examConfigurationValueService + public Result applyQuitPassword(final Exam exam) { + return this.examConfigurationValueService .applyQuitPasswordToConfigs(exam.id, exam.quitPassword) - .getOrThrow(); + .flatMap(id -> this.sebRestrictionService.applySEBClientRestriction(exam)) + .flatMap(e -> this.examDAO.setSEBRestriction(e.id, true)) + .onError(t -> log.error("Failed to update SEB Client restriction for Exam: {}", exam, t)); } private Result initAdditionalAttributesForMoodleExams(final Exam exam) { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAdministrationController.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAdministrationController.java index 6ff20ca6..75df0c6f 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAdministrationController.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAdministrationController.java @@ -15,7 +15,6 @@ import java.util.stream.Collectors; import javax.validation.Valid; import ch.ethz.seb.sebserver.gbl.util.Cryptor; -import ch.ethz.seb.sebserver.webservice.servicelayer.exam.ExamConfigurationValueService; import ch.ethz.seb.sebserver.webservice.servicelayer.lms.impl.NoSEBRestrictionException; import org.apache.commons.lang3.StringUtils; import org.joda.time.DateTime; @@ -669,12 +668,9 @@ public class ExamAdministrationController extends EntityController { @Override protected Result notifySaved(final Exam entity) { - return Result.tryCatch(() -> { - this.examAdminService.notifyExamSaved(entity); - this.examAdminService.applyQuitPassword(entity); - this.examSessionService.flushCache(entity); - return entity; - }); + return this.examAdminService.notifyExamSaved(entity) + .flatMap(this.examAdminService::applyQuitPassword) + .flatMap(this.examSessionService::flushCache); } @Override