From 8a255f8b41d1154bbf928304f84eafd0f1c296d1 Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Mon, 27 Apr 2020 18:11:06 -0400 Subject: [PATCH] Add a basic layout for improved table granular reset --- CTFd/admin/__init__.py | 62 +++++++++++++++---- .../admin/templates/configs/appearance.html | 2 +- CTFd/themes/admin/templates/reset.html | 41 +++++++++++- 3 files changed, 89 insertions(+), 16 deletions(-) diff --git a/CTFd/admin/__init__.py b/CTFd/admin/__init__.py index 4216614..0ade465 100644 --- a/CTFd/admin/__init__.py +++ b/CTFd/admin/__init__.py @@ -14,10 +14,13 @@ from flask import ( url_for, ) -from CTFd.cache import cache, clear_config +from CTFd.cache import cache, clear_config, clear_standings, clear_pages from CTFd.models import ( Awards, + Challenges, Configs, + Notifications, + Pages, Solves, Submissions, Teams, @@ -176,19 +179,52 @@ def config(): @admins_only def reset(): if request.method == "POST": - # Truncate Users, Teams, Submissions, Solves, Notifications, Awards, Unlocks, Tracking - Tracking.query.delete() - Solves.query.delete() - Submissions.query.delete() - Awards.query.delete() - Unlocks.query.delete() - Users.query.delete() - Teams.query.delete() - set_config("setup", False) + require_setup = False + logout = False + next_url = url_for("admin.statistics") + + data = request.form + + if data.get("pages"): + Pages.query.delete() + # PageFiles + + if data.get("notifications"): + Notifications.query.delete() + + if data.get("challenges"): + Challenges.query.delete() + # ChallengeFiles + + if data.get("accounts"): + Users.query.delete() + Teams.query.delete() + require_setup = True + logout = True + + if data.get("submissions"): + Solves.query.delete() + Submissions.query.delete() + Awards.query.delete() + Unlocks.query.delete() + + if require_setup: + set_config("setup", False) + cache.clear() + logout_user() + next_url = url_for("views.setup") + db.session.commit() - cache.clear() - logout_user() + + clear_pages() + clear_standings() + clear_config() + + if logout is True: + cache.clear() + logout_user() + db.session.close() - return redirect(url_for("views.setup")) + return redirect(next_url) return render_template("admin/reset.html") diff --git a/CTFd/themes/admin/templates/configs/appearance.html b/CTFd/themes/admin/templates/configs/appearance.html index e72850e..ec1f4af 100644 --- a/CTFd/themes/admin/templates/configs/appearance.html +++ b/CTFd/themes/admin/templates/configs/appearance.html @@ -64,7 +64,7 @@ or choose to form teams. -
+
Accounts (Users, Teams, Submissions) + +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+