Commit 72dbee11 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Make teacher information page configurable in config file

parent 333b7ba1
Pipeline #636 passed with stage
in 12 minutes and 40 seconds
...@@ -18,6 +18,7 @@ pub struct Config { ...@@ -18,6 +18,7 @@ pub struct Config {
pub cookie_signing_secret: Option<String>, pub cookie_signing_secret: Option<String>,
pub disable_results_page: Option<bool>, pub disable_results_page: Option<bool>,
pub server_message: Option<String>, pub server_message: Option<String>,
pub teacher_page: Option<String>,
} }
#[derive(StructOpt, Debug)] #[derive(StructOpt, Debug)]
...@@ -58,6 +59,10 @@ pub struct Opt { ...@@ -58,6 +59,10 @@ pub struct Opt {
/// Disable results page to reduce load on the server /// Disable results page to reduce load on the server
#[structopt(long = "disable-results-page")] #[structopt(long = "disable-results-page")]
pub disableresultspage: bool, pub disableresultspage: bool,
/// Teacher page in task directory
#[structopt(short = "t", long = "teacherpage")]
pub teacherpage: Option<String>,
} }
pub fn read_config_from_file(file: &Path) -> Config { pub fn read_config_from_file(file: &Path) -> Config {
......
...@@ -1030,7 +1030,7 @@ pub fn edit_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id: ...@@ -1030,7 +1030,7 @@ pub fn edit_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id:
Ok(result) Ok(result)
} }
pub fn teacher_infos<T: MedalConnection>(conn: &T, session_token: &str) -> MedalValueResult { pub fn teacher_infos<T: MedalConnection>(conn: &T, session_token: &str, teacher_page: Option<&str>) -> MedalValueResult {
let session = conn.get_session(&session_token).ensure_logged_in().ok_or(MedalError::NotLoggedIn)?; let session = conn.get_session(&session_token).ensure_logged_in().ok_or(MedalError::NotLoggedIn)?;
if !session.is_teacher { if !session.is_teacher {
return Err(MedalError::AccessDenied); return Err(MedalError::AccessDenied);
...@@ -1038,7 +1038,11 @@ pub fn teacher_infos<T: MedalConnection>(conn: &T, session_token: &str) -> Medal ...@@ -1038,7 +1038,11 @@ pub fn teacher_infos<T: MedalConnection>(conn: &T, session_token: &str) -> Medal
let mut data = json_val::Map::new(); let mut data = json_val::Map::new();
fill_user_data(&session, &mut data); fill_user_data(&session, &mut data);
if let Some(teacher_page) = teacher_page {
data.insert("teacher_page".to_string(), to_json(&teacher_page));
}
Ok(("teacher".to_string(), data)) Ok(("teacher".to_string(), data))
} }
......
...@@ -202,6 +202,7 @@ fn main() { ...@@ -202,6 +202,7 @@ fn main() {
// Let options override config values // Let options override config values
opt.databasefile.map(|x| config.database_file = Some(x)); opt.databasefile.map(|x| config.database_file = Some(x));
opt.databaseurl.map(|x| config.database_url = Some(x)); opt.databaseurl.map(|x| config.database_url = Some(x));
opt.teacherpage.map(|x| config.teacher_page = Some(x));
opt.port.map(|x| config.port = Some(x)); opt.port.map(|x| config.port = Some(x));
config.no_contest_scan = if opt.nocontestscan { Some(true) } else { config.no_contest_scan }; config.no_contest_scan = if opt.nocontestscan { Some(true) } else { config.no_contest_scan };
config.open_browser = if opt.openbrowser { Some(true) } else { config.open_browser }; config.open_browser = if opt.openbrowser { Some(true) } else { config.open_browser };
......
...@@ -875,7 +875,10 @@ fn teacherinfos<C>(req: &mut Request) -> IronResult<Response> ...@@ -875,7 +875,10 @@ fn teacherinfos<C>(req: &mut Request) -> IronResult<Response>
where C: MedalConnection + std::marker::Send + 'static { where C: MedalConnection + std::marker::Send + 'static {
let session_token = req.expect_session_token()?; let session_token = req.expect_session_token()?;
let (template, data) = with_conn![core::teacher_infos, C, req, &session_token].aug(req)?; let config = req.get::<Read<SharedConfiguration>>().unwrap();
let (template, data) = with_conn![core::teacher_infos, C, req, &session_token, config.teacher_page.as_ref().map(|x| &**x)].aug(req)?;
// .as_ref().map(|x| &**x) can be written as .as_deref() since rust 1.40
let mut resp = Response::new(); let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok); resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
......
...@@ -2,7 +2,11 @@ ...@@ -2,7 +2,11 @@
<div class="columns"> <div class="columns">
<div class="column is-8 is-offset-2"> <div class="column is-8 is-offset-2">
<h3 class="title is-4">Lehrer-Informationen</h3> <h3 class="title is-4">Lehrer-Informationen</h3>
<iframe src="/tasks/teacher/index.html" style="height: calc(100vh - 550px); min-height:200px;"></iframe> {{#if teacher_page }}
<iframe src="/tasks/{{ teacher_page }}" style="height: calc(100vh - 550px); min-height:200px;"></iframe>
{{else}}
<em>Noch keine Informationen vorhanden</em>
{{/if}}
</div> </div>
</div> </div>
{{/inline}} {{/inline}}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment