recording note content and title changes to audit_log

This commit is contained in:
azivner 2017-09-30 21:18:23 -04:00
parent 470e1fc19f
commit 569f7a392d
4 changed files with 19 additions and 2 deletions

2
TODO
View File

@ -1,7 +1,7 @@
- logout detection
- conflict detection - conflict detection
- note title and content changes are not in audit_log table - note title and content changes are not in audit_log table
- deleting cloned nodes ends with 500 (probably only on folders) - deleting cloned nodes ends with 500 (probably only on folders)
- what links here - what links here
- recent changes - link to note should lead to the revision - recent changes - link to note should lead to the revision
- db upgrade / migration - db upgrade / migration
- dates should be stored in UTC to work correctly with time zones

View File

@ -1,4 +1,5 @@
UPDATE_CONTENT = 'CONTENT' UPDATE_CONTENT = 'CONTENT'
UPDATE_TITLE = 'TITLE'
CHANGE_POSITION = 'POSITION' CHANGE_POSITION = 'POSITION'
CREATE_NOTE = 'CREATE' CREATE_NOTE = 'CREATE'
DELETE_NOTE = 'DELETE' DELETE_NOTE = 'DELETE'

View File

@ -10,7 +10,7 @@ from flask_login import login_required
from sql import delete from sql import delete
from sql import execute, insert, commit from sql import execute, insert, commit
from sql import getResults, getSingleResult, getOption, addAudit from sql import getResults, getSingleResult, getOption, addAudit, deleteRecentAudits
import audit_category import audit_category
@ -68,6 +68,14 @@ def updateNote(note_id):
now now
]) ])
if note['detail']['note_title'] != detail['note_title']:
deleteRecentAudits(audit_category.UPDATE_TITLE, request, note_id)
addAudit(audit_category.UPDATE_TITLE, request, note_id)
if note['detail']['note_text'] != detail['note_text']:
deleteRecentAudits(audit_category.UPDATE_CONTENT, request, note_id)
addAudit(audit_category.UPDATE_CONTENT, request, note_id)
if note['detail']['encryption'] != detail['encryption']: if note['detail']['encryption'] != detail['encryption']:
addAudit(audit_category.ENCRYPTION, request, note_id, detail['encryption'], note['detail']['encryption']) addAudit(audit_category.ENCRYPTION, request, note_id, detail['encryption'], note['detail']['encryption'])

View File

@ -46,6 +46,14 @@ def addAudit(category, request = None, note_id = None, change_from = None, chang
execute("INSERT INTO audit_log (date_modified, category, browser_id, note_id, change_from, change_to, comment)" execute("INSERT INTO audit_log (date_modified, category, browser_id, note_id, change_from, change_to, comment)"
" VALUES (?, ?, ?, ?, ?, ?, ?)", [now, category, browser_id, note_id, change_from, change_to, comment]) " VALUES (?, ?, ?, ?, ?, ?, ?)", [now, category, browser_id, note_id, change_from, change_to, comment])
def deleteRecentAudits(category, request, note_id):
browser_id = request.headers['x-browser-id']
delete_cutoff = math.floor(time.time()) - 10 * 60;
execute("DELETE FROM audit_log WHERE category = ? AND browser_id = ? AND note_id = ? AND date_modified > ?",
[category, browser_id, note_id, delete_cutoff])
def delete(tablename, note_id): def delete(tablename, note_id):
execute("DELETE FROM " + tablename + " WHERE note_id = ?", [note_id]) execute("DELETE FROM " + tablename + " WHERE note_id = ?", [note_id])