-
Notifications
You must be signed in to change notification settings - Fork 7
Feature/dnd validation #738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #738 +/- ##
==========================================
+ Coverage 36.77% 38.13% +1.36%
==========================================
Files 545 545
Lines 23692 23836 +144
Branches 2832 2855 +23
==========================================
+ Hits 8713 9091 +378
+ Misses 14102 13847 -255
- Partials 877 898 +21 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This reverts commit 558eab8.
This fixes a bug where we didn't return a default explanation when an incorrect answer without an explanation was matched.
src/test/java/uk/ac/cam/cl/dtg/isaac/api/IsaacIntegrationTestWithREST.java
Fixed
Show fixed
Hide fixed
jsharkey13
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some initial thoughts.
One that is not addressed everywhere inline is the use of var. We have never used var before (because the codebase started in Java 6, and was Java 8 for most of its life). I would much prefer explicit types everywhere, since they are almost always easier to read (var can't even help us with the awful Map<String, ? extends Map<String, ? extends List<? extends LightweightQuestionValidationResponse>>> type we use a lot, since you obviously cannot use it in method signatures; that's one case where hiding this mess of a type would be useful and it's no help!). There's at least one comment on var with a suggestion from a Java style guide I found useful - since I hadn't met var before this PR.
src/main/java/uk/ac/cam/cl/dtg/isaac/dos/content/DndChoice.java
Outdated
Show resolved
Hide resolved
src/main/java/uk/ac/cam/cl/dtg/isaac/quiz/IsaacDndValidator.java
Outdated
Show resolved
Hide resolved
| return injector; | ||
| } | ||
|
|
||
| public static void setInjector(final Injector newInjector) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is dangerous, and I don't like it. If we add it, we should add it @Deprecated immediately, so that nobody thinks they can use it. It also needs either a name or clear JavaDoc indicating the dangers of using it, i.e. that it will pollute the global creation of new classes going forwards.
If this is used in a test, all subsequent tests may be affected.
src/main/java/uk/ac/cam/cl/dtg/isaac/quiz/IsaacDndValidator.java
Outdated
Show resolved
Hide resolved
src/main/java/uk/ac/cam/cl/dtg/isaac/quiz/IsaacDndValidator.java
Outdated
Show resolved
Hide resolved
src/main/java/uk/ac/cam/cl/dtg/isaac/quiz/IsaacDndValidator.java
Outdated
Show resolved
Hide resolved
src/main/java/uk/ac/cam/cl/dtg/isaac/quiz/IsaacDndValidator.java
Outdated
Show resolved
Hide resolved
src/main/java/uk/ac/cam/cl/dtg/isaac/quiz/IsaacDndValidator.java
Outdated
Show resolved
Hide resolved
jsharkey13
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some initial thoughts.
One that is not addressed everywhere inline is the use of var. We have never used var before (because the codebase started in Java 6, and was Java 8 for most of its life). I would much prefer explicit types everywhere, since they are almost always easier to read (var can't even help us with the awful Map<String, ? extends Map<String, ? extends List<? extends LightweightQuestionValidationResponse>>> type we use a lot, since you obviously cannot use it in method signatures; that's one case where hiding this mess of a type would be useful and it's no help!). There's at least one comment on var with a suggestion from a Java style guide I found useful - since I hadn't met var before this PR.
this is to address #738 (comment)
This had changed earlier, but is now also codified in tests. The changes to `IsaacDndValidator` are just cosmetic, they don't implement the change that's now tested.
This reverts commit c733f02.
This reverts commit 3919369.
to address https://github.com/isaacphysics/isaac-api/pull/738/files /c6b7d7d98555c654b6341a53eb24762a3fcfc8f3#diff-69b2f786502a295b7be330beab103f5b0699a5958ff1596a12089bd5766d402c
This adds a validator for the DnD question type. You can test that this works using the following question: http://localhost:8004/questions/c4520e54-4777-41b9-9967-2893cea96a62. Although the front-end does not yet
implement showing item-level feedback, you can see that the response also contains the necessary information for this.
The feature
Here's how it works. To create a drag-and-drop question, the content developer must specify the type as drag and drop, declare drop zones in either text or figure content, and define the drag-and-drop items. Then, they need to specify at least one correct answer, which is a pairing of drop zones and items. They may also define incorrect answers. This is only necessary if they'd like to show specific feedback to the student about why a submission is wrong.
Requirements for answers:
Differences between DnD and Cloze questions.
The implementation
There are changes to 13 non-test and 7 test files.
Code changes
(15 files)8 files):DndChoice,DndChoiceDTO,DndValidationResponse,DndValidationResponseDTO. The validator forIsaacDndQuestionneeded a minor adjustment, and the change toItemChoiceis stylistic.QuestionValidationResponseDeserializerneeded changing so we correctly preload DnD questions with the last attempt when one is available.QuestionValidationMappersupports the newDndValidationResponsetype.IsaacDndValidatorandValidationUtils(2 files). This is where validation is mainly implemented. I've modelled the behavior onIsaacClozeValidator. Compared to it, the most important changes are:IsaacClozeValidatortries to fix invalid questions by, for example, ignoring any answers that are invalid (eg: the item id is missing), IsaacDndValidator refuses to validate invalid questions (it says the answer was incorrect, and explains that the question is invalid). I'm hoping that by being stricter with validation, we'll save ourselves some trouble later, by only needing to support a more limited number of question states for this type. Invalid DnD questions show up as non-critical content errors. Even when invalid, they're ETL'ed.SegueGuiceConfigurationModule: a newsetInjectormethod, used for mocking the injector from integration tests. It would be better if we didn't have to mock at all from integration tests, but I didn't have the strength to make this change.ElasticSearchIndexer: changed a few method visisbilites to public so we can load content objects during integration testsContentIndexerimplements the ETL process. This has been updated so invalid questions show up as content errors. This performs the same question validation as the marking endpoint.Test changes
QuestionsFacade. I made this because I wanted to explore how Jackson reacts to requests with invalid JSON, to get a better idea of what still needed to be checked manually in the validator. I needed to extendAbstractIntegrationTestso it can provide the new dependencies this required.IsaacIntegrationTestWithRestTestAppenderhelper, which I used when testing loggingIsaacDndValidator, and extended tests forContentIndexer.IsaacClozeValidatoralso got a new test, despite the functionality in the class not getting modified (I wanted to be sure it worked how I expected it to).Logging
When the
/answerendpoint encounters an invalid question, it logs this so we are aware there is an invalid question on the platform. However, it doesn't create logs for attempts that are generated by users. The ETL process also doesn't log invalid questions, as these are just recorded as content errors.Security
After reading through the code of several validators, I concluded that protecting against SQL injuctions doesn't happen here. I did add stricter validation, which should also make the endpoint more secure, but didn't add any additional protections against SQL injection to the DnD validator (eg: by sanitising the submitted answer). Although the validator itself never touches the database, the validation response it produces does get recorded, and the response includes the answer, which is user-provided. If the reviewer feels I should have done this as part of this PR, I'm happy to do it.
Performance
Possible improvements
Please don't be afraid to request changes, I'm sure we can find a way to get them done quickly^^.
Pull Request Check List