Skip to content

New audit_log table, and log edits to actions in the audit_log#415

Draft
yyi5708 wants to merge 1 commit into
devfrom
324-have-an-auditability-system-that-tracks-important-actions
Draft

New audit_log table, and log edits to actions in the audit_log#415
yyi5708 wants to merge 1 commit into
devfrom
324-have-an-auditability-system-that-tracks-important-actions

Conversation

@yyi5708

@yyi5708 yyi5708 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@yyi5708 yyi5708 added this to the v1.10.0 milestone Jul 23, 2026
@yyi5708
yyi5708 requested a review from andymeneely July 23, 2026 13:34
@yyi5708 yyi5708 self-assigned this Jul 23, 2026
@yyi5708 yyi5708 added the enhancement New feature or request label Jul 23, 2026
@yyi5708 yyi5708 linked an issue Jul 23, 2026 that may be closed by this pull request
@github-project-automation github-project-automation Bot moved this to Needs Planning in Portal Development Jul 23, 2026
@yyi5708 yyi5708 moved this from Needs Planning to Todo in Portal Development Jul 23, 2026
@yyi5708 yyi5708 moved this from Todo to In Progress in Portal Development Jul 23, 2026
@yyi5708
yyi5708 marked this pull request as draft July 23, 2026 13:35

@andymeneely andymeneely left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! Ok the main things are:

  • There might be some methods here that are either repeats of methods we've done elsewhere, so it might be worthwhile to either use them or move them to a more shared utility module.
  • Since the AuditLogger primarily interacts with the database anyway, I think we should keep the parameter to the routes module as it is, and AuditLogger just uses the db object. Keeps the interface simpler I think.

entity_type TEXT NOT NULL,
entity_id TEXT,
message TEXT NOT NULL,
details TEXT,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename it to details_json so future people know it's intended to be formatted using json.

Suggested change
details TEXT,
details_json TEXT,

try {
await db.query(insertQuery, params);
} catch (err) {
Logger.error(`Failed to write audit log entry: ${err.message}`);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add more context info here so we can debug easier - like the username and action type. Don't need the ENTIRE audit info filling up the log, but making it easier to search for if it fails.

@@ -9,4 +9,5 @@
.read table_sql/users.sql
.read table_sql/sponsor_notes.sql
.read table_sql/page_html.sql

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure you also add test data to this PR as well. Might be good to capture some data you generate from testing things out, then putting it into the test data.

(nothing to do with create_all_tables.sql - probably goes into test_data)

};

module.exports = (db) => {
function getActor(req) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are getActor and actorLabel methods that we do elsewhere? We've had to look these up before for other features - might be good to reuse those if possible.

}
}

function humanizeFieldName(field) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing with humanizeFieldName and displayValue as getActor - seem like methods that would be useful for all the modules to have, and maybe we had to do something like this before?


// Routes
module.exports = (db) => {
module.exports = (db, AuditLog) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure we need AuditLog to be passed here? Don't we just import it and use it? Trying to figure out why we need the new parameter for this.


db.query(updateQuery, params)
.then(() => {
let changedFields = {};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to extract this whole chunk into its own method to show that it's all auditability stuff.

const router = require("express").Router();
const DBHandler = require("../database/db");
let db = new DBHandler();
const AuditLog = require("../audit/audit_logger")(db);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the audit log is being saved in the DB, it's using the DBHandler anyway. So I don't think AuditLog needs to be passed in as a parameter - just import it in the other files and use the db object from there. This is related to my above comment about (db, AuditLog)

@github-project-automation github-project-automation Bot moved this from In Progress to Under Review in Portal Development Jul 23, 2026
@andymeneely andymeneely changed the title Auditability System New audit_log table, and initial calls to the audit log Jul 23, 2026
@andymeneely andymeneely changed the title New audit_log table, and initial calls to the audit log New audit_log table, and log edits to actions in the audit_log Jul 23, 2026
@yyi5708 yyi5708 moved this from Under Review to In Progress in Portal Development Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Have an auditability system that tracks important actions

2 participants