Commit 6ea1ca71 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Autostart contests only when they are running and the grade is matching. Fixes #74

parent 216d1ce8
...@@ -268,16 +268,6 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: i32, session_token ...@@ -268,16 +268,6 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: i32, session_token
let mut opt_part = conn.get_participation(&session_token, contest_id); let mut opt_part = conn.get_participation(&session_token, contest_id);
// Autostart if appropriate
// TODO: Should participation start automatically for teacher? Even before the contest start?
// Should teachers have all time access or only the same limited amount of time?
// if opt_part.is_none() && (contest.duration == 0 || session.is_teacher) {
// TODO: Should autostart only happen in the contest time?
if opt_part.is_none() && contest.duration == 0 {
conn.new_participation(&session_token, contest_id).map_err(|_| MedalError::AccessDenied)?;
opt_part = Some(Participation { contest: contest_id, user: session.id, start: time::get_time() });
}
let ci = ContestInfo { id: contest.id.unwrap(), let ci = ContestInfo { id: contest.id.unwrap(),
name: contest.name.clone(), name: contest.name.clone(),
duration: contest.duration, duration: contest.duration,
...@@ -295,6 +285,15 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: i32, session_token ...@@ -295,6 +285,15 @@ pub fn show_contest<T: MedalConnection>(conn: &T, contest_id: i32, session_token
data.insert("has_duration".to_string(), to_json(&has_duration)); data.insert("has_duration".to_string(), to_json(&has_duration));
data.insert("can_start".to_string(), to_json(&can_start)); data.insert("can_start".to_string(), to_json(&can_start));
// Autostart if appropriate
// TODO: Should participation start automatically for teacher? Even before the contest start?
// Should teachers have all time access or only the same limited amount of time?
// if opt_part.is_none() && (contest.duration == 0 || session.is_teacher) {
if opt_part.is_none() && contest.duration == 0 && constraints.contest_running && constraints.grade_matching {
conn.new_participation(&session_token, contest_id).map_err(|_| MedalError::AccessDenied)?;
opt_part = Some(Participation { contest: contest_id, user: session.id, start: time::get_time() });
}
let now = time::get_time(); let now = time::get_time();
if let Some(start) = contest.start { if let Some(start) = contest.start {
if now < start { if now < start {
......
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