Ensure image files & Record can be cleaned when a user is removed
This commit is contained in:
7
app.py
7
app.py
@@ -162,6 +162,13 @@ def FUN_delete_user(id):
|
|||||||
if session.get("current_user", None) == "ADMIN":
|
if session.get("current_user", None) == "ADMIN":
|
||||||
if id == "ADMIN": # ADMIN account can't be deleted.
|
if id == "ADMIN": # ADMIN account can't be deleted.
|
||||||
return abort(403)
|
return abort(403)
|
||||||
|
|
||||||
|
# [1] Delete this user's images in image pool
|
||||||
|
images_to_remove = [x[0] for x in list_images_for_user(id)]
|
||||||
|
for f in images_to_remove:
|
||||||
|
image_to_delete_from_pool = [y for y in [x for x in os.listdir(app.config['UPLOAD_FOLDER'])] if y.split("-", 1)[0] == f][0]
|
||||||
|
os.remove(os.path.join(app.config['UPLOAD_FOLDER'], image_to_delete_from_pool))
|
||||||
|
# [2] Delele the records in database files
|
||||||
delete_user_from_db(id)
|
delete_user_from_db(id)
|
||||||
return(redirect(url_for("FUN_admin")))
|
return(redirect(url_for("FUN_admin")))
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -42,7 +42,9 @@ def delete_user_from_db(id):
|
|||||||
_conn.commit()
|
_conn.commit()
|
||||||
_conn.close()
|
_conn.close()
|
||||||
|
|
||||||
# when we delete a user from database USERS, we also need to delete all his or her images data from database IMAGES
|
# when we delete a user from database USERS, we also need to
|
||||||
|
# [1] delete all his or her images from image pool (done in app.py)
|
||||||
|
# [2] delete all his or her images records from database IMAGES
|
||||||
_conn = sqlite3.connect(image_db_file_location)
|
_conn = sqlite3.connect(image_db_file_location)
|
||||||
_c = _conn.cursor()
|
_c = _conn.cursor()
|
||||||
_c.execute("delete from images where owner = '" + id + "';")
|
_c.execute("delete from images where owner = '" + id + "';")
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 208 KiB After Width: | Height: | Size: 208 KiB |
Reference in New Issue
Block a user