diff options
author | Frederick Yin <fkfd@fkfd.me> | 2021-10-31 17:03:19 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2021-10-31 17:13:01 +0800 |
commit | 7644830f34f3bd81d3b21b2d05710fbc91f20eb6 (patch) | |
tree | d20b89bacc2cec650e00d3f1e9ba68d8d699356b /jimbrella/admin.py | |
parent | 59c899e372a6d5e0309c585de43df015f775ebe7 (diff) |
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.
Diffstat (limited to 'jimbrella/admin.py')
-rw-r--r-- | jimbrella/admin.py | 16 |
1 files changed, 14 insertions, 2 deletions
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")) |