Event on delete

This commit is contained in:
adrinr 2023-03-24 14:31:12 +00:00
parent cbadf69a29
commit 26f077cc1c
5 changed files with 25 additions and 1 deletions

View File

@ -2,6 +2,7 @@ import { publishEvent } from "../events"
import {
Event,
ScimUserCreatedEvent,
ScimUserDeletedEvent,
ScimUserUpdatedEvent,
} from "@budibase/types"
@ -25,7 +26,15 @@ async function SCIMUserUpdated(props: {
await publishEvent(Event.SCIM_USER_UPDATED, properties, props.timestamp)
}
async function SCIMUserDeleted(props: { userId: string }) {
const properties: ScimUserDeletedEvent = {
userId: props.userId,
}
await publishEvent(Event.SCIM_USER_DELETED, properties)
}
export default {
SCIMUserCreated,
SCIMUserUpdated,
SCIMUserDeleted,
}

View File

@ -123,3 +123,4 @@ jest.spyOn(events.plugin, "deleted")
jest.spyOn(events.scim, "SCIMUserCreated")
jest.spyOn(events.scim, "SCIMUserUpdated")
jest.spyOn(events.scim, "SCIMUserDeleted")

View File

@ -188,6 +188,7 @@ export enum Event {
// SCIM
SCIM_USER_CREATED = "scim:user:created",
SCIM_USER_UPDATED = "scim:user:updated",
SCIM_USER_DELETED = "scim:user:deleted",
}
// all events that are not audited have been added to this record as undefined, this means
@ -372,6 +373,7 @@ export const AuditedEventFriendlyName: Record<Event, string | undefined> = {
// SCIM
[Event.SCIM_USER_CREATED]: `SCIM user "{{ email }}" created`,
[Event.SCIM_USER_UPDATED]: `SCIM user "{{ email }}" updated`,
[Event.SCIM_USER_DELETED]: `SCIM user "{{ email }}" deleted`,
}
// properties added at the final stage of the event pipeline

View File

@ -7,3 +7,6 @@ export interface ScimUserCreatedEvent extends BaseEvent {
export interface ScimUserUpdatedEvent extends BaseEvent {
email: string
}
export interface ScimUserDeletedEvent extends BaseEvent {
userId: string
}

View File

@ -438,7 +438,7 @@ describe("/api/global/scim/v2/users", () => {
expect(persistedUser).toEqual(expectedScimUser)
})
it.only("an event is dispatched", async () => {
it("an event is dispatched", async () => {
const body: ScimUpdateRequest = {
schemas: ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
Operations: [
@ -498,5 +498,14 @@ describe("/api/global/scim/v2/users", () => {
it("an non existing user can not be deleted", async () => {
await deleteScimUser(structures.uuid(), { expect: 404 })
})
it("an event is dispatched", async () => {
await deleteScimUser(user.id, { expect: 204 })
expect(events.scim.SCIMUserDeleted).toBeCalledTimes(1)
expect(events.scim.SCIMUserDeleted).toBeCalledWith({
userId: user.id,
})
})
})
})