From 90d403c2b30634b3f91f6ade6595265e8942675a Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 15 Jun 2023 10:40:50 +0200 Subject: [PATCH 1/6] SEBSERV-449 fixed name query --- .../lms/impl/moodle/plugin/MoodlePluginCourseAccess.java | 6 ++++-- .../moodle/plugin/MooldePluginLmsAPITemplateFactory.java | 2 +- src/main/resources/config/application-ws.properties | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MoodlePluginCourseAccess.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MoodlePluginCourseAccess.java index 2321adeb..dd59758a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MoodlePluginCourseAccess.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MoodlePluginCourseAccess.java @@ -438,8 +438,10 @@ public class MoodlePluginCourseAccess extends AbstractCachedCourseAccess impleme // TODO clarify with Amr and Luca if this is OK // and if it is possible to apply the nameCondition also the the course name (shortname) - if (this.applyNameCriteria && StringUtils.isNotBlank(nameCondition)) { - sqlCondition = sqlCondition + " AND (m.name LIKE '" + + if (StringUtils.isNotBlank(nameCondition)) { + sqlCondition = sqlCondition + " AND (name LIKE '" + + Utils.toSQLWildcard(nameCondition) + + "' OR shortname LIKE '" + Utils.toSQLWildcard(nameCondition) + "')"; } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MooldePluginLmsAPITemplateFactory.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MooldePluginLmsAPITemplateFactory.java index 7b027a1e..f83dbecf 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MooldePluginLmsAPITemplateFactory.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MooldePluginLmsAPITemplateFactory.java @@ -57,7 +57,7 @@ public class MooldePluginLmsAPITemplateFactory implements LmsAPITemplateFactory final ExamConfigurationValueService examConfigurationValueService, final ClientHttpRequestFactoryService clientHttpRequestFactoryService, @Value("${sebserver.webservice.lms.moodle.api.token.request.paths:}") final String alternativeTokenRequestPaths, - @Value("${sebserver.webservice.lms.moodle.fetch.applyNameCriteria:false}") final boolean applyNameCriteria) { + @Value("${sebserver.webservice.lms.moodle.fetch.applyNameCriteria:true}") final boolean applyNameCriteria) { this.jsonMapper = jsonMapper; this.cacheManager = cacheManager; diff --git a/src/main/resources/config/application-ws.properties b/src/main/resources/config/application-ws.properties index f3568646..f1f2727a 100644 --- a/src/main/resources/config/application-ws.properties +++ b/src/main/resources/config/application-ws.properties @@ -81,7 +81,7 @@ sebserver.webservice.lms.openedx.api.token.request.paths=/oauth2/access_token sebserver.webservice.lms.moodle.api.token.request.paths=/login/token.php sebserver.webservice.lms.moodle.prependShortCourseName=true sebserver.webservice.lms.moodle.fetch.cutoffdate.yearsBeforeNow=2 -sebserver.webservice.lms.moodle.fetch.applyNameCriteria=false +sebserver.webservice.lms.moodle.fetch.applyNameCriteria=true sebserver.webservice.lms.olat.sendAdditionalAttributesWithRestriction=false sebserver.webservice.lms.address.alias= sebserver.webservice.lms.datafetch.validity.seconds=600 From 922149e7401556573f8208a373abb899866fe1c5 Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 15 Jun 2023 10:41:20 +0200 Subject: [PATCH 2/6] SEBSERV-449 fixed name query --- .../lms/impl/moodle/plugin/MoodlePluginCourseAccess.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MoodlePluginCourseAccess.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MoodlePluginCourseAccess.java index dd59758a..d8568f3b 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MoodlePluginCourseAccess.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MoodlePluginCourseAccess.java @@ -436,9 +436,7 @@ public class MoodlePluginCourseAccess extends AbstractCachedCourseAccess impleme final String fromElement = String.valueOf(page * size); final LinkedMultiValueMap attributes = new LinkedMultiValueMap<>(); - // TODO clarify with Amr and Luca if this is OK - // and if it is possible to apply the nameCondition also the the course name (shortname) - if (StringUtils.isNotBlank(nameCondition)) { + if (this.applyNameCriteria && StringUtils.isNotBlank(nameCondition)) { sqlCondition = sqlCondition + " AND (name LIKE '" + Utils.toSQLWildcard(nameCondition) + "' OR shortname LIKE '" + From c99922c7ef9272b00275d6b4d9b7b20cd81f02c5 Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 15 Jun 2023 10:42:18 +0200 Subject: [PATCH 3/6] fixed exam lms availability update --- .../servicelayer/session/impl/ExamUpdateHandler.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamUpdateHandler.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamUpdateHandler.java index 665e9400..033e7e5f 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamUpdateHandler.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamUpdateHandler.java @@ -410,11 +410,14 @@ class ExamUpdateHandler { .getLmsAPITemplate(lmsSetupId) .getOrThrow(); + final Exam exam = exams.get(quizId); if (!lmsTemplate.getType().features.contains(Features.COURSE_RECOVERY)) { + if (exam.lmsAvailable == null || exam.isLmsAvailable()) { + this.examDAO.markLMSAvailability(quizId, false, updateId); + } throw new UnsupportedOperationException("No Course Recovery"); } - final Exam exam = exams.get(quizId); final int attempts = Integer.parseInt(this.additionalAttributesDAO.getAdditionalAttribute( EntityType.EXAM, exam.id, From 4b051fbc97eefbd98a39eb2929dc08107ef0a11d Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 15 Jun 2023 10:42:53 +0200 Subject: [PATCH 4/6] fixed also marked as lms unavailable exams shows in running exams --- .../servicelayer/session/impl/ExamSessionServiceImpl.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionServiceImpl.java index a227cc04..b5f61c64 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionServiceImpl.java @@ -267,8 +267,7 @@ public class ExamSessionServiceImpl implements ExamSessionService { filterMap .putIfAbsent(Exam.FILTER_ATTR_ACTIVE, Constants.TRUE_STRING) - .putIfAbsent(Exam.FILTER_ATTR_STATUS, ExamStatus.RUNNING.name()) - .putIfAbsent(Exam.FILTER_ATTR_HIDE_MISSING, Constants.TRUE_STRING); + .putIfAbsent(Exam.FILTER_ATTR_STATUS, ExamStatus.RUNNING.name()); return this.examDAO.allMatching(filterMap, predicate) .map(col -> col.stream() From 768fcea15b2b2090558e3359d1e1ca809a6a6ed9 Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 15 Jun 2023 10:43:37 +0200 Subject: [PATCH 5/6] SEBSERV-444 fixed also in exam delete message --- .../ethz/seb/sebserver/gui/content/exam/ExamDeletePopup.java | 3 ++- src/main/java/ch/ethz/seb/sebserver/gui/widget/Message.java | 2 +- .../servicelayer/lms/impl/mockup/MockCourseAccessAPI.java | 2 +- .../webservice/integration/api/admin/ExamAPITest.java | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamDeletePopup.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamDeletePopup.java index 5ec0af5d..c039a91d 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamDeletePopup.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamDeletePopup.java @@ -16,6 +16,7 @@ import java.util.function.Predicate; import java.util.function.Supplier; import java.util.stream.Collectors; +import org.apache.commons.text.StringEscapeUtils; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; @@ -161,7 +162,7 @@ public class ExamDeletePopup { new ActionEvent(action), action.pageContext()); - final String examName = examToDelete.toName().name; + final String examName = StringEscapeUtils.escapeXml11(examToDelete.toName().name); final List dependencies = report.results.stream() .filter(key -> !key.equals(entityKey)) .collect(Collectors.toList()); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/Message.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/Message.java index 9913deec..4ad20c14 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/Message.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/Message.java @@ -46,7 +46,7 @@ public final class Message extends MessageBox { super.prepareOpen(); } catch (final IllegalArgumentException e) { // fallback on markup text error - super.setMessage(StringEscapeUtils.escapeHtml4(super.getMessage())); + super.setMessage(StringEscapeUtils.escapeXml11(super.getMessage())); super.prepareOpen(); } final GridLayout layout = (GridLayout) super.shell.getLayout(); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/mockup/MockCourseAccessAPI.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/mockup/MockCourseAccessAPI.java index e5db1a9b..b65da02a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/mockup/MockCourseAccessAPI.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/mockup/MockCourseAccessAPI.java @@ -63,7 +63,7 @@ public class MockCourseAccessAPI implements CourseAccessAPI { "quiz1", institutionId, lmsSetupId, lmsType, "Demo Quiz 1 (MOCKUP)", "

