Add scim info in update/delete user events

This commit is contained in:
adrinr 2023-03-24 16:54:13 +00:00
parent 6df08799bb
commit 648247b10e
3 changed files with 13 additions and 7 deletions

View File

@ -17,12 +17,14 @@ import {
} from "@budibase/types" } from "@budibase/types"
import { context } from "../.." import { context } from "../.."
const isScim = () => (context.getIdentity() as any)?.isScimCall
async function created(user: User, timestamp?: number) { async function created(user: User, timestamp?: number) {
const properties: UserCreatedEvent = { const properties: UserCreatedEvent = {
userId: user._id as string, userId: user._id as string,
audited: { audited: {
email: user.email, email: user.email,
viaScim: !!(context.getIdentity() as any)?.isScimCall, viaScim: isScim(),
}, },
} }
await publishEvent(Event.USER_CREATED, properties, timestamp) await publishEvent(Event.USER_CREATED, properties, timestamp)
@ -32,7 +34,8 @@ async function updated(user: User) {
const properties: UserUpdatedEvent = { const properties: UserUpdatedEvent = {
userId: user._id as string, userId: user._id as string,
audited: { audited: {
email: user.email email: user.email,
viaScim: isScim(),
}, },
} }
await publishEvent(Event.USER_UPDATED, properties) await publishEvent(Event.USER_UPDATED, properties)
@ -43,6 +46,7 @@ async function deleted(user: User) {
userId: user._id as string, userId: user._id as string,
audited: { audited: {
email: user.email, email: user.email,
viaScim: isScim(),
}, },
} }
await publishEvent(Event.USER_DELETED, properties) await publishEvent(Event.USER_DELETED, properties)

View File

@ -199,8 +199,8 @@ export enum Event {
export const AuditedEventFriendlyName: Record<Event, string | undefined> = { export const AuditedEventFriendlyName: Record<Event, string | undefined> = {
// USER // USER
[Event.USER_CREATED]: `User "{{ email }}" created{{#if viaScim}} via SCIM{{/if}}`, [Event.USER_CREATED]: `User "{{ email }}" created{{#if viaScim}} via SCIM{{/if}}`,
[Event.USER_UPDATED]: `User "{{ email }}" updated`, [Event.USER_UPDATED]: `User "{{ email }}" updated{{#if viaScim}} via SCIM{{/if}}`,
[Event.USER_DELETED]: `User "{{ email }}" deleted`, [Event.USER_DELETED]: `User "{{ email }}" deleted{{#if viaScim}} via SCIM{{/if}}`,
[Event.USER_PERMISSION_ADMIN_ASSIGNED]: `User "{{ email }}" admin role assigned`, [Event.USER_PERMISSION_ADMIN_ASSIGNED]: `User "{{ email }}" admin role assigned`,
[Event.USER_PERMISSION_ADMIN_REMOVED]: `User "{{ email }}" admin role removed`, [Event.USER_PERMISSION_ADMIN_REMOVED]: `User "{{ email }}" admin role removed`,
[Event.USER_PERMISSION_BUILDER_ASSIGNED]: `User "{{ email }}" builder role assigned`, [Event.USER_PERMISSION_BUILDER_ASSIGNED]: `User "{{ email }}" builder role assigned`,

View File

@ -4,21 +4,23 @@ export interface UserCreatedEvent extends BaseEvent {
userId: string userId: string
audited: { audited: {
email: string email: string
viaScim: boolean viaScim?: boolean
} }
} }
export interface UserUpdatedEvent extends BaseEvent { export interface UserUpdatedEvent extends BaseEvent {
userId: string userId: string
audited: { audited: {
email: string email: string,
viaScim?: boolean
} }
} }
export interface UserDeletedEvent extends BaseEvent { export interface UserDeletedEvent extends BaseEvent {
userId: string userId: string
audited: { audited: {
email: string email: string,
viaScim?: boolean
} }
} }