Skip to content

Commit

Permalink
Merge pull request #4530 from FlowFuse/4529-auto-snapshot-user
Browse files Browse the repository at this point in the history
Use the provided user info sent to the audit endpoint to get which user is triggering an operation
  • Loading branch information
knolleary authored Sep 24, 2024
2 parents 53f3d00 + c7b7e03 commit fd45104
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions forge/routes/logging/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ module.exports = async function (app) {
const auditEvent = request.body
const event = auditEvent.event
const error = auditEvent.error
const userId = auditEvent.user ? app.db.models.User.decodeHashid(auditEvent.user) : undefined
let user = request.session?.User || null
if (!user && auditEvent?.user && typeof auditEvent.user === 'string') {
user = await app.db.models.User.byId(auditEvent.user) || null
}
const userId = user?.id || null

// first check to see if the event is a known structured event
if (event === 'start-failed') {
Expand Down Expand Up @@ -114,7 +118,7 @@ module.exports = async function (app) {
setImmediate(async () => {
// when after the response is sent & IO is done, perform the snapshot
try {
const meta = { user: request.session.User }
const meta = { user }
const options = { clean: true, setAsTarget: false }
const snapshot = await snapshotController.doInstanceAutoSnapshot(request.project, auditEvent.type, options, meta)
if (!snapshot) {
Expand Down

0 comments on commit fd45104

Please sign in to comment.