import { t } from "@lingui/macro"; import { html, TemplateResult } from "lit"; import { customElement, property } from "lit/decorators"; import { ifDefined } from "lit/directives/if-defined"; import { until } from "lit/directives/until"; import { Flow, FlowDesignationEnum, PolicyEngineMode, FlowsApi, CapabilitiesEnum, } from "@goauthentik/api"; import { config, DEFAULT_CONFIG } from "../../api/Config"; import "../../elements/forms/HorizontalFormElement"; import { ModelForm } from "../../elements/forms/ModelForm"; 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, filePathRequest: { url: data.background || "", }, }); }); } }); }; renderDesignations(): TemplateResult { return html` ${t`Authentication`} ${t`Authorization`} ${t`Enrollment`} ${t`Invalidation`} ${t`Recovery`} ${t`Stage Configuration`} ${t`Unenrollment`} `; } renderForm(): TemplateResult { return html` ${t`Shown as the Title in Flow pages.`} ${t`Visible in the URL.`} ${t`ANY, any policy must match to grant access.`} ${t`ALL, all policies must match to grant access.`} --------- ${this.renderDesignations()} ${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`Clear background image`} ${t`Delete currently set background image.`} ` : html``}`; } return html` ${t`Background shown during execution.`} `; }), )} ${t`Compatibility mode`} ${t`Enable compatibility mode, increases compatibility with password managers on mobile devices.`} `; } }
${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.`}
${t`Currently set to:`} ${this.instance?.background}
${t`Background shown during execution.`}
${t`Delete currently set background image.`}
${t`Enable compatibility mode, increases compatibility with password managers on mobile devices.`}