import "@goauthentik/admin/events/RuleForm"; import "@goauthentik/admin/policies/BoundPoliciesList"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { uiConfig } from "@goauthentik/common/ui/config"; import "@goauthentik/elements/buttons/SpinnerButton"; import "@goauthentik/elements/forms/DeleteBulkForm"; import "@goauthentik/elements/forms/ModalForm"; import { PaginatedResponse } from "@goauthentik/elements/table/Table"; import { TableColumn } from "@goauthentik/elements/table/Table"; import { TablePage } from "@goauthentik/elements/table/TablePage"; import { t } from "@lingui/macro"; import { TemplateResult, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { EventsApi, NotificationRule, SeverityEnum } from "@goauthentik/api"; export function SeverityToLabel(severity: SeverityEnum | null | undefined): string { if (!severity) return t`Unknown severity`; switch (severity) { case SeverityEnum.Alert: return t`Alert`; case SeverityEnum.Notice: return t`Notice`; case SeverityEnum.Warning: return t`Warning`; } return t`Unknown severity`; } @customElement("ak-event-rule-list") export class RuleListPage extends TablePage { expandable = true; checkbox = true; searchEnabled(): boolean { return true; } pageTitle(): string { return t`Notification Rules`; } pageDescription(): string { return t`Send notifications whenever a specific Event is created and matched by policies.`; } pageIcon(): string { return "pf-icon pf-icon-attention-bell"; } @property() order = "name"; async apiEndpoint(page: number): Promise> { return new EventsApi(DEFAULT_CONFIG).eventsRulesList({ ordering: this.order, page: page, pageSize: (await uiConfig()).pagination.perPage, search: this.search || "", }); } columns(): TableColumn[] { return [ new TableColumn(t`Name`, "name"), new TableColumn(t`Severity`, "severity"), new TableColumn(t`Sent to group`, "group"), new TableColumn(t`Actions`), ]; } renderToolbarSelected(): TemplateResult { const disabled = this.selectedElements.length < 1; return html` { return new EventsApi(DEFAULT_CONFIG).eventsRulesUsedByList({ pbmUuid: item.pk, }); }} .delete=${(item: NotificationRule) => { return new EventsApi(DEFAULT_CONFIG).eventsRulesDestroy({ pbmUuid: item.pk, }); }} > `; } row(item: NotificationRule): TemplateResult[] { return [ html`${item.name}`, html`${SeverityToLabel(item.severity)}`, html`${item.groupObj?.name || t`None (rule disabled)`}`, html` ${t`Update`} ${t`Update Notification Rule`} `, ]; } renderObjectCreate(): TemplateResult { return html` ${t`Create`} ${t`Create Notification Rule`} `; } renderExpanded(item: NotificationRule): TemplateResult { return html`

${t`These bindings control upon which events this rule triggers. Bindings to groups/users are checked against the user of the event.`}

`; } }