Commit 7004e101 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Redirect to contest if task is not accessible (either because contest not...

Redirect to contest if task is not accessible (either because contest not started yet or because contest time is up)
parent e62879bf
......@@ -720,7 +720,7 @@ pub fn save_submission<T: MedalConnection>(conn: &T, task_id: i32, session_token
Ok("{}".to_string())
}
pub fn show_task<T: MedalConnection>(conn: &T, task_id: i32, session_token: &str) -> MedalValueResult {
pub fn show_task<T: MedalConnection>(conn: &T, task_id: i32, session_token: &str) -> Result<MedalValue, i32> {
let session = conn.get_session_or_new(&session_token).unwrap();
let (t, tg, c) = conn.get_task_by_id_complete(task_id);
......@@ -748,7 +748,7 @@ pub fn show_task<T: MedalConnection>(conn: &T, task_id: i32, session_token: &str
}
match conn.get_own_participation(&session_token, c.id.expect("Value from database")) {
None => Err(MedalError::AccessDenied),
None => Err(c.id.unwrap()),
Some(participation) => {
let now = time::get_time();
let passed_secs = now.sec - participation.start.sec;
......@@ -764,9 +764,8 @@ pub fn show_task<T: MedalConnection>(conn: &T, task_id: i32, session_token: &str
let left_secs = i64::from(c.duration) * 60 - passed_secs;
if c.duration > 0 && left_secs < 0 {
Err(MedalError::AccessDenied)
Err(c.id.unwrap())
// Contest over
// TODO: Nicer message!
} else {
let (hour, min, sec) = (left_secs / 3600, left_secs / 60 % 60, left_secs % 60);
......
......@@ -703,11 +703,17 @@ fn task<C>(req: &mut Request) -> IronResult<Response>
let task_id = req.expect_int::<i32>("taskid")?;
let session_token = req.require_session_token()?;
let (template, data) = with_conn![core::show_task, C, req, task_id, &session_token].aug(req)?;
let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
Ok(resp)
match with_conn![core::show_task, C, req, task_id, &session_token] {
Ok((template, data)) => {
let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
Ok(resp)
},
Err(contest_id) => {
// Idea: Append task, and if contest can be started immediately, we can just redirect again!
Ok(Response::with((status::Found, Redirect(url_for!(req, "contest", "contestid" => format!("{}",contest_id))))))
}
}
}
fn groups<C>(req: &mut Request) -> IronResult<Response>
......
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