Delete files when resetting pages and challenges

table-granular-admin-reset
Kevin Chung 2020-04-28 02:44:24 -04:00
parent 1d33ed4cb2
commit 696872fee5
1 changed files with 10 additions and 2 deletions

View File

@ -36,6 +36,7 @@ from CTFd.utils.exports import export_ctf as export_ctf_util
from CTFd.utils.exports import import_ctf as import_ctf_util from CTFd.utils.exports import import_ctf as import_ctf_util
from CTFd.utils.helpers import get_errors from CTFd.utils.helpers import get_errors
from CTFd.utils.security.auth import logout_user from CTFd.utils.security.auth import logout_user
from CTFd.utils.uploads import delete_file
from CTFd.utils.user import is_admin from CTFd.utils.user import is_admin
admin = Blueprint("admin", __name__) admin = Blueprint("admin", __name__)
@ -185,15 +186,22 @@ def reset():
data = request.form data = request.form
if data.get("pages"): if data.get("pages"):
_pages = Pages.query.all()
for p in _pages:
for f in p.files:
delete_file(file_id=f.id)
Pages.query.delete() Pages.query.delete()
# PageFiles
if data.get("notifications"): if data.get("notifications"):
Notifications.query.delete() Notifications.query.delete()
if data.get("challenges"): if data.get("challenges"):
_challenges = Challenges.query.all()
for c in _challenges:
for f in c.files:
delete_file(file_id=f.id)
Challenges.query.delete() Challenges.query.delete()
# ChallengeFiles
if data.get("accounts"): if data.get("accounts"):
Users.query.delete() Users.query.delete()