events: allow setting a mapping for webhook transport to customise request payloads
closes #1383 Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
@ -15,9 +15,9 @@ import AKGlobal from "../../authentik.css";
|
||||
|
||||
import { configureSentry } from "../../api/Sentry";
|
||||
import { CurrentTenant } from "@goauthentik/api";
|
||||
import { ifDefined } from "lit-html/directives/if-defined";
|
||||
import { EVENT_SIDEBAR_TOGGLE } from "../../constants";
|
||||
import { tenant } from "../../api/Config";
|
||||
import { first } from "../../utils";
|
||||
|
||||
// If the viewport is wider than MIN_WIDTH, the sidebar
|
||||
// is shown besides the content, and not overlayed.
|
||||
@ -99,7 +99,7 @@ export class SidebarBrand extends LitElement {
|
||||
<a href="#/" class="pf-c-page__header-brand-link">
|
||||
<div class="pf-c-brand ak-brand">
|
||||
<img
|
||||
src="${ifDefined(this.tenant.brandingLogo)}"
|
||||
src="${first(this.tenant.brandingLogo, DefaultTenant.brandingLogo)}"
|
||||
alt="authentik icon"
|
||||
loading="lazy"
|
||||
/>
|
||||
|
||||
@ -45,11 +45,12 @@ import {
|
||||
ShellChallenge,
|
||||
} from "@goauthentik/api";
|
||||
import { DEFAULT_CONFIG, tenant } from "../api/Config";
|
||||
import { ifDefined } from "lit-html/directives/if-defined";
|
||||
import { until } from "lit-html/directives/until";
|
||||
import { TITLE_DEFAULT } from "../constants";
|
||||
import { configureSentry } from "../api/Sentry";
|
||||
import { WebsocketClient } from "../common/ws";
|
||||
import { first } from "../utils";
|
||||
import { DefaultTenant } from "../elements/sidebar/SidebarBrand";
|
||||
|
||||
@customElement("ak-flow-executor")
|
||||
export class FlowExecutor extends LitElement implements StageHost {
|
||||
@ -342,7 +343,10 @@ export class FlowExecutor extends LitElement implements StageHost {
|
||||
<header class="pf-c-login__header">
|
||||
<div class="pf-c-brand ak-brand">
|
||||
<img
|
||||
src="${ifDefined(this.tenant?.brandingLogo)}"
|
||||
src="${first(
|
||||
this.tenant?.brandingLogo,
|
||||
DefaultTenant.brandingLogo,
|
||||
)}"
|
||||
alt="authentik icon"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@ -1646,6 +1646,7 @@ msgstr "Export flow"
|
||||
#: src/pages/events/EventInfo.ts
|
||||
#: src/pages/policies/expression/ExpressionPolicyForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingLDAPForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingNotification.ts
|
||||
#: src/pages/property-mappings/PropertyMappingSAMLForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingScopeForm.ts
|
||||
msgid "Expression"
|
||||
@ -1653,6 +1654,7 @@ msgstr "Expression"
|
||||
|
||||
#: src/pages/policies/expression/ExpressionPolicyForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingLDAPForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingNotification.ts
|
||||
#: src/pages/property-mappings/PropertyMappingSAMLForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingScopeForm.ts
|
||||
msgid "Expression using Python."
|
||||
@ -2316,6 +2318,7 @@ msgstr "Loading"
|
||||
#: src/pages/applications/ApplicationForm.ts
|
||||
#: src/pages/events/RuleForm.ts
|
||||
#: src/pages/events/RuleForm.ts
|
||||
#: src/pages/events/TransportForm.ts
|
||||
#: src/pages/flows/StageBindingForm.ts
|
||||
#: src/pages/flows/StageBindingForm.ts
|
||||
#: src/pages/groups/GroupForm.ts
|
||||
@ -2564,6 +2567,7 @@ msgstr "My Applications"
|
||||
#: src/pages/policies/reputation/ReputationPolicyForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingLDAPForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingListPage.ts
|
||||
#: src/pages/property-mappings/PropertyMappingNotification.ts
|
||||
#: src/pages/property-mappings/PropertyMappingSAMLForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingScopeForm.ts
|
||||
#: src/pages/providers/ProviderListPage.ts
|
||||
@ -3530,6 +3534,7 @@ msgstr "Secret:"
|
||||
|
||||
#: src/pages/policies/expression/ExpressionPolicyForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingLDAPForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingNotification.ts
|
||||
#: src/pages/property-mappings/PropertyMappingSAMLForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingScopeForm.ts
|
||||
msgid "See documentation for a list of all variables."
|
||||
@ -3968,6 +3973,7 @@ msgid "Successfully created invitation."
|
||||
msgstr "Successfully created invitation."
|
||||
|
||||
#: src/pages/property-mappings/PropertyMappingLDAPForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingNotification.ts
|
||||
#: src/pages/property-mappings/PropertyMappingSAMLForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingScopeForm.ts
|
||||
msgid "Successfully created mapping."
|
||||
@ -4124,6 +4130,7 @@ msgid "Successfully updated invitation."
|
||||
msgstr "Successfully updated invitation."
|
||||
|
||||
#: src/pages/property-mappings/PropertyMappingLDAPForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingNotification.ts
|
||||
#: src/pages/property-mappings/PropertyMappingSAMLForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingScopeForm.ts
|
||||
msgid "Successfully updated mapping."
|
||||
@ -5071,6 +5078,10 @@ msgstr "Webhook (Slack/Discord)"
|
||||
msgid "Webhook (generic)"
|
||||
msgstr "Webhook (generic)"
|
||||
|
||||
#: src/pages/events/TransportForm.ts
|
||||
msgid "Webhook Mapping"
|
||||
msgstr "Webhook Mapping"
|
||||
|
||||
#: src/pages/events/TransportForm.ts
|
||||
msgid "Webhook URL"
|
||||
msgstr "Webhook URL"
|
||||
|
||||
@ -1638,6 +1638,7 @@ msgstr ""
|
||||
#: src/pages/events/EventInfo.ts
|
||||
#: src/pages/policies/expression/ExpressionPolicyForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingLDAPForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingNotification.ts
|
||||
#: src/pages/property-mappings/PropertyMappingSAMLForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingScopeForm.ts
|
||||
msgid "Expression"
|
||||
@ -1645,6 +1646,7 @@ msgstr ""
|
||||
|
||||
#: src/pages/policies/expression/ExpressionPolicyForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingLDAPForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingNotification.ts
|
||||
#: src/pages/property-mappings/PropertyMappingSAMLForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingScopeForm.ts
|
||||
msgid "Expression using Python."
|
||||
@ -2308,6 +2310,7 @@ msgstr ""
|
||||
#: src/pages/applications/ApplicationForm.ts
|
||||
#: src/pages/events/RuleForm.ts
|
||||
#: src/pages/events/RuleForm.ts
|
||||
#: src/pages/events/TransportForm.ts
|
||||
#: src/pages/flows/StageBindingForm.ts
|
||||
#: src/pages/flows/StageBindingForm.ts
|
||||
#: src/pages/groups/GroupForm.ts
|
||||
@ -2556,6 +2559,7 @@ msgstr ""
|
||||
#: src/pages/policies/reputation/ReputationPolicyForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingLDAPForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingListPage.ts
|
||||
#: src/pages/property-mappings/PropertyMappingNotification.ts
|
||||
#: src/pages/property-mappings/PropertyMappingSAMLForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingScopeForm.ts
|
||||
#: src/pages/providers/ProviderListPage.ts
|
||||
@ -3522,6 +3526,7 @@ msgstr ""
|
||||
|
||||
#: src/pages/policies/expression/ExpressionPolicyForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingLDAPForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingNotification.ts
|
||||
#: src/pages/property-mappings/PropertyMappingSAMLForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingScopeForm.ts
|
||||
msgid "See documentation for a list of all variables."
|
||||
@ -3960,6 +3965,7 @@ msgid "Successfully created invitation."
|
||||
msgstr ""
|
||||
|
||||
#: src/pages/property-mappings/PropertyMappingLDAPForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingNotification.ts
|
||||
#: src/pages/property-mappings/PropertyMappingSAMLForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingScopeForm.ts
|
||||
msgid "Successfully created mapping."
|
||||
@ -4116,6 +4122,7 @@ msgid "Successfully updated invitation."
|
||||
msgstr ""
|
||||
|
||||
#: src/pages/property-mappings/PropertyMappingLDAPForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingNotification.ts
|
||||
#: src/pages/property-mappings/PropertyMappingSAMLForm.ts
|
||||
#: src/pages/property-mappings/PropertyMappingScopeForm.ts
|
||||
msgid "Successfully updated mapping."
|
||||
@ -5056,6 +5063,10 @@ msgstr ""
|
||||
msgid "Webhook (generic)"
|
||||
msgstr ""
|
||||
|
||||
#: src/pages/events/TransportForm.ts
|
||||
msgid "Webhook Mapping"
|
||||
msgstr ""
|
||||
|
||||
#: src/pages/events/TransportForm.ts
|
||||
msgid "Webhook URL"
|
||||
msgstr ""
|
||||
|
||||
@ -1,4 +1,9 @@
|
||||
import { EventsApi, NotificationTransport, NotificationTransportModeEnum } from "@goauthentik/api";
|
||||
import {
|
||||
EventsApi,
|
||||
NotificationTransport,
|
||||
NotificationTransportModeEnum,
|
||||
PropertymappingsApi,
|
||||
} from "@goauthentik/api";
|
||||
import { t } from "@lingui/macro";
|
||||
import { customElement, property } from "lit-element";
|
||||
import { html, TemplateResult } from "lit-html";
|
||||
@ -7,6 +12,7 @@ import { ifDefined } from "lit-html/directives/if-defined";
|
||||
import "../../elements/forms/HorizontalFormElement";
|
||||
import { first } from "../../utils";
|
||||
import { ModelForm } from "../../elements/forms/ModelForm";
|
||||
import { until } from "lit-html/directives/until";
|
||||
|
||||
@customElement("ak-event-transport-form")
|
||||
export class TransportForm extends ModelForm<NotificationTransport, string> {
|
||||
@ -112,6 +118,32 @@ export class TransportForm extends ModelForm<NotificationTransport, string> {
|
||||
class="pf-c-form-control"
|
||||
/>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal
|
||||
?hidden=${!this.showWebhook}
|
||||
label=${t`Webhook Mapping`}
|
||||
name="webhookMapping"
|
||||
>
|
||||
<select class="pf-c-form-control">
|
||||
<option value="" ?selected=${this.instance?.webhookMapping === undefined}>
|
||||
---------
|
||||
</option>
|
||||
${until(
|
||||
new PropertymappingsApi(DEFAULT_CONFIG)
|
||||
.propertymappingsNotificationList({})
|
||||
.then((mappings) => {
|
||||
return mappings.results.map((mapping) => {
|
||||
return html`<option
|
||||
value=${ifDefined(mapping.pk)}
|
||||
?selected=${this.instance?.webhookMapping === mapping.pk}
|
||||
>
|
||||
${mapping.name}
|
||||
</option>`;
|
||||
});
|
||||
}),
|
||||
html`<option>${t`Loading...`}</option>`,
|
||||
)}
|
||||
</select>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal name="sendOnce">
|
||||
<div class="pf-c-check">
|
||||
<input
|
||||
|
||||
@ -12,6 +12,7 @@ import "./PropertyMappingTestForm";
|
||||
import "./PropertyMappingScopeForm";
|
||||
import "./PropertyMappingLDAPForm";
|
||||
import "./PropertyMappingSAMLForm";
|
||||
import "./PropertyMappingNotification";
|
||||
import { TableColumn } from "../../elements/table/Table";
|
||||
import { until } from "lit-html/directives/until";
|
||||
import { PAGE_SIZE } from "../../constants";
|
||||
|
||||
@ -0,0 +1,65 @@
|
||||
import { NotificationWebhookMapping, PropertymappingsApi } from "@goauthentik/api";
|
||||
import { t } from "@lingui/macro";
|
||||
import { customElement } from "lit-element";
|
||||
import { html, TemplateResult } from "lit-html";
|
||||
import { DEFAULT_CONFIG } from "../../api/Config";
|
||||
import { ifDefined } from "lit-html/directives/if-defined";
|
||||
import "../../elements/forms/HorizontalFormElement";
|
||||
import "../../elements/CodeMirror";
|
||||
import { ModelForm } from "../../elements/forms/ModelForm";
|
||||
|
||||
@customElement("ak-property-mapping-notification-form")
|
||||
export class PropertyMappingNotification extends ModelForm<NotificationWebhookMapping, string> {
|
||||
loadInstance(pk: string): Promise<NotificationWebhookMapping> {
|
||||
return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsNotificationRetrieveRaw({
|
||||
pmUuid: pk,
|
||||
});
|
||||
}
|
||||
|
||||
getSuccessMessage(): string {
|
||||
if (this.instance) {
|
||||
return t`Successfully updated mapping.`;
|
||||
} else {
|
||||
return t`Successfully created mapping.`;
|
||||
}
|
||||
}
|
||||
|
||||
send = (data: NotificationWebhookMapping): Promise<NotificationWebhookMapping> => {
|
||||
if (this.instance) {
|
||||
return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsNotificationUpdate({
|
||||
pmUuid: this.instance.pk || "",
|
||||
notificationWebhookMappingRequest: data,
|
||||
});
|
||||
} else {
|
||||
return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsNotificationCreate({
|
||||
notificationWebhookMappingRequest: data,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
renderForm(): TemplateResult {
|
||||
return html`<form class="pf-c-form pf-m-horizontal">
|
||||
<ak-form-element-horizontal label=${t`Name`} ?required=${true} name="name">
|
||||
<input
|
||||
type="text"
|
||||
value="${ifDefined(this.instance?.name)}"
|
||||
class="pf-c-form-control"
|
||||
required
|
||||
/>
|
||||
</ak-form-element-horizontal>
|
||||
<ak-form-element-horizontal label=${t`Expression`} ?required=${true} name="expression">
|
||||
<ak-codemirror mode="python" value="${ifDefined(this.instance?.expression)}">
|
||||
</ak-codemirror>
|
||||
<p class="pf-c-form__helper-text">
|
||||
${t`Expression using Python.`}
|
||||
<a
|
||||
target="_blank"
|
||||
href="https://goauthentik.io/docs/property-mappings/expression/"
|
||||
>
|
||||
${t`See documentation for a list of all variables.`}
|
||||
</a>
|
||||
</p>
|
||||
</ak-form-element-horizontal>
|
||||
</form>`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user