Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Password-protect assessment instance creation #5367

Merged
merged 7 commits into from
Feb 8, 2022

Conversation

nwalters512
Copy link
Contributor

This PR ensures, for exams that require a password, that the student has already entered it before they are allowed to create a new assessment instance. This avoids a problem with prompting for the password after the assessment instance has been created: for time-limited exams, the timer would start counting down as soon as the instance is created, but before the user had entered the password.

Regarding the implementation, I don't love the fact that we now have two pieces of code that need to check for the password, but I don't see a great way around that - the logic of when to actually prompt for a password when hitting a studentAssessment{Exam,Homework} page can't be really easily expressed up at the middleware level. I tried to compromise by reusing code and leaving plenty of comments 馃し

Closes #5365.

@@ -2,6 +2,7 @@ var ERR = require('async-stacktrace');
var express = require('express');
var router = express.Router();

const { checkPasswordOrRedirect } = require('../../middlewares/studentAssessmentAccess');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I鈥檓 not in love with requiring middleware from page routes, but I don鈥檛 strongly object either. We could shift this function to lib/, but I鈥檓 not convinced it would be neater. I wanted to at least raise the question to see whether you had any other ideas!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't love this either, but if we move this to lib/, I think we'd have to move much of studentAssessmentAccess too (along with the .ejs file), which basically feels like we're still importing middleware, just without /middleware/ in the path 馃槄 I'm inclined to leave this as-is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Let's stick with things as you have them.

@mwest1066
Copy link
Member

the logic of when to actually prompt for a password when hitting a studentAssessment{Exam,Homework} page can't be really easily expressed up at the middleware level. I tried to compromise by reusing code and leaving plenty of comments 馃し

Just for my own curiosity, can you say something a bit more about why it wasn鈥檛 enough to do the type of simple check that I was thinking of in #5365?

@nwalters512
Copy link
Contributor Author

Just for my own curiosity, can you say something a bit more about why it wasn鈥檛 enough to do the type of simple check that I was thinking of in #5365?

Yes! The main issue is that the studentAssessmentAccess middleware would run on the studentAssessment{Exam,Homework} pages before we've even had a chance to check if an assessment instance exists, so res.locals.assessment_instance will always be null for those pages. This means that landing on studentAssessment{Exam,Homework} for an assessment that already has a closed instance, we'll incorrectly prompt the user for the password. At least, I think this is how it would all work - does that sound correct?

The alternative would be to move the "does assessment instance exist for this assessment" logic into middleware that runs before studentAssessmentAcccess.

@mwest1066
Copy link
Member

Yes! The main issue is that the studentAssessmentAccess middleware would run on the studentAssessment{Exam,Homework} pages before we've even had a chance to check if an assessment instance exists, so res.locals.assessment_instance will always be null for those pages. This means that landing on studentAssessment{Exam,Homework} for an assessment that already has a closed instance, we'll incorrectly prompt the user for the password. At least, I think this is how it would all work - does that sound correct?

Excellent point! We don't load the AI until we are in the page handler, which is after the middleware has run.

The alternative would be to move the "does assessment instance exist for this assessment" logic into middleware that runs before studentAssessmentAcccess.

Yeah, I'm not sure this is cleaner in any way.

@nwalters512 nwalters512 merged commit 345085a into master Feb 8, 2022
@nwalters512 nwalters512 deleted the feat/password-protect-assessment branch February 8, 2022 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change password entry to protect assessments (not just assessment instances)
2 participants