import { Flow, FlowDesignationEnum, PolicyEngineMode, FlowsApi, CapabilitiesEnum } from "authentik-api"; import { t } from "@lingui/macro"; import { customElement, property } from "lit-element"; import { html, TemplateResult } from "lit-html"; import { config, DEFAULT_CONFIG } from "../../api/Config"; import { ifDefined } from "lit-html/directives/if-defined"; import "../../elements/forms/HorizontalFormElement"; import { ModelForm } from "../../elements/forms/ModelForm"; import { until } from "lit-html/directives/until"; import { first } from "../../utils"; @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 = (data: Flow): Promise => { let writeOp: Promise; if (this.instance) { writeOp = new FlowsApi(DEFAULT_CONFIG).flowsInstancesUpdate({ slug: this.instance.slug, flowRequest: data }); } else { writeOp = new FlowsApi(DEFAULT_CONFIG).flowsInstancesCreate({ flowRequest: data }); } return config().then((c) => { if (c.capabilities.includes(CapabilitiesEnum.SaveMedia)) { const icon = this.getFormFile(); if (icon || this.clearBackground) { return writeOp.then(app => { return new FlowsApi(DEFAULT_CONFIG).flowsInstancesSetBackgroundCreate({ slug: app.slug, file: icon, clear: this.clearBackground, }); }); } } else { return writeOp.then(app => { return new FlowsApi(DEFAULT_CONFIG).flowsInstancesSetBackgroundUrlCreate({ slug: app.slug, setIconURLRequest: { url: data.background || "", } }); }); } }); }; renderDesignations(): TemplateResult { return html` `; } renderForm(): TemplateResult { return html`

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

${t`Visible in the URL.`}

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

${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.`}

`; } }