import "@goauthentik/admin/applications/ProviderSelectModal"; import { iconHelperText } from "@goauthentik/admin/helperText"; import { DEFAULT_CONFIG, config } from "@goauthentik/common/api/config"; import { first, groupBy } from "@goauthentik/common/utils"; 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, ProvidersAllListRequest, ProvidersApi, } from "@goauthentik/api"; @customElement("ak-application-form") export class ApplicationForm extends ModelForm { 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; } renderForm(): TemplateResult { return html`

${msg("Application's display Name.")}

${msg("Internal application name, used in URLs.")}

${msg( "Optionally enter a group name. Applications with identical groups are shown grouped together.", )}

=> { const args: ProvidersAllListRequest = { ordering: "name", }; if (query !== undefined) { args.search = query; } const items = await new ProvidersApi(DEFAULT_CONFIG).providersAllList(args); return items.results; }} .renderElement=${(item: Provider): string => { return item.name; }} .value=${(item: Provider | undefined): number | undefined => { return item?.pk; }} .groupBy=${(items: Provider[]) => { return groupBy(items, (item) => item.verboseName); }} .selected=${(item: Provider): boolean => { return this.instance?.provider === item.pk; }} ?blankable=${true} >

${msg("Select a provider that this application should use.")}

{ this.backchannelProviders = items; this.requestUpdate(); return Promise.resolve(); }} >
${this.backchannelProviders.map((provider) => { return html` { const idx = this.backchannelProviders.indexOf(provider); this.backchannelProviders.splice(idx, 1); this.requestUpdate(); }} > ${provider.name} `; })}

${msg( "Select backchannel providers which augment the functionality of the main provider.", )}

${msg("UI settings")}

${msg( "If left empty, authentik will try to extract the launch URL based on the selected provider.", )}

${msg( "If checked, the launch URL will open in a new browser tab or window from the user's application library.", )}

${rootInterface()?.config?.capabilities.includes(CapabilitiesEnum.CanSaveMedia) ? html` ${this.instance?.metaIcon ? html`

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

` : html``}
${this.instance?.metaIcon ? html`

${msg("Delete currently set icon.")}

` : html``}` : html`

${iconHelperText}

`}
`; } }