Override identity for events sent from dispatcher
This commit is contained in:
parent
7df5e7a8a7
commit
50c0fb1f97
|
@ -1,4 +1,4 @@
|
|||
import { Event } from "@budibase/types"
|
||||
import { Event, Identity } from "@budibase/types"
|
||||
import { processors } from "./processors"
|
||||
import identification from "./identification"
|
||||
import * as backfill from "./backfill"
|
||||
|
@ -7,12 +7,19 @@ import { publishAsyncEvent } from "./asyncEvents"
|
|||
export const publishEvent = async (
|
||||
event: Event,
|
||||
properties: any,
|
||||
timestamp?: string | number
|
||||
timestamp?: string | number,
|
||||
identityOverride?: Identity
|
||||
) => {
|
||||
// in future this should use async events via a distributed queue.
|
||||
const identity = await identification.getCurrentIdentity()
|
||||
const identity =
|
||||
identityOverride || (await identification.getCurrentIdentity())
|
||||
|
||||
// Backfilling is get from the user cache, but when we override the identity cache is not available. Overrides are
|
||||
// normally performed in automatic actions or operations in async flows (BPM) where the user session is not available.
|
||||
const backfilling = identityOverride
|
||||
? false
|
||||
: await backfill.isBackfillingEvent(event)
|
||||
|
||||
const backfilling = await backfill.isBackfillingEvent(event)
|
||||
// no backfill - send the event and exit
|
||||
if (!backfilling) {
|
||||
// send off async events if required
|
||||
|
|
|
@ -5,13 +5,19 @@ import {
|
|||
AccountCreatedEvent,
|
||||
AccountDeletedEvent,
|
||||
AccountVerifiedEvent,
|
||||
Identity,
|
||||
} from "@budibase/types"
|
||||
|
||||
async function created(account: Account) {
|
||||
async function created(account: Account, identityOverride?: Identity) {
|
||||
const properties: AccountCreatedEvent = {
|
||||
tenantId: account.tenantId,
|
||||
}
|
||||
await publishEvent(Event.ACCOUNT_CREATED, properties)
|
||||
await publishEvent(
|
||||
Event.ACCOUNT_CREATED,
|
||||
properties,
|
||||
undefined,
|
||||
identityOverride
|
||||
)
|
||||
}
|
||||
|
||||
async function deleted(account: Account) {
|
||||
|
|
Loading…
Reference in New Issue