import { DEFAULT_CONFIG, config } from "@goauthentik/common/api/config"; import { first, groupBy } from "@goauthentik/common/utils"; 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 { t } from "@lingui/macro"; import { TemplateResult, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { ifDefined } from "lit/directives/if-defined.js"; import { until } from "lit/directives/until.js"; import { Application, CapabilitiesEnum, CoreApi, PolicyEngineMode, Provider, ProvidersAllListRequest, ProvidersApi, } from "@goauthentik/api"; @customElement("ak-application-form") export class ApplicationForm extends ModelForm { loadInstance(pk: string): Promise { return new CoreApi(DEFAULT_CONFIG).coreApplicationsRetrieve({ slug: pk, }); } @property({ attribute: false }) provider?: number; @property({ type: Boolean }) clearIcon = false; getSuccessMessage(): string { if (this.instance) { return t`Successfully updated application.`; } else { return t`Successfully created application.`; } } send = async (data: Application): Promise => { let app: Application; 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.SaveMedia)) { 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`

${t`Application's display Name.`}

${t`Internal application name, used in URLs.`}

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

${t`Select a provider that this application should use.`}

${t`UI settings`}

${t`If left empty, authentik will try to extract the launch URL based on the selected provider.`}

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

${until( config().then((c) => { if (c.capabilities.includes(CapabilitiesEnum.SaveMedia)) { return html` ${this.instance?.metaIcon ? html`

${t`Currently set to:`} ${this.instance?.metaIcon}

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

${t`Delete currently set icon.`}

` : html``}`; } return html`

${t`Either input a full URL, a relative path, or use 'fa://fa-test' to use the Font Awesome icon "fa-test".`}

`; }), )}
`; } }