Merge pull request #9844 from Budibase/fix/audit-log-muli-tenant
Audit log multi-tenancy fix
This commit is contained in:
commit
a7d5f0fa7e
|
@ -8,7 +8,7 @@ import {
|
||||||
HostInfo,
|
HostInfo,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { EventProcessor } from "./types"
|
import { EventProcessor } from "./types"
|
||||||
import { getAppId } from "../../context"
|
import { getAppId, doInTenant } from "../../context"
|
||||||
import BullQueue from "bull"
|
import BullQueue from "bull"
|
||||||
import { createQueue, JobQueue } from "../../queue"
|
import { createQueue, JobQueue } from "../../queue"
|
||||||
import { isAudited } from "../../utils"
|
import { isAudited } from "../../utils"
|
||||||
|
@ -26,28 +26,30 @@ export default class AuditLogsProcessor implements EventProcessor {
|
||||||
JobQueue.AUDIT_LOG
|
JobQueue.AUDIT_LOG
|
||||||
)
|
)
|
||||||
return AuditLogsProcessor.auditLogQueue.process(async job => {
|
return AuditLogsProcessor.auditLogQueue.process(async job => {
|
||||||
let properties = job.data.properties
|
return doInTenant(job.data.tenantId, async () => {
|
||||||
if (properties.audited) {
|
let properties = job.data.properties
|
||||||
properties = {
|
if (properties.audited) {
|
||||||
...properties,
|
properties = {
|
||||||
...properties.audited,
|
...properties,
|
||||||
|
...properties.audited,
|
||||||
|
}
|
||||||
|
delete properties.audited
|
||||||
}
|
}
|
||||||
delete properties.audited
|
|
||||||
}
|
|
||||||
|
|
||||||
// this feature is disabled by default due to privacy requirements
|
// this feature is disabled by default due to privacy requirements
|
||||||
// in some countries - available as env var in-case it is desired
|
// in some countries - available as env var in-case it is desired
|
||||||
// in self host deployments
|
// in self host deployments
|
||||||
let hostInfo: HostInfo | undefined = {}
|
let hostInfo: HostInfo | undefined = {}
|
||||||
if (env.ENABLE_AUDIT_LOG_IP_ADDR) {
|
if (env.ENABLE_AUDIT_LOG_IP_ADDR) {
|
||||||
hostInfo = job.data.opts.hostInfo
|
hostInfo = job.data.opts.hostInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
await writeAuditLogs(job.data.event, properties, {
|
await writeAuditLogs(job.data.event, properties, {
|
||||||
userId: job.data.opts.userId,
|
userId: job.data.opts.userId,
|
||||||
timestamp: job.data.opts.timestamp,
|
timestamp: job.data.opts.timestamp,
|
||||||
appId: job.data.opts.appId,
|
appId: job.data.opts.appId,
|
||||||
hostInfo,
|
hostInfo,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -72,6 +74,7 @@ export default class AuditLogsProcessor implements EventProcessor {
|
||||||
appId: getAppId(),
|
appId: getAppId(),
|
||||||
hostInfo: identity.hostInfo,
|
hostInfo: identity.hostInfo,
|
||||||
},
|
},
|
||||||
|
tenantId: identity.tenantId!,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,4 +18,5 @@ export type AuditLogQueueEvent = {
|
||||||
event: Event
|
event: Event
|
||||||
properties: any
|
properties: any
|
||||||
opts: AuditWriteOpts
|
opts: AuditWriteOpts
|
||||||
|
tenantId: string
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue