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 { processors } from "./processors"
|
||||||
import identification from "./identification"
|
import identification from "./identification"
|
||||||
import * as backfill from "./backfill"
|
import * as backfill from "./backfill"
|
||||||
|
@ -7,12 +7,19 @@ import { publishAsyncEvent } from "./asyncEvents"
|
||||||
export const publishEvent = async (
|
export const publishEvent = async (
|
||||||
event: Event,
|
event: Event,
|
||||||
properties: any,
|
properties: any,
|
||||||
timestamp?: string | number
|
timestamp?: string | number,
|
||||||
|
identityOverride?: Identity
|
||||||
) => {
|
) => {
|
||||||
// in future this should use async events via a distributed queue.
|
// 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
|
// no backfill - send the event and exit
|
||||||
if (!backfilling) {
|
if (!backfilling) {
|
||||||
// send off async events if required
|
// send off async events if required
|
||||||
|
|
|
@ -5,13 +5,19 @@ import {
|
||||||
AccountCreatedEvent,
|
AccountCreatedEvent,
|
||||||
AccountDeletedEvent,
|
AccountDeletedEvent,
|
||||||
AccountVerifiedEvent,
|
AccountVerifiedEvent,
|
||||||
|
Identity,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
async function created(account: Account) {
|
async function created(account: Account, identityOverride?: Identity) {
|
||||||
const properties: AccountCreatedEvent = {
|
const properties: AccountCreatedEvent = {
|
||||||
tenantId: account.tenantId,
|
tenantId: account.tenantId,
|
||||||
}
|
}
|
||||||
await publishEvent(Event.ACCOUNT_CREATED, properties)
|
await publishEvent(
|
||||||
|
Event.ACCOUNT_CREATED,
|
||||||
|
properties,
|
||||||
|
undefined,
|
||||||
|
identityOverride
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleted(account: Account) {
|
async function deleted(account: Account) {
|
||||||
|
|
Loading…
Reference in New Issue