From 2190fa555be79004db0da5bdf7519a0b6654c39a Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 12 May 2021 16:41:15 +0200 Subject: [PATCH] events/api: fix error when updating transports closes #866 Signed-off-by: Jens Langhammer --- authentik/events/api/notification_rule.py | 5 +- swagger.yaml | 99 +++++------------------ web/src/pages/events/RuleForm.ts | 4 +- web/src/pages/events/RuleListPage.ts | 2 +- 4 files changed, 25 insertions(+), 85 deletions(-) diff --git a/authentik/events/api/notification_rule.py b/authentik/events/api/notification_rule.py index 996216e2a..fbe0788c3 100644 --- a/authentik/events/api/notification_rule.py +++ b/authentik/events/api/notification_rule.py @@ -2,22 +2,25 @@ from rest_framework.serializers import ModelSerializer from rest_framework.viewsets import ModelViewSet +from authentik.core.api.groups import GroupSerializer from authentik.events.models import NotificationRule class NotificationRuleSerializer(ModelSerializer): """NotificationRule Serializer""" + group_obj = GroupSerializer(read_only=True, source="group") + class Meta: model = NotificationRule - depth = 2 fields = [ "pk", "name", "transports", "severity", "group", + "group_obj", ] diff --git a/swagger.yaml b/swagger.yaml index b324adae6..26411c5ae 100755 --- a/swagger.yaml +++ b/swagger.yaml @@ -15694,6 +15694,7 @@ definitions: NotificationRule: required: - name + - transports type: object properties: pk: @@ -15706,38 +15707,17 @@ 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. type: array items: - 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 - send_once: - title: Send once - description: Only send notification once, for example when sending a - webhook into a chat channel. - type: boolean - readOnly: true + 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 severity: title: Severity description: Controls which severity level the created notifications will @@ -15748,57 +15728,14 @@ definitions: - warning - alert group: - 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: - 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 - x-nullable: true - readOnly: true - readOnly: true + 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 + group_obj: + $ref: '#/definitions/Group' NotificationTransport: required: - name diff --git a/web/src/pages/events/RuleForm.ts b/web/src/pages/events/RuleForm.ts index 7e922ac0c..d931d4bdc 100644 --- a/web/src/pages/events/RuleForm.ts +++ b/web/src/pages/events/RuleForm.ts @@ -67,7 +67,7 @@ export class RuleForm extends ModelForm { ${until(new CoreApi(DEFAULT_CONFIG).coreGroupsList({}).then(groups => { return groups.results.map(group => { - return html``; + return html``; }); }), html``)} @@ -80,7 +80,7 @@ export class RuleForm extends ModelForm { ${until(new EventsApi(DEFAULT_CONFIG).eventsTransportsList({}).then(transports => { return transports.results.map(transport => { const selected = Array.from(this.instance?.transports || []).some(su => { - return su.uuid == transport.pk; + return su == transport.pk; }); return html``; }); diff --git a/web/src/pages/events/RuleListPage.ts b/web/src/pages/events/RuleListPage.ts index 7ffcd4d30..3852fd293 100644 --- a/web/src/pages/events/RuleListPage.ts +++ b/web/src/pages/events/RuleListPage.ts @@ -55,7 +55,7 @@ export class RuleListPage extends TablePage { return [ html`${item.name}`, html`${item.severity}`, - html`${item.group?.name || t`None (rule disabled)`}`, + html`${item.groupObj?.name || t`None (rule disabled)`}`, html`