-
Notifications
You must be signed in to change notification settings - Fork 3
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
Make course instance joinable with a special code #1314
Changes from 2 commits
41f50df
b3f48db
ba22356
4d44af7
30a71ab
12f64e9
e853d7c
385816d
acd1b64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE course_instances DROP COLUMN join_code; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ALTER TABLE course_instances | ||
ADD COLUMN join_code varchar(1024); | ||
COMMENT ON COLUMN course_instances.join_code IS 'Regeneratable code that is used to join the course'; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE course_accesses; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CREATE TABLE course_accesses ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. join_code_uses |
||
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY, | ||
course_instance_id UUID NOT NULL REFERENCES course_instances(id), | ||
user_id UUID NOT NULL REFERENCES users(id), | ||
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), | ||
deleted_at TIMESTAMP WITH TIME ZONE | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add the updated_at column and then the trigger to update it automatically. |
||
COMMENT ON TABLE course_accesses IS 'This table is used to check if user has access to a course that is only joinable by a special code'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On this comment explain how this table is related to the course_instances.join_code. |
||
COMMENT ON COLUMN course_accesses.id IS 'A unique, stable identifier for the record.'; | ||
COMMENT ON COLUMN course_accesses.course_instance_id IS 'Course instance that the user has access to.'; | ||
COMMENT ON COLUMN course_accesses.user_id IS 'User who has the access to the course.'; | ||
COMMENT ON COLUMN course_accesses.created_at IS 'Timestamp of when the record was created'; | ||
COMMENT ON COLUMN course_accesses.deleted_at IS 'Timestamp when the record was deleted. If null, the record is not deleted.'; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ pub struct CourseInstance { | |
pub teacher_in_charge_name: String, | ||
pub teacher_in_charge_email: String, | ||
pub support_email: Option<String>, | ||
pub join_code: Option<String>, | ||
} | ||
|
||
impl CourseInstance { | ||
|
@@ -85,7 +86,8 @@ RETURNING id, | |
description, | ||
teacher_in_charge_name, | ||
teacher_in_charge_email, | ||
support_email | ||
support_email, | ||
join_code | ||
"#, | ||
pkey_policy.into_uuid(), | ||
new_course_instance.course_id, | ||
|
@@ -118,7 +120,8 @@ SELECT id, | |
description, | ||
teacher_in_charge_name, | ||
teacher_in_charge_email, | ||
support_email | ||
support_email, | ||
join_code | ||
FROM course_instances | ||
WHERE id = $1 | ||
AND deleted_at IS NULL; | ||
|
@@ -187,7 +190,8 @@ SELECT i.id, | |
i.description, | ||
i.teacher_in_charge_name, | ||
i.teacher_in_charge_email, | ||
i.support_email | ||
i.support_email, | ||
i.join_code | ||
FROM user_course_settings ucs | ||
JOIN course_instances i ON (ucs.current_course_instance_id = i.id) | ||
WHERE ucs.user_id = $1 | ||
|
@@ -221,7 +225,8 @@ SELECT i.id, | |
i.description, | ||
i.teacher_in_charge_name, | ||
i.teacher_in_charge_email, | ||
i.support_email | ||
i.support_email, | ||
i.join_code | ||
FROM course_instances i | ||
JOIN course_instance_enrollments ie ON (i.id = ie.course_id) | ||
WHERE i.course_id = $1 | ||
|
@@ -253,7 +258,8 @@ SELECT id, | |
description, | ||
teacher_in_charge_name, | ||
teacher_in_charge_email, | ||
support_email | ||
support_email, | ||
join_code | ||
FROM course_instances | ||
WHERE deleted_at IS NULL | ||
"# | ||
|
@@ -281,7 +287,8 @@ SELECT id, | |
description, | ||
teacher_in_charge_name, | ||
teacher_in_charge_email, | ||
support_email | ||
support_email, | ||
join_code | ||
FROM course_instances | ||
WHERE course_id = $1 | ||
AND deleted_at IS NULL; | ||
|
@@ -852,6 +859,25 @@ WHERE ce.course_instance_id = $1 | |
Ok(res.map(|r| r.student_duration_seconds).unwrap_or_default()) | ||
} | ||
|
||
pub async fn generate_join_code_for_course_instance( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a better function name would be |
||
conn: &mut PgConnection, | ||
course_instance_id: Uuid, | ||
join_code: String, | ||
) -> ModelResult<()> { | ||
sqlx::query!( | ||
" | ||
UPDATE course_instances | ||
SET join_code = $2 | ||
WHERE id = $1 | ||
", | ||
course_instance_id, | ||
join_code | ||
) | ||
.execute(conn) | ||
.await?; | ||
Ok(()) | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -443,6 +443,28 @@ async fn get_user_progress_for_course_instance( | |
token.authorized_ok(web::Json(user_course_instance_progress)) | ||
} | ||
|
||
/** | ||
POST /api/v0/main-frontend/course-instance/:course_instance_id/generate-join-code - Generates a code that is used as a part of URL to join course | ||
*/ | ||
#[instrument(skip(pool))] | ||
async fn generate_join_code_for_course_instance( | ||
id: web::Path<Uuid>, | ||
pool: web::Data<PgPool>, | ||
user: AuthUser, | ||
) -> ControllerResult<HttpResponse> { | ||
let mut conn = pool.acquire().await?; | ||
let token = authorize( | ||
&mut conn, | ||
Act::Edit, | ||
Some(user.id), | ||
Res::CourseInstance(*id), | ||
) | ||
.await?; | ||
let code = Uuid::new_v4().to_string(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a random string would be better. Also, we have to keep in mind that these strings should be long enough that no one can guess them, and we have to keep them easy to type. |
||
|
||
models::course_instances::generate_join_code_for_course_instance(&mut conn, *id, code).await?; | ||
token.authorized_ok(HttpResponse::Ok().finish()) | ||
} | ||
/** | ||
Add a route for each controller in this module. | ||
|
||
|
@@ -502,5 +524,9 @@ pub fn _add_routes(cfg: &mut ServiceConfig) { | |
.route( | ||
"/{course_instance_id}/default-certificate-configurations", | ||
web::get().to(certificate_configurations), | ||
) | ||
.route( | ||
"/{course_instance_id}/generate-join-code", | ||
web::post().to(generate_join_code_for_course_instance), | ||
); | ||
} |
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.
Explain the join_code_uses table.