From 134226636834cc961f08092ce53947c419ad24ea Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 14 Jan 2021 16:58:21 +0100 Subject: [PATCH] events: include full group in event notification --- authentik/events/api/notification_trigger.py | 1 + swagger.yaml | 95 ++++++++++++++++---- web/src/api/EventNotification.ts | 25 ++++++ web/src/api/EventTriggers.ts | 3 +- web/src/api/Groups.ts | 13 +++ web/src/pages/events/TriggerListPage.ts | 2 +- 6 files changed, 121 insertions(+), 18 deletions(-) create mode 100644 web/src/api/EventNotification.ts create mode 100644 web/src/api/Groups.ts diff --git a/authentik/events/api/notification_trigger.py b/authentik/events/api/notification_trigger.py index b059b3ca6..d8f666d02 100644 --- a/authentik/events/api/notification_trigger.py +++ b/authentik/events/api/notification_trigger.py @@ -11,6 +11,7 @@ class NotificationTriggerSerializer(ModelSerializer): class Meta: model = NotificationTrigger + depth = 2 fields = [ "pk", "name", diff --git a/swagger.yaml b/swagger.yaml index 7f0b28359..079ca7f17 100755 --- a/swagger.yaml +++ b/swagger.yaml @@ -7663,7 +7663,6 @@ definitions: description: NotificationTrigger Serializer required: - name - - transports type: object properties: pk: @@ -7676,17 +7675,35 @@ definitions: type: string minLength: 1 transports: - description: Select which transports should be used to notify the user. If - none are selected, the notification will only be shown in the authentik - UI. + description: '' type: array items: - description: Select which transports should be used to notify the user. - If none are selected, the notification will only be shown in the authentik - UI. - type: string - format: uuid - uniqueItems: true + description: Action which is executed when a Trigger matches + required: + - name + - mode + type: object + properties: + uuid: + title: Uuid + type: string + format: uuid + readOnly: true + name: + title: Name + type: string + minLength: 1 + mode: + title: Mode + type: string + enum: + - webhook + - webhook_slack + - email + webhook_url: + title: Webhook url + type: string + readOnly: true severity: title: Severity description: Controls which severity level the created notifications will @@ -7697,12 +7714,58 @@ definitions: - warning - alert group: - title: Group - description: Define which group of users this notification should be sent - and shown to. If left empty, Notification won't ben sent. - type: string - format: uuid - x-nullable: true + description: Custom Group model which supports a basic hierarchy + required: + - name + type: object + properties: + group_uuid: + title: Group uuid + type: string + format: uuid + readOnly: true + name: + title: Name + type: string + maxLength: 80 + minLength: 1 + is_superuser: + title: Is superuser + description: Users added to this group will be superusers. + type: boolean + attributes: + title: Attributes + type: object + parent: + description: Custom Group model which supports a basic hierarchy + required: + - name + - parent + type: object + properties: + group_uuid: + title: Group uuid + type: string + format: uuid + readOnly: true + name: + title: Name + type: string + maxLength: 80 + minLength: 1 + is_superuser: + title: Is superuser + description: Users added to this group will be superusers. + type: boolean + attributes: + title: Attributes + type: object + parent: + title: Parent + type: string + format: uuid + readOnly: true + readOnly: true Stage: title: Stage obj description: Stage Serializer diff --git a/web/src/api/EventNotification.ts b/web/src/api/EventNotification.ts new file mode 100644 index 000000000..a33af27a5 --- /dev/null +++ b/web/src/api/EventNotification.ts @@ -0,0 +1,25 @@ +import { DefaultClient, QueryArguments, PBResponse } from "./Client"; + +export class Notification { + pk: string; + name: string; + mode: string; + mode_verbose: string; + webhook_url: string; + + constructor() { + throw Error(); + } + + static get(pk: string): Promise { + return DefaultClient.fetch(["events", "transports", pk]); + } + + static list(filter?: QueryArguments): Promise> { + return DefaultClient.fetch>(["events", "transports"], filter); + } + + static adminUrl(rest: string): string { + return `/administration/events/transports/${rest}`; + } +} diff --git a/web/src/api/EventTriggers.ts b/web/src/api/EventTriggers.ts index f8654ded5..a80f74fad 100644 --- a/web/src/api/EventTriggers.ts +++ b/web/src/api/EventTriggers.ts @@ -1,11 +1,12 @@ import { DefaultClient, QueryArguments, PBResponse } from "./Client"; +import { Group } from "./Groups"; export class Trigger { pk: string; name: string; transports: string[]; severity: string; - group?: string; + group?: Group; constructor() { throw Error(); diff --git a/web/src/api/Groups.ts b/web/src/api/Groups.ts new file mode 100644 index 000000000..666635924 --- /dev/null +++ b/web/src/api/Groups.ts @@ -0,0 +1,13 @@ +export class Group { + + group_uuid: string; + name: string; + is_superuser: boolean; + attributes: object; + parent?: Group; + + constructor() { + throw Error(); + } + +} diff --git a/web/src/pages/events/TriggerListPage.ts b/web/src/pages/events/TriggerListPage.ts index 046f650b9..1bad8b87e 100644 --- a/web/src/pages/events/TriggerListPage.ts +++ b/web/src/pages/events/TriggerListPage.ts @@ -50,7 +50,7 @@ export class TriggerListPage extends TablePage { return [ html`${item.name}`, html`${item.severity}`, - html`${item.group || gettext("None (trigger disabled)")}`, + html`${item.group?.name || gettext("None (trigger disabled)")}`, html`