From 18dd715276fc32138282bc9cf129384fb75e6f47 Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Wed, 22 Nov 2017 03:33:48 -0500 Subject: [PATCH] Workshop mode (#477) * Implementing workshop mode * Fixing a bug in /chals/solves where challenges with 0 solves weren't hidden. * Spinner errors are now 20vh down instead of 210px down * Users now use their private team endpoint at /team instead of /team/ --- .travis.yml | 2 +- CTFd/admin/__init__.py | 8 +++- CTFd/challenges.py | 19 +++++++-- CTFd/themes/admin/templates/config.html | 10 +++++ CTFd/themes/original/static/css/style.css | 2 +- CTFd/themes/original/templates/base.html | 5 ++- CTFd/utils.py | 2 +- CTFd/views.py | 5 +++ tests/user/test_challenges.py | 25 ++++++++++-- tests/user/test_user_facing.py | 50 +++++++++++++++++++++++ 10 files changed, 115 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 08f66424..202fc150 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,4 +15,4 @@ before_script: - psql -c 'create database ctfd;' -U postgres script: - pep8 --ignore E501,E712 CTFd/ tests/ - - nosetests + - nosetests -d diff --git a/CTFd/admin/__init__.py b/CTFd/admin/__init__.py index 2504e9e7..93b05496 100644 --- a/CTFd/admin/__init__.py +++ b/CTFd/admin/__init__.py @@ -117,6 +117,7 @@ def admin_config(): mail_tls = bool(request.form.get('mail_tls', None)) mail_ssl = bool(request.form.get('mail_ssl', None)) mail_useauth = bool(request.form.get('mail_useauth', None)) + workshop_mode = bool(request.form.get('workshop_mode', None)) except (ValueError, TypeError): view_challenges_unregistered = None view_scoreboard_if_authed = None @@ -128,6 +129,7 @@ def admin_config(): mail_tls = None mail_ssl = None mail_useauth = None + workshop_mode = None finally: view_challenges_unregistered = utils.set_config('view_challenges_unregistered', view_challenges_unregistered) view_scoreboard_if_authed = utils.set_config('view_scoreboard_if_authed', view_scoreboard_if_authed) @@ -139,6 +141,7 @@ def admin_config(): mail_tls = utils.set_config('mail_tls', mail_tls) mail_ssl = utils.set_config('mail_ssl', mail_ssl) mail_useauth = utils.set_config('mail_useauth', mail_useauth) + workshop_mode = utils.set_config('workshop_mode', workshop_mode) mail_server = utils.set_config("mail_server", request.form.get('mail_server', None)) mail_port = utils.set_config("mail_port", request.form.get('mail_port', None)) @@ -207,6 +210,8 @@ def admin_config(): prevent_name_change = utils.get_config('prevent_name_change') verify_emails = utils.get_config('verify_emails') + workshop_mode = utils.get_config('workshop_mode') + db.session.commit() db.session.close() @@ -236,4 +241,5 @@ def admin_config(): prevent_name_change=prevent_name_change, verify_emails=verify_emails, view_after_ctf=view_after_ctf, - themes=themes) + themes=themes, + workshop_mode=workshop_mode) diff --git a/CTFd/challenges.py b/CTFd/challenges.py index 9ced0812..f7831155 100644 --- a/CTFd/challenges.py +++ b/CTFd/challenges.py @@ -153,6 +153,11 @@ def solves_per_chal(): if not utils.user_can_view_challenges(): return redirect(url_for('auth.login', next=request.path)) + chals = Challenges.query\ + .filter(or_(Challenges.hidden != True, Challenges.hidden == None))\ + .order_by(Challenges.value)\ + .all() + solves_sub = db.session.query( Solves.chalid, db.func.count(Solves.chalid).label('solves') @@ -168,15 +173,21 @@ def solves_per_chal(): ) \ .join(Challenges, solves_sub.columns.chalid == Challenges.id).all() - json = {} + data = {} if utils.hide_scores(): for chal, count, name in solves: - json[chal] = -1 + data[chal] = -1 + for c in chals: + if c.id not in data: + data[c.id] = -1 else: for chal, count, name in solves: - json[chal] = count + data[chal] = count + for c in chals: + if c.id not in data: + data[c.id] = 0 db.session.close() - return jsonify(json) + return jsonify(data) @challenges.route('/solves') diff --git a/CTFd/themes/admin/templates/config.html b/CTFd/themes/admin/templates/config.html index 00a074b3..d93d9d65 100644 --- a/CTFd/themes/admin/templates/config.html +++ b/CTFd/themes/admin/templates/config.html @@ -53,6 +53,16 @@ +
+ +
+