From 2bdadcadeda86ba73769cf53a8fce1833bab1535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20Sigur=C3=B0arson?= Date: Fri, 26 Aug 2016 20:24:03 +0000 Subject: [PATCH] unblock stuff --- config.py | 4 ++++ routes/challenges.py | 4 ++-- utils/decorators.py | 9 +++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index d012fb0..750c0ee 100644 --- a/config.py +++ b/config.py @@ -63,6 +63,10 @@ if production: def competition_is_running(): return competition_begin < datetime.now() < competition_end + +def competition_has_started(): + return competition_begin < datetime.now() + # Don't touch these. Instead, copy secrets.example to secrets and edit that. import yaml from collections import namedtuple diff --git a/routes/challenges.py b/routes/challenges.py index 1a76bd9..ac1f2a0 100644 --- a/routes/challenges.py +++ b/routes/challenges.py @@ -10,7 +10,7 @@ challenges = Blueprint("challenges", __name__, template_folder="../templates/cha @challenges.route('/challenges/') @decorators.must_be_allowed_to("view challenges") -@decorators.competition_running_required +@decorators.competition_started_required @decorators.confirmed_email_required def index(): stages = challenge.get_stages() @@ -25,7 +25,7 @@ def index(): @challenges.route('/challenges//solves/') @decorators.must_be_allowed_to("view challenge solves") @decorators.must_be_allowed_to("view challenges") -@decorators.competition_running_required +@decorators.competition_started_required @decorators.confirmed_email_required def show_solves(challenge_id): try: diff --git a/utils/decorators.py b/utils/decorators.py index dc94d53..4171cbc 100644 --- a/utils/decorators.py +++ b/utils/decorators.py @@ -48,6 +48,15 @@ def competition_running_required(f): return f(*args, **kwargs) return decorated +def competition_started_required(f): + @wraps(f) + def decorated(*args, **kwargs): + if not config.competition_has_started() and not ("admin" in session and session["admin"]): + flash("The competition hasn't started") + return redirect(url_for('scoreboard.index')) + return f(*args, **kwargs) + return decorated + def admin_required(f): @wraps(f) def decorated(*args, **kwargs):