events/api: fix error when updating transports

closes #866

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-05-12 16:41:15 +02:00
parent ae1edde17b
commit 2190fa555b
4 changed files with 25 additions and 85 deletions

View file

@ -2,22 +2,25 @@
from rest_framework.serializers import ModelSerializer from rest_framework.serializers import ModelSerializer
from rest_framework.viewsets import ModelViewSet from rest_framework.viewsets import ModelViewSet
from authentik.core.api.groups import GroupSerializer
from authentik.events.models import NotificationRule from authentik.events.models import NotificationRule
class NotificationRuleSerializer(ModelSerializer): class NotificationRuleSerializer(ModelSerializer):
"""NotificationRule Serializer""" """NotificationRule Serializer"""
group_obj = GroupSerializer(read_only=True, source="group")
class Meta: class Meta:
model = NotificationRule model = NotificationRule
depth = 2
fields = [ fields = [
"pk", "pk",
"name", "name",
"transports", "transports",
"severity", "severity",
"group", "group",
"group_obj",
] ]

View file

@ -15694,6 +15694,7 @@ definitions:
NotificationRule: NotificationRule:
required: required:
- name - name
- transports
type: object type: object
properties: properties:
pk: pk:
@ -15706,38 +15707,17 @@ definitions:
type: string type: string
minLength: 1 minLength: 1
transports: 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 type: array
items: items:
required: description: Select which transports should be used to notify the user.
- name If none are selected, the notification will only be shown in the authentik
- mode UI.
type: object type: string
properties: format: uuid
uuid: uniqueItems: true
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
severity: severity:
title: Severity title: Severity
description: Controls which severity level the created notifications will description: Controls which severity level the created notifications will
@ -15748,57 +15728,14 @@ definitions:
- warning - warning
- alert - alert
group: group:
required: title: Group
- name description: Define which group of users this notification should be sent
type: object and shown to. If left empty, Notification won't ben sent.
properties: type: string
group_uuid: format: uuid
title: Group uuid x-nullable: true
type: string group_obj:
format: uuid $ref: '#/definitions/Group'
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
NotificationTransport: NotificationTransport:
required: required:
- name - name

View file

@ -67,7 +67,7 @@ export class RuleForm extends ModelForm<NotificationRule, string> {
<option value="" ?selected=${this.instance?.group === undefined}>---------</option> <option value="" ?selected=${this.instance?.group === undefined}>---------</option>
${until(new CoreApi(DEFAULT_CONFIG).coreGroupsList({}).then(groups => { ${until(new CoreApi(DEFAULT_CONFIG).coreGroupsList({}).then(groups => {
return groups.results.map(group => { return groups.results.map(group => {
return html`<option value=${ifDefined(group.pk)} ?selected=${this.instance?.group?.groupUuid === group.pk}>${group.name}</option>`; return html`<option value=${ifDefined(group.pk)} ?selected=${this.instance?.group === group.pk}>${group.name}</option>`;
}); });
}), html`<option>${t`Loading...`}</option>`)} }), html`<option>${t`Loading...`}</option>`)}
</select> </select>
@ -80,7 +80,7 @@ export class RuleForm extends ModelForm<NotificationRule, string> {
${until(new EventsApi(DEFAULT_CONFIG).eventsTransportsList({}).then(transports => { ${until(new EventsApi(DEFAULT_CONFIG).eventsTransportsList({}).then(transports => {
return transports.results.map(transport => { return transports.results.map(transport => {
const selected = Array.from(this.instance?.transports || []).some(su => { const selected = Array.from(this.instance?.transports || []).some(su => {
return su.uuid == transport.pk; return su == transport.pk;
}); });
return html`<option value=${ifDefined(transport.pk)} ?selected=${selected}>${transport.name}</option>`; return html`<option value=${ifDefined(transport.pk)} ?selected=${selected}>${transport.name}</option>`;
}); });

View file

@ -55,7 +55,7 @@ export class RuleListPage extends TablePage<NotificationRule> {
return [ return [
html`${item.name}`, html`${item.name}`,
html`${item.severity}`, html`${item.severity}`,
html`${item.group?.name || t`None (rule disabled)`}`, html`${item.groupObj?.name || t`None (rule disabled)`}`,
html` html`
<ak-forms-modal> <ak-forms-modal>
<span slot="submit"> <span slot="submit">