From 04bd9dda9c4a8fe6128c99aed25386cc5295d52f Mon Sep 17 00:00:00 2001 From: adrinr Date: Mon, 27 Mar 2023 11:10:07 +0100 Subject: [PATCH] Use new scim context functions --- packages/backend-core/src/context/mainContext.ts | 13 +++++++++++++ packages/backend-core/src/context/types.ts | 1 + packages/backend-core/src/events/publishers/user.ts | 8 +++----- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/backend-core/src/context/mainContext.ts b/packages/backend-core/src/context/mainContext.ts index 02ba16aa8c..8ea6324817 100644 --- a/packages/backend-core/src/context/mainContext.ts +++ b/packages/backend-core/src/context/mainContext.ts @@ -214,6 +214,13 @@ export function doInEnvironmentContext( return newContext(updates, task) } +export function doInScimContext(task: any) { + const updates: ContextMap = { + scimCall: true, + } + return newContext(updates, task) +} + export function getEnvironmentVariables() { const context = Context.get() if (!context.environmentVariables) { @@ -270,3 +277,9 @@ export function getDevAppDB(opts?: any): Database { } return getDB(conversions.getDevelopmentAppID(appId), opts) } + +export function isScimCall(): boolean { + const context = Context.get() + const scimCall = context?.scimCall + return !!scimCall +} diff --git a/packages/backend-core/src/context/types.ts b/packages/backend-core/src/context/types.ts index 78197ed528..0d8958dbd3 100644 --- a/packages/backend-core/src/context/types.ts +++ b/packages/backend-core/src/context/types.ts @@ -6,4 +6,5 @@ export type ContextMap = { appId?: string identity?: IdentityContext environmentVariables?: Record + scimCall?: boolean } diff --git a/packages/backend-core/src/events/publishers/user.ts b/packages/backend-core/src/events/publishers/user.ts index f9110f2765..cf5f041c1d 100644 --- a/packages/backend-core/src/events/publishers/user.ts +++ b/packages/backend-core/src/events/publishers/user.ts @@ -17,14 +17,12 @@ import { } from "@budibase/types" import { context } from "../.." -const isScim = () => (context.getIdentity() as any)?.isScimCall - async function created(user: User, timestamp?: number) { const properties: UserCreatedEvent = { userId: user._id as string, audited: { email: user.email, - viaScim: isScim(), + viaScim: context.isScimCall(), }, } await publishEvent(Event.USER_CREATED, properties, timestamp) @@ -35,7 +33,7 @@ async function updated(user: User) { userId: user._id as string, audited: { email: user.email, - viaScim: isScim(), + viaScim: context.isScimCall(), }, } await publishEvent(Event.USER_UPDATED, properties) @@ -46,7 +44,7 @@ async function deleted(user: User) { userId: user._id as string, audited: { email: user.email, - viaScim: isScim(), + viaScim: context.isScimCall(), }, } await publishEvent(Event.USER_DELETED, properties)