Event on delete
This commit is contained in:
parent
cbadf69a29
commit
26f077cc1c
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -123,3 +123,4 @@ jest.spyOn(events.plugin, "deleted")
|
|||
|
||||
jest.spyOn(events.scim, "SCIMUserCreated")
|
||||
jest.spyOn(events.scim, "SCIMUserUpdated")
|
||||
jest.spyOn(events.scim, "SCIMUserDeleted")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -7,3 +7,6 @@ export interface ScimUserCreatedEvent extends BaseEvent {
|
|||
export interface ScimUserUpdatedEvent extends BaseEvent {
|
||||
email: string
|
||||
}
|
||||
export interface ScimUserDeletedEvent extends BaseEvent {
|
||||
userId: string
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue