import "@goauthentik/admin/applications/ProviderSelectModal"; import { iconHelperText } from "@goauthentik/admin/helperText"; import { DEFAULT_CONFIG, config } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/components/ak-file-input"; import "@goauthentik/components/ak-radio-input"; import "@goauthentik/components/ak-switch-input"; import "@goauthentik/components/ak-text-input"; import "@goauthentik/components/ak-textarea-input"; import { rootInterface } from "@goauthentik/elements/Base"; import "@goauthentik/elements/forms/FormGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; import "@goauthentik/elements/forms/ModalForm"; import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/ProxyForm"; import "@goauthentik/elements/forms/Radio"; import "@goauthentik/elements/forms/SearchSelect"; import "@patternfly/elements/pf-tooltip/pf-tooltip.js"; import { msg } from "@lit/localize"; import { TemplateResult, html } from "lit"; import { customElement, property, state } from "lit/decorators.js"; import { ifDefined } from "lit/directives/if-defined.js"; import { Application, CapabilitiesEnum, CoreApi, PolicyEngineMode, Provider, } from "@goauthentik/api"; import "./components/ak-backchannel-input"; import "./components/ak-provider-search-input"; export const policyOptions = [ { label: "any", value: PolicyEngineMode.Any, default: true, description: html`${msg("Any policy must match to grant access")}`, }, { label: "all", value: PolicyEngineMode.All, description: html`${msg("All policies must match to grant access")}`, }, ]; @customElement("ak-application-form") export class ApplicationForm extends ModelForm { constructor() { super(); this.handleConfirmBackchannelProviders = this.handleConfirmBackchannelProviders.bind(this); this.makeRemoveBackchannelProviderHandler = this.makeRemoveBackchannelProviderHandler.bind(this); } async loadInstance(pk: string): Promise { const app = await new CoreApi(DEFAULT_CONFIG).coreApplicationsRetrieve({ slug: pk, }); this.clearIcon = false; this.backchannelProviders = app.backchannelProvidersObj || []; return app; } @property({ attribute: false }) provider?: number; @state() backchannelProviders: Provider[] = []; @property({ type: Boolean }) clearIcon = false; getSuccessMessage(): string { if (this.instance) { return msg("Successfully updated application."); } else { return msg("Successfully created application."); } } async send(data: Application): Promise { let app: Application; data.backchannelProviders = this.backchannelProviders.map((p) => p.pk); if (this.instance) { app = await new CoreApi(DEFAULT_CONFIG).coreApplicationsUpdate({ slug: this.instance.slug, applicationRequest: data, }); } else { app = await new CoreApi(DEFAULT_CONFIG).coreApplicationsCreate({ applicationRequest: data, }); } const c = await config(); if (c.capabilities.includes(CapabilitiesEnum.CanSaveMedia)) { const icon = this.getFormFiles()["metaIcon"]; if (icon || this.clearIcon) { await new CoreApi(DEFAULT_CONFIG).coreApplicationsSetIconCreate({ slug: app.slug, file: icon, clear: this.clearIcon, }); } } else { await new CoreApi(DEFAULT_CONFIG).coreApplicationsSetIconUrlCreate({ slug: app.slug, filePathRequest: { url: data.metaIcon || "", }, }); } return app; } handleConfirmBackchannelProviders(items: Provider[]) { this.backchannelProviders = items; this.requestUpdate(); return Promise.resolve(); } makeRemoveBackchannelProviderHandler(provider: Provider) { return () => { const idx = this.backchannelProviders.indexOf(provider); this.backchannelProviders.splice(idx, 1); this.requestUpdate(); }; } handleClearIcon(ev: Event) { ev.stopPropagation(); if (!(ev instanceof InputEvent) || !ev.target) { return; } this.clearIcon = !!(ev.target as HTMLInputElement).checked; } renderForm(): TemplateResult { return html`
`} > ${msg("UI settings")}
${rootInterface()?.config?.capabilities.includes(CapabilitiesEnum.CanSaveMedia) ? html` ${this.instance?.metaIcon ? html` ` : html``}` : html` `}
`; } }