import { CapabilitiesEnum, WithCapabilitiesConfig } from "#elements/mixins/capabilities"; import { DesignationToLabel, LayoutToLabel } from "@goauthentik/admin/flows/utils"; import { AuthenticationEnum } from "@goauthentik/api/dist/models/AuthenticationEnum"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/Radio"; import { msg } from "@lit/localize"; import { TemplateResult, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { ifDefined } from "lit/directives/if-defined.js"; import { DeniedActionEnum, Flow, FlowDesignationEnum, FlowLayoutEnum, FlowsApi, PolicyEngineMode, } from "@goauthentik/api"; @customElement("ak-flow-form") export class FlowForm extends WithCapabilitiesConfig(ModelForm) { async loadInstance(pk: string): Promise { const flow = await new FlowsApi(DEFAULT_CONFIG).flowsInstancesRetrieve({ slug: pk, }); this.clearBackground = false; return flow; } getSuccessMessage(): string { return this.instance ? msg("Successfully updated flow.") : msg("Successfully created flow."); } @property({ type: Boolean }) clearBackground = false; async send(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, }); } if (this.can(CapabilitiesEnum.CanSaveMedia)) { 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; } renderForm(): TemplateResult { return html`

${msg("Shown as the Title in Flow pages.")}

${msg("Visible in the URL.")}

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

${msg("Required authentication level for this flow.")}

${msg("Behavior settings")}

${msg( "Increases compatibility with password managers and mobile devices.", )}

${msg( "Decides the response when a policy denies access to this flow for a user.", )}

${msg("Appearance settings")}
${this.can(CapabilitiesEnum.CanSaveMedia) ? html` ${this.instance?.background ? html`

${msg("Currently set to:")} ${this.instance?.background}

` : html``}

${msg("Background shown during execution.")}

${this.instance?.background ? html`

${msg("Delete currently set background image.")}

` : html``}` : html`

${msg("Background shown during execution.")}

`}
`; } } declare global { interface HTMLElementTagNameMap { "ak-flow-form": FlowForm; } }