-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow course material viewers to view closed chapters
- Loading branch information
Showing
18 changed files
with
204 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -331,17 +331,29 @@ pub async fn authorize_access_to_tmc_server( | |
)) | ||
} | ||
|
||
/** Can be used to check whether user is allowed to view some course material */ | ||
pub async fn can_user_view_not_open_chapter( | ||
/** Can be used to check whether user is allowed to view some course material. Chapters can be closed and and limited to certain people only. */ | ||
pub async fn can_user_view_chapter( | ||
conn: &mut PgConnection, | ||
user_id: Option<Uuid>, | ||
course_id: Uuid, | ||
course_id: Option<Uuid>, | ||
chapter_id: Option<Uuid>, | ||
) -> Result<bool, ControllerError> { | ||
if user_id.is_none() { | ||
return Ok(false); | ||
if let Some(course_id) = course_id { | ||
if let Some(chapter_id) = chapter_id { | ||
if !models::chapters::is_open(&mut *conn, chapter_id).await? { | ||
if user_id.is_none() { | ||
return Ok(false); | ||
} | ||
// If the user has been granted access to view the material, then they can see the unopened chapters too | ||
// This is important because sometimes teachers wish to test unopened chapters with real students | ||
let permission = | ||
authorize(conn, Act::ViewMaterial, user_id, Res::Course(course_id)).await; | ||
|
||
return Ok(permission.is_ok()); | ||
} | ||
} | ||
} | ||
let permission = authorize(conn, Act::Edit, user_id, Res::Course(course_id)).await; | ||
Ok(permission.is_ok()) | ||
Ok(true) | ||
} | ||
|
||
/** | ||
|
@@ -404,10 +416,10 @@ pub async fn authorize_with_fetched_list_of_roles( | |
// for some resources, we need to get more information from the database | ||
match resource { | ||
Resource::Chapter(id) => { | ||
// if trying to View a chapter that is not open, check for permission to Teach | ||
// if trying to View a chapter that is not open, check for permission to view the material | ||
let action = | ||
if matches!(action, Action::View) && !models::chapters::is_open(conn, id).await? { | ||
Action::Teach | ||
Action::ViewMaterial | ||
} else { | ||
action | ||
}; | ||
|
@@ -869,6 +881,8 @@ pub async fn authenticate_test_user( | |
models::users::get_by_email(conn, "[email protected]").await? | ||
} else if email == "[email protected]" && password == "language.teacher" { | ||
models::users::get_by_email(conn, "[email protected]").await? | ||
} else if email == "[email protected]" && password == "material.viewer" { | ||
models::users::get_by_email(conn, "[email protected]").await? | ||
} else if email == "[email protected]" && password == "user" { | ||
models::users::get_by_email(conn, "[email protected]").await? | ||
} else if email == "[email protected]" && password == "assistant" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
services/headless-lms/server/src/programs/seed/seed_certificate_fonts.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.