Fix up reset ui

This commit is contained in:
Kevin Chung
2020-04-28 03:53:25 -04:00
parent aa2dd04378
commit a62b18fadb
3 changed files with 87 additions and 51 deletions

View File

@@ -24,6 +24,7 @@ from CTFd.models import (
Solves, Solves,
Submissions, Submissions,
Teams, Teams,
Tracking,
Unlocks, Unlocks,
Users, Users,
db, db,
@@ -214,6 +215,7 @@ def reset():
Submissions.query.delete() Submissions.query.delete()
Awards.query.delete() Awards.query.delete()
Unlocks.query.delete() Unlocks.query.delete()
Tracking.query.delete()
if require_setup: if require_setup:
set_config("setup", False) set_config("setup", False)

View File

@@ -15,7 +15,12 @@
<form method="POST" id="reset-ctf-form"> <form method="POST" id="reset-ctf-form">
<div class="alert alert-danger" role="alert"> <div class="alert alert-danger" role="alert">
<p> <p>
Resetting your CTF will delete the selected data <strong>PERMANENTLY</strong>. Resetting your CTFd instance allows you to bulk delete data to prepare it for other events,
classes, or otherwise get it to a clean state.
</p>
<p>
Resetting your CTFd instance will delete the selected data <strong>PERMANENTLY</strong>.
</p> </p>
<p> <p>
@@ -25,42 +30,71 @@
<span> <span>
<strong> <strong>
Create backups of all data you need by <a href="{{ url_for('admin.config', _anchor='backup') }}">creating a CTFd Export</a> Create backups of all data you need by <a href="{{ url_for('admin.config', _anchor='backup') }}">creating a CTFd Export</a>
or by copying the database and CTFd source code folder.
</strong> </strong>
</span> </span>
</div> </div>
<hr> <hr>
<div class="form-check pb-1"> <div class="form-group pb-2">
<div class="form-check">
<label class="form-check-label"> <label class="form-check-label">
<input class="form-check-input" type="checkbox" name="accounts"> Accounts (Users, Teams, Submissions) <input class="form-check-input" type="checkbox" name="accounts"> Accounts
</label> </label>
</div> </div>
<span class="text-muted">
<div class="form-check pb-1"> Deletes all user and team accounts and their associated information<br>
<label class="form-check-label"> <small>(Users, Teams, Submissions, Tracking)</small>
<input class="form-check-input" type="checkbox" name="submissions"> Submissions (Submissions, Awards, Unlocks) </span>
</label>
</div> </div>
<div class="form-check pb-1"> <div class="form-group pb-2">
<div class="form-check">
<label class="form-check-label"> <label class="form-check-label">
<input class="form-check-input" type="checkbox" name="challenges"> Challenges (Challenges, Flags, Hints, Tags, Hints) <input class="form-check-input" type="checkbox" name="submissions"> Submissions
</label> </label>
</div> </div>
<span class="text-muted">
<div class="form-check pb-1"> Deletes all records that accounts gained points or took an action<br>
<label class="form-check-label"> <small>(Submissions, Awards, Unlocks, Tracking)</small>
<input class="form-check-input" type="checkbox" name="pages"> Pages (Pages) </span>
</label>
</div> </div>
<div class="form-check pb-1"> <div class="form-group pb-2">
<div class="form-check">
<label class="form-check-label"> <label class="form-check-label">
<input class="form-check-input" type="checkbox" name="notifications"> Notifications (Notifications) <input class="form-check-input" type="checkbox" name="challenges"> Challenges
</label> </label>
</div> </div>
<span class="text-muted">
Deletes all challenges and associated data<br>
<small>(Challenges, Flags, Hints, Tags, Challenge Files)</small>
</span>
</div>
<div class="form-group pb-2">
<div class="form-check">
<label class="form-check-label">
<input class="form-check-input" type="checkbox" name="pages"> Pages
</label>
</div>
<span class="text-muted">
Deletes all pages and their associated files<br>
<small>(Pages, Page Files)</small>
</span>
</div>
<div class="form-group pb-2">
<div class="form-check">
<label class="form-check-label">
<input class="form-check-input" type="checkbox" name="notifications"> Notifications
</label>
</div>
<span class="text-muted">
Deletes all notifications<br>
<small>(Notifications)</small>
</span>
</div>
<br> <br>

View File

@@ -78,20 +78,6 @@ def test_reset():
client = login_as_user(app, name="admin", password="password") client = login_as_user(app, name="admin", password="password")
with client.session_transaction() as sess:
data = {"nonce": sess.get("nonce"), "submissions": "on"}
r = client.post("/admin/reset", data=data)
assert r.location.endswith("/admin/statistics")
assert Submissions.query.count() == 0
assert Solves.query.count() == 0
assert Fails.query.count() == 0
assert Awards.query.count() == 0
assert Unlocks.query.count() == 0
assert Users.query.count() == 11
assert Challenges.query.count() == 10
assert Flags.query.count() == 10
assert Tracking.query.count() == 11
with client.session_transaction() as sess: with client.session_transaction() as sess:
data = {"nonce": sess.get("nonce"), "pages": "on"} data = {"nonce": sess.get("nonce"), "pages": "on"}
r = client.post("/admin/reset", data=data) r = client.post("/admin/reset", data=data)
@@ -123,6 +109,20 @@ def test_reset():
assert Users.query.count() == 11 assert Users.query.count() == 11
assert Tracking.query.count() == 11 assert Tracking.query.count() == 11
with client.session_transaction() as sess:
data = {"nonce": sess.get("nonce"), "submissions": "on"}
r = client.post("/admin/reset", data=data)
assert r.location.endswith("/admin/statistics")
assert Submissions.query.count() == 0
assert Solves.query.count() == 0
assert Fails.query.count() == 0
assert Awards.query.count() == 0
assert Unlocks.query.count() == 0
assert Users.query.count() == 11
assert Challenges.query.count() == 0
assert Flags.query.count() == 0
assert Tracking.query.count() == 0
with client.session_transaction() as sess: with client.session_transaction() as sess:
data = {"nonce": sess.get("nonce"), "accounts": "on"} data = {"nonce": sess.get("nonce"), "accounts": "on"}
r = client.post("/admin/reset", data=data) r = client.post("/admin/reset", data=data)
@@ -187,21 +187,6 @@ def test_reset_team_mode():
client = login_as_user(app, name="admin", password="password") client = login_as_user(app, name="admin", password="password")
with client.session_transaction() as sess:
data = {"nonce": sess.get("nonce"), "submissions": "on"}
r = client.post("/admin/reset", data=data)
assert r.location.endswith("/admin/statistics")
assert Submissions.query.count() == 0
assert Solves.query.count() == 0
assert Fails.query.count() == 0
assert Awards.query.count() == 0
assert Unlocks.query.count() == 0
assert Teams.query.count() == 10
assert Users.query.count() == 51
assert Challenges.query.count() == 10
assert Flags.query.count() == 10
assert Tracking.query.count() == 11
with client.session_transaction() as sess: with client.session_transaction() as sess:
data = {"nonce": sess.get("nonce"), "pages": "on"} data = {"nonce": sess.get("nonce"), "pages": "on"}
r = client.post("/admin/reset", data=data) r = client.post("/admin/reset", data=data)
@@ -236,6 +221,21 @@ def test_reset_team_mode():
assert Users.query.count() == 51 assert Users.query.count() == 51
assert Tracking.query.count() == 11 assert Tracking.query.count() == 11
with client.session_transaction() as sess:
data = {"nonce": sess.get("nonce"), "submissions": "on"}
r = client.post("/admin/reset", data=data)
assert r.location.endswith("/admin/statistics")
assert Submissions.query.count() == 0
assert Solves.query.count() == 0
assert Fails.query.count() == 0
assert Awards.query.count() == 0
assert Unlocks.query.count() == 0
assert Teams.query.count() == 10
assert Users.query.count() == 51
assert Challenges.query.count() == 0
assert Flags.query.count() == 0
assert Tracking.query.count() == 0
with client.session_transaction() as sess: with client.session_transaction() as sess:
data = {"nonce": sess.get("nonce"), "accounts": "on"} data = {"nonce": sess.get("nonce"), "accounts": "on"}
r = client.post("/admin/reset", data=data) r = client.post("/admin/reset", data=data)