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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enrolment via a secret key #90

Merged
merged 6 commits into from
Oct 30, 2023
Merged

Add enrolment via a secret key #90

merged 6 commits into from
Oct 30, 2023

Conversation

alasdairwilson
Copy link
Collaborator

@alasdairwilson alasdairwilson commented Oct 18, 2023

This adds a secret enrolment key and instructor key to events, if the student provides these when selecting enrol then it automatically sets their status to STUDENT (or INSTRUCTOR). The old button for request enrollment is still there if they have not received a key.

I considered hashing these keys, because they are available in the client? I really do not see it being an issue though, happy to be convinced otherwise.

enrolkey

closes #88

Copy link
Contributor

@martinjrobins martinjrobins left a comment

Choose a reason for hiding this comment

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

Thanks @alasdairwilson. I really like the idea of the enrollment key, this will work really well :) I've requested a few changes below, I think the enrolment dialog would be better written as a (very simple) form. Also could you add a component test for EnrolDialog as well?

@@ -45,6 +59,39 @@ const EnrolDialog: React.FC<Props> = ({ event, show, onEnrol}) => {
})
};

const enrolWithKey = () => {
const enrolKey = (document.getElementById('enrol-key') as HTMLInputElement).value;
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't think you could use getElementByID in React because it manages its own virtual DOM?

This is basically a form, so I would use the https://react-hook-form.com/ library, which we use in other places in the codebase: eg. https://github.com/OxfordRSE/gutenberg/blob/main/components/content/Challenge.tsx

Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -57,8 +104,32 @@ const EnrolDialog: React.FC<Props> = ({ event, show, onEnrol}) => {
</Modal.Header>
<Modal.Body>
<Content markdown={event.enrol} />
You should have received an enrolment key from the course organiser:
<div className="flex">
Copy link
Contributor

Choose a reason for hiding this comment

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

Use our Stack component here: https://github.com/OxfordRSE/gutenberg/blob/main/components/ui/Stack.tsx

This is used to render a vertical or horizontal stack of components with spacing between them, e.g.

<Stack direction='row' spacing={2} className="justify-center">

lib/actions/putEvent.ts Outdated Show resolved Hide resolved
pages/api/eventGroup/[eventGroupId].ts Outdated Show resolved Hide resolved
pages/api/userOnEvent/[eventId].ts Outdated Show resolved Hide resolved
pages/event/[eventId].tsx Outdated Show resolved Hide resolved
martinjrobins
martinjrobins previously approved these changes Oct 30, 2023
Copy link
Contributor

@martinjrobins martinjrobins left a comment

Choose a reason for hiding this comment

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

looks great, couple of minor suggestions then I think we can merge it

@@ -100,6 +100,8 @@ model Event {
summary String @default("")
enrol String @default("")
content String @default("")
enrolKey String @default("")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
enrolKey String @default("")
enrolKey String @default(uuid())

Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps set this by default to a random string / uuid?, and the instructor key as well

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this would affect the migration as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ironically, by changing the enroldialog to use a form, it means you can't submit a blank string anyway (if the enrolkey is blank it wont match the undefined form submission for submitting a blank string) but I will make this change.

I had initially thought about hashing the key but this makes the edit event page significantly more complex as I would need a separate method of submitting the keys as you cant have them populated by default and therefore submitting the changes without setting a key would change the key.

I figured since that actually without the hashing there is no real layer of security; the keys are exposed in the browser memory because the Event object is there so I just left it, but yeah this change is fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

ahhh yes, probably with the form this doesn't really add much :) I agree with your thoughts re hashing, probably not worth implementing this as we don't need high security (at least I don't think we do.....)

@@ -100,6 +100,8 @@ model Event {
summary String @default("")
enrol String @default("")
content String @default("")
enrolKey String @default("")
instructorKey String @default("@mHJdxza218sxzd014s8ASDsa0axv0sdfmBJNLM=3asfdnmYHL1234adczcz") // just in case this is unset then we don't want to let blank keys let users in
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
instructorKey String @default("@mHJdxza218sxzd014s8ASDsa0axv0sdfmBJNLM=3asfdnmYHL1234adczcz") // just in case this is unset then we don't want to let blank keys let users in
instructorKey String @default(uuid())

@alasdairwilson alasdairwilson merged commit fc8d638 into main Oct 30, 2023
2 checks passed
@alasdairwilson alasdairwilson deleted the enrolment-key branch October 30, 2023 14:26
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.

better enrollment workflow
2 participants