import { DesignationToLabel, LayoutToLabel } from "@goauthentik/admin/flows/utils"; import { AuthenticationEnum } from "@goauthentik/api/dist/models/AuthenticationEnum"; import { DEFAULT_CONFIG, config } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/elements/forms/HorizontalFormElement"; import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import { t } from "@lingui/macro"; import { TemplateResult, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { ifDefined } from "lit/directives/if-defined.js"; import { until } from "lit/directives/until.js"; import { CapabilitiesEnum, DeniedActionEnum, Flow, FlowDesignationEnum, FlowsApi, LayoutEnum, PolicyEngineMode, } from "@goauthentik/api"; @customElement("ak-flow-form") export class FlowForm extends ModelForm { loadInstance(pk: string): Promise { return new FlowsApi(DEFAULT_CONFIG).flowsInstancesRetrieve({ slug: pk, }); } getSuccessMessage(): string { if (this.instance) { return t`Successfully updated flow.`; } else { return t`Successfully created flow.`; } } @property({ type: Boolean }) clearBackground = false; send = async (data: Flow): Promise => { let flow: Flow; if (this.instance) { flow = await new FlowsApi(DEFAULT_CONFIG).flowsInstancesUpdate({ slug: this.instance.slug, flowRequest: data, }); } else { flow = await new FlowsApi(DEFAULT_CONFIG).flowsInstancesCreate({ flowRequest: data, }); } const c = await config(); if (c.capabilities.includes(CapabilitiesEnum.SaveMedia)) { const icon = this.getFormFiles()["background"]; if (icon || this.clearBackground) { await new FlowsApi(DEFAULT_CONFIG).flowsInstancesSetBackgroundCreate({ slug: flow.slug, file: icon, clear: this.clearBackground, }); } } else { await new FlowsApi(DEFAULT_CONFIG).flowsInstancesSetBackgroundUrlCreate({ slug: flow.slug, filePathRequest: { url: data.background || "", }, }); } return flow; }; renderDesignations(): TemplateResult { return html` `; } renderDeniedAction(): TemplateResult { return html` `; } renderAuthentication(): TemplateResult { return html` `; } renderLayout(): TemplateResult { return html` `; } renderForm(): TemplateResult { return html`

${t`Shown as the Title in Flow pages.`}

${t`Visible in the URL.`}

${t`Required authentication level for this flow.`}

${t`Decides what this Flow is used for. For example, the Authentication flow is redirect to when an un-authenticated user visits authentik.`}

${t`Decides the response when a policy denies access to this flow for a user.`}

${until( config().then((c) => { if (c.capabilities.includes(CapabilitiesEnum.SaveMedia)) { return html` ${this.instance?.background ? html`

${t`Currently set to:`} ${this.instance?.background}

` : html``}

${t`Background shown during execution.`}

${this.instance?.background ? html`
{ const target = ev.target as HTMLInputElement; this.clearBackground = target.checked; }} />

${t`Delete currently set background image.`}

` : html``}`; } return html`

${t`Background shown during execution.`}

`; }), )}

${t`Enable compatibility mode, increases compatibility with password managers on mobile devices.`}

`; } }