From 7644830f34f3bd81d3b21b2d05710fbc91f20eb6 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Sun, 31 Oct 2021 17:03:19 +0800 Subject: Implement ADMIN_MODIFY_DB logs When an admin requests /admin/umbrella/edit and the request succeeds, an ADMIN_MODIFY_DB log is kept. `Database.update` will keep track of the updated columns. --- jimbrella/admin.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'jimbrella/admin.py') diff --git a/jimbrella/admin.py b/jimbrella/admin.py index 9a9f6c8..eaf0e54 100644 --- a/jimbrella/admin.py +++ b/jimbrella/admin.py @@ -72,9 +72,8 @@ def umbrellas_edit(): ]: data[key] = request.form.get(key) - error = None try: - db.update(data) + diff = db.update(data) except UmbrellaValueError as e: # invalid field is in `e.message`. return redirect( @@ -85,6 +84,19 @@ def umbrellas_edit(): except UmbrellaNotFoundError: pass # impossible on web console + for column, value_pair in diff.items(): + past, new = value_pair + admin_log.log( + "ADMIN_MODIFY_DB", + { + "admin_name": session["username"], + "serial": data["serial"], + "column": column, + "past_value": past, + "new_value": new, + }, + ) + return redirect(url_for("admin.umbrellas")) -- cgit v1.2.3