Demo Quiz Mockup

", "2020-01-01T09:00:00Z", null, "http://lms.mockup.com/api/")); this.mockups.add(new QuizData( - "quiz2", institutionId, lmsSetupId, lmsType, "Demo Quiz 2 (MOCKUP) äöüèÜÄÖ ?< ", + "quiz2 äöüèÜÄÖ ?<", institutionId, lmsSetupId, lmsType, "Demo Quiz 2 (MOCKUP) äöüèÜÄÖ ?< ", "

Demo Quiz Mockup

", "2020-01-01T09:00:00Z", "2025-01-01T09:00:00Z", "http://lms.mockup.com/api/")); this.mockups.add(new QuizData( diff --git a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/ExamAPITest.java b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/ExamAPITest.java index 3076b492..5bd8c9b1 100644 --- a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/ExamAPITest.java +++ b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/ExamAPITest.java @@ -36,12 +36,12 @@ public class ExamAPITest extends AdministrationAPIIntegrationTester { sebAdminAccess, sebAdminAccess, "LmsSetupMock", - "quiz2", + "quiz2 äöüèÜÄÖ ?<", ExamType.MANAGED, "user5"); assertNotNull(exam); - assertEquals("quiz2", exam.getExternalId()); + assertEquals("quiz2 äöüèÜÄÖ ?<", exam.getExternalId()); // Note cannot set right collation on h2 assertEquals(ExamType.MANAGED, exam.getType()); assertFalse(exam.getSupporter().isEmpty()); From 20429ce1275f3ca94ba2956435e2d5f4f846c9c8 Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 15 Jun 2023 11:12:36 +0200 Subject: [PATCH 6/6] SEBSERV-444 --- .../ch/ethz/seb/sebserver/gui/content/exam/LmsSetupForm.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/LmsSetupForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/LmsSetupForm.java index a980c810..fcac8ab8 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/LmsSetupForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/LmsSetupForm.java @@ -15,7 +15,6 @@ import java.util.function.BooleanSupplier; import java.util.function.Function; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.text.StringEscapeUtils; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; @@ -482,7 +481,7 @@ public class LmsSetupForm implements TemplateComposer { case TOKEN_REQUEST: { throw new PageMessageException(new LocTextKey( "sebserver.lmssetup.action.test.tokenRequestError", - Utils.formatHTMLLinesForceEscaped(StringEscapeUtils.escapeHtml4(error.message)))); + Utils.formatHTMLLinesForceEscaped(Utils.escapeHTML_XML_EcmaScript(error.message)))); } case QUIZ_ACCESS_API_REQUEST: { if (error.message.contains("quizaccess_sebserver_get_exams")) {