From 79ad434d41e9f4ac987070fa223565ef9b5b4caa Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Mon, 26 Jun 2023 19:27:27 -0400 Subject: [PATCH] Add a rough implementation of improving the challenge preview --- CTFd/admin/challenges.py | 44 ++++ .../admin/templates/challenges/preview.html | 209 ++++++++++++++++++ 2 files changed, 253 insertions(+) create mode 100644 CTFd/themes/admin/templates/challenges/preview.html diff --git a/CTFd/admin/challenges.py b/CTFd/admin/challenges.py index 973e7ca3..cef1360f 100644 --- a/CTFd/admin/challenges.py +++ b/CTFd/admin/challenges.py @@ -71,6 +71,50 @@ def challenges_detail(challenge_id): ) +from CTFd.utils.security.signing import serialize +from CTFd.utils.user import ( + get_current_team, + get_current_user, +) +from CTFd.schemas.tags import TagSchema + +@admin.route("/admin/challenges/preview/") +@admins_only +def challenges_preview(challenge_id): + challenge = Challenges.query.filter_by(id=challenge_id).first_or_404() + chal_class = get_chal_class(challenge.type) + user = get_current_user() + team = get_current_team() + + files = [] + for f in challenge.files: + token = { + "user_id": user.id, + "team_id": team.id if team else None, + "file_id": f.id, + } + files.append( + url_for("views.files", path=f.location, token=serialize(token)) + ) + + tags = [ + tag["value"] for tag in TagSchema("user", many=True).dump(challenge.tags).data + ] + + content = render_template( + chal_class.templates["view"].lstrip("/"), + solves=None, + solved_by_me=False, + files=files, + tags=tags, + hints=challenge.hints, + max_attempts=challenge.max_attempts, + attempts=0, + challenge=challenge, + ) + return render_template("admin/challenges/preview.html", content=content) + + @admin.route("/admin/challenges/new") @admins_only def challenges_new(): diff --git a/CTFd/themes/admin/templates/challenges/preview.html b/CTFd/themes/admin/templates/challenges/preview.html new file mode 100644 index 00000000..0d8b7c17 --- /dev/null +++ b/CTFd/themes/admin/templates/challenges/preview.html @@ -0,0 +1,209 @@ +{% extends "page.html" %} + +{% block content %} +{{ super() }} +

+ Preview may be slightly different from the user-facing implementation +

+{% endblock %} + +{% block scripts %} + {% if "beta" in Configs.ctf_theme %} + {{ Assets.js("assets/js/challenges.js") }} + {% else %} + + {% endif %} +{% endblock %} \ No newline at end of file