Add isScim to user created event
This commit is contained in:
parent
31eaa36883
commit
6df08799bb
8 changed files with 24 additions and 6 deletions
|
@ -19,7 +19,12 @@ export function doInIdentityContext(identity: IdentityContext, task: any) {
|
|||
}
|
||||
|
||||
// used in server/worker
|
||||
export function doInUserContext(user: User, ctx: Ctx, task: any) {
|
||||
export function doInUserContext(
|
||||
user: User,
|
||||
ctx: Ctx,
|
||||
task: any,
|
||||
isScim: boolean
|
||||
) {
|
||||
const userContext: UserContext = {
|
||||
...user,
|
||||
_id: user._id as string,
|
||||
|
@ -29,6 +34,7 @@ export function doInUserContext(user: User, ctx: Ctx, task: any) {
|
|||
// filled in by koa-useragent package
|
||||
userAgent: ctx.userAgent._agent.source,
|
||||
},
|
||||
isScimCall: isScim,
|
||||
}
|
||||
return doInIdentityContext(userContext, task)
|
||||
}
|
||||
|
|
|
@ -15,13 +15,14 @@ import {
|
|||
UserUpdatedEvent,
|
||||
UserOnboardingEvent,
|
||||
} from "@budibase/types"
|
||||
import { context } from "../.."
|
||||
|
||||
async function created(user: User, timestamp?: number) {
|
||||
const properties: UserCreatedEvent = {
|
||||
userId: user._id as string,
|
||||
audited: {
|
||||
email: user.email,
|
||||
scim: !!user.scimInfo?.isSync,
|
||||
viaScim: !!(context.getIdentity() as any)?.isScimCall,
|
||||
},
|
||||
}
|
||||
await publishEvent(Event.USER_CREATED, properties, timestamp)
|
||||
|
@ -31,7 +32,7 @@ async function updated(user: User) {
|
|||
const properties: UserUpdatedEvent = {
|
||||
userId: user._id as string,
|
||||
audited: {
|
||||
email: user.email,
|
||||
email: user.email
|
||||
},
|
||||
}
|
||||
await publishEvent(Event.USER_UPDATED, properties)
|
||||
|
|
|
@ -4,6 +4,7 @@ import {
|
|||
clearCookie,
|
||||
openJwt,
|
||||
isValidInternalAPIKey,
|
||||
isScimEndpoint,
|
||||
} from "../utils"
|
||||
import { getUser } from "../cache/user"
|
||||
import { getSession, updateSessionTTL } from "../security/sessions"
|
||||
|
@ -105,6 +106,8 @@ export default function (
|
|||
apiKey = ctx.request.headers[Header.AUTHORIZATION].split(" ")[1]
|
||||
}
|
||||
|
||||
const isScimCall = isScimEndpoint(ctx)
|
||||
|
||||
const tenantId = ctx.request.headers[Header.TENANT_ID]
|
||||
let authenticated = false,
|
||||
user = null,
|
||||
|
@ -168,7 +171,7 @@ export default function (
|
|||
finalise(ctx, { authenticated, user, internal, version, publicEndpoint })
|
||||
|
||||
if (user && user.email) {
|
||||
return identity.doInUserContext(user, ctx, next)
|
||||
return identity.doInUserContext(user, ctx, next, isScimCall)
|
||||
} else {
|
||||
return next()
|
||||
}
|
||||
|
|
6
packages/backend-core/src/utils/endpointUtils.ts
Normal file
6
packages/backend-core/src/utils/endpointUtils.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
import { Ctx } from "@budibase/types"
|
||||
|
||||
const SCIM_ENDPOINTS = new RegExp(["scim/"].join("|"))
|
||||
export function isScimEndpoint(ctx: Ctx): boolean {
|
||||
return SCIM_ENDPOINTS.test(ctx.request.url)
|
||||
}
|
|
@ -1,2 +1,3 @@
|
|||
export * from "./hashing"
|
||||
export * from "./utils"
|
||||
export * from "./endpointUtils"
|
||||
|
|
|
@ -17,6 +17,7 @@ export interface UserContext extends BaseContext, User {
|
|||
tenantId: string
|
||||
account?: Account
|
||||
hostInfo: HostInfo
|
||||
isScimCall?: boolean
|
||||
}
|
||||
|
||||
export type IdentityContext = BaseContext | AccountUserContext | UserContext
|
||||
|
|
|
@ -198,7 +198,7 @@ export enum Event {
|
|||
// a user facing event or not.
|
||||
export const AuditedEventFriendlyName: Record<Event, string | undefined> = {
|
||||
// USER
|
||||
[Event.USER_CREATED]: `User "{{ email }}" created{{#if scim}} via SCIM{{/if}}`,
|
||||
[Event.USER_CREATED]: `User "{{ email }}" created{{#if viaScim}} via SCIM{{/if}}`,
|
||||
[Event.USER_UPDATED]: `User "{{ email }}" updated`,
|
||||
[Event.USER_DELETED]: `User "{{ email }}" deleted`,
|
||||
[Event.USER_PERMISSION_ADMIN_ASSIGNED]: `User "{{ email }}" admin role assigned`,
|
||||
|
|
|
@ -4,7 +4,7 @@ export interface UserCreatedEvent extends BaseEvent {
|
|||
userId: string
|
||||
audited: {
|
||||
email: string
|
||||
scim: boolean
|
||||
viaScim: boolean
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue