mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-18 06:24:23 +01:00
Fix chal deletion (#241)
* improving get_config * Fixing challenge deletion * Puts challenge deletion under utils.delete_file
This commit is contained in:
@@ -263,11 +263,9 @@ def admin_delete_chal():
|
||||
Solves.query.filter_by(chalid=challenge.id).delete()
|
||||
Keys.query.filter_by(chal=challenge.id).delete()
|
||||
files = Files.query.filter_by(chal=challenge.id).all()
|
||||
for f in files:
|
||||
utils.delete_file(f.id)
|
||||
Files.query.filter_by(chal=challenge.id).delete()
|
||||
for file in files:
|
||||
upload_folder = app.config['UPLOAD_FOLDER']
|
||||
folder = os.path.dirname(os.path.join(os.path.normpath(app.root_path), upload_folder, file.location))
|
||||
utils.rmdir(folder)
|
||||
Tags.query.filter_by(chal=challenge.id).delete()
|
||||
Challenges.query.filter_by(id=challenge.id).delete()
|
||||
db.session.commit()
|
||||
|
||||
@@ -349,8 +349,8 @@ def upload_file(file, chalid):
|
||||
return True
|
||||
|
||||
|
||||
def delete_file(filename):
|
||||
f = Files.query.filter_by(id=filename).first_or_404()
|
||||
def delete_file(file_id):
|
||||
f = Files.query.filter_by(id=file_id).first_or_404()
|
||||
upload_folder = os.path.join(app.root_path, app.config['UPLOAD_FOLDER'])
|
||||
if os.path.exists(os.path.join(upload_folder, f.location)): # Some kind of os.path.isfile issue on Windows...
|
||||
os.unlink(os.path.join(upload_folder, f.location))
|
||||
|
||||
Reference in New Issue
Block a user