Use new scim context functions

This commit is contained in:
adrinr 2023-03-27 11:10:07 +01:00
parent a5f6fddbdb
commit 04bd9dda9c
3 changed files with 17 additions and 5 deletions

View File

@ -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
}

View File

@ -6,4 +6,5 @@ export type ContextMap = {
appId?: string
identity?: IdentityContext
environmentVariables?: Record<string, string>
scimCall?: boolean
}

View File

@ -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)