2022-09-14 22:05:21 +00:00
|
|
|
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
|
2022-12-22 16:03:08 +00:00
|
|
|
import { docLink } from "@goauthentik/common/global";
|
2022-09-14 22:05:21 +00:00
|
|
|
import "@goauthentik/elements/CodeMirror";
|
|
|
|
import "@goauthentik/elements/forms/HorizontalFormElement";
|
|
|
|
import { ModelForm } from "@goauthentik/elements/forms/ModelForm";
|
2022-06-25 15:44:17 +00:00
|
|
|
|
2021-09-11 23:02:51 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
2021-10-28 07:48:51 +00:00
|
|
|
import { TemplateResult, html } from "lit";
|
2021-11-04 21:34:48 +00:00
|
|
|
import { customElement } from "lit/decorators.js";
|
|
|
|
import { ifDefined } from "lit/directives/if-defined.js";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
|
|
|
import { NotificationWebhookMapping, PropertymappingsApi } from "@goauthentik/api";
|
|
|
|
|
2021-09-11 23:02:51 +00:00
|
|
|
@customElement("ak-property-mapping-notification-form")
|
|
|
|
export class PropertyMappingNotification extends ModelForm<NotificationWebhookMapping, string> {
|
|
|
|
loadInstance(pk: string): Promise<NotificationWebhookMapping> {
|
2021-09-23 14:13:58 +00:00
|
|
|
return new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsNotificationRetrieve({
|
2021-09-11 23:02:51 +00:00
|
|
|
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"
|
2022-12-22 16:03:08 +00:00
|
|
|
href="${docLink("/docs/property-mappings/expression?utm_source=authentik")}"
|
2021-09-11 23:02:51 +00:00
|
|
|
>
|
|
|
|
${t`See documentation for a list of all variables.`}
|
|
|
|
</a>
|
|
|
|
</p>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
</form>`;
|
|
|
|
}
|
|
|
|
}
|