2022-09-14 22:05:21 +00:00
|
|
|
import { DEFAULT_CONFIG, config } from "@goauthentik/common/api/config";
|
2022-12-29 12:15:09 +00:00
|
|
|
import { first, groupBy } from "@goauthentik/common/utils";
|
2023-03-23 13:05:14 +00:00
|
|
|
import { rootInterface } from "@goauthentik/elements/Base";
|
2022-09-14 22:05:21 +00:00
|
|
|
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";
|
2023-01-02 13:51:44 +00:00
|
|
|
import "@goauthentik/elements/forms/Radio";
|
|
|
|
import "@goauthentik/elements/forms/SearchSelect";
|
2022-06-25 15:44:17 +00:00
|
|
|
|
2021-09-21 09:31:37 +00:00
|
|
|
import { t } from "@lingui/macro";
|
|
|
|
|
2021-10-28 07:48:51 +00:00
|
|
|
import { TemplateResult, html } from "lit";
|
2021-11-04 21:34:48 +00:00
|
|
|
import { customElement, property } from "lit/decorators.js";
|
|
|
|
import { ifDefined } from "lit/directives/if-defined.js";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
2021-08-03 15:52:21 +00:00
|
|
|
import {
|
|
|
|
Application,
|
|
|
|
CapabilitiesEnum,
|
2021-10-28 07:48:51 +00:00
|
|
|
CoreApi,
|
|
|
|
PolicyEngineMode,
|
|
|
|
Provider,
|
2022-12-29 12:15:09 +00:00
|
|
|
ProvidersAllListRequest,
|
2021-10-28 07:48:51 +00:00
|
|
|
ProvidersApi,
|
2021-08-15 19:32:28 +00:00
|
|
|
} from "@goauthentik/api";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
2021-03-29 19:29:27 +00:00
|
|
|
@customElement("ak-application-form")
|
2021-05-11 09:48:34 +00:00
|
|
|
export class ApplicationForm extends ModelForm<Application, string> {
|
2023-04-30 11:25:18 +00:00
|
|
|
async loadInstance(pk: string): Promise<Application> {
|
|
|
|
const app = await new CoreApi(DEFAULT_CONFIG).coreApplicationsRetrieve({
|
2021-08-03 15:52:21 +00:00
|
|
|
slug: pk,
|
2021-05-11 09:48:34 +00:00
|
|
|
});
|
2023-04-30 11:25:18 +00:00
|
|
|
this.clearIcon = false;
|
|
|
|
return app;
|
2021-05-11 09:48:34 +00:00
|
|
|
}
|
2021-03-29 19:29:27 +00:00
|
|
|
|
|
|
|
@property({ attribute: false })
|
|
|
|
provider?: number;
|
|
|
|
|
2021-06-05 19:33:03 +00:00
|
|
|
@property({ type: Boolean })
|
|
|
|
clearIcon = false;
|
|
|
|
|
2021-03-29 19:29:27 +00:00
|
|
|
getSuccessMessage(): string {
|
2021-05-11 09:48:34 +00:00
|
|
|
if (this.instance) {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully updated application.`;
|
2021-03-29 19:29:27 +00:00
|
|
|
} else {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully created application.`;
|
2021-03-29 19:29:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-30 16:55:29 +00:00
|
|
|
async send(data: Application): Promise<Application | void> {
|
2021-11-23 11:18:39 +00:00
|
|
|
let app: Application;
|
2021-05-11 09:48:34 +00:00
|
|
|
if (this.instance) {
|
2021-11-23 11:18:39 +00:00
|
|
|
app = await new CoreApi(DEFAULT_CONFIG).coreApplicationsUpdate({
|
2021-05-11 09:48:34 +00:00
|
|
|
slug: this.instance.slug,
|
2021-08-03 15:52:21 +00:00
|
|
|
applicationRequest: data,
|
2021-03-29 19:29:27 +00:00
|
|
|
});
|
|
|
|
} else {
|
2021-11-23 11:18:39 +00:00
|
|
|
app = await new CoreApi(DEFAULT_CONFIG).coreApplicationsCreate({
|
2021-08-03 15:52:21 +00:00
|
|
|
applicationRequest: data,
|
2021-03-29 19:29:27 +00:00
|
|
|
});
|
|
|
|
}
|
2021-11-23 11:18:39 +00:00
|
|
|
const c = await config();
|
2023-04-20 16:48:56 +00:00
|
|
|
if (c.capabilities.includes(CapabilitiesEnum.CanSaveMedia)) {
|
2022-06-25 22:46:40 +00:00
|
|
|
const icon = this.getFormFiles()["metaIcon"];
|
2021-11-23 11:18:39 +00:00
|
|
|
if (icon || this.clearIcon) {
|
|
|
|
await new CoreApi(DEFAULT_CONFIG).coreApplicationsSetIconCreate({
|
|
|
|
slug: app.slug,
|
|
|
|
file: icon,
|
|
|
|
clear: this.clearIcon,
|
2021-03-29 19:29:27 +00:00
|
|
|
});
|
2021-05-20 15:01:08 +00:00
|
|
|
}
|
2021-11-23 11:18:39 +00:00
|
|
|
} else {
|
|
|
|
await new CoreApi(DEFAULT_CONFIG).coreApplicationsSetIconUrlCreate({
|
|
|
|
slug: app.slug,
|
|
|
|
filePathRequest: {
|
|
|
|
url: data.metaIcon || "",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return app;
|
2023-04-30 16:55:29 +00:00
|
|
|
}
|
2021-03-29 19:29:27 +00:00
|
|
|
|
|
|
|
renderForm(): TemplateResult {
|
|
|
|
return html`<form class="pf-c-form pf-m-horizontal">
|
2021-08-03 15:52:21 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Name`} ?required=${true} name="name">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
value="${ifDefined(this.instance?.name)}"
|
|
|
|
class="pf-c-form-control"
|
|
|
|
required
|
|
|
|
/>
|
2021-04-03 17:26:43 +00:00
|
|
|
<p class="pf-c-form__helper-text">${t`Application's display Name.`}</p>
|
2021-03-29 19:29:27 +00:00
|
|
|
</ak-form-element-horizontal>
|
2021-08-03 15:52:21 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Slug`} ?required=${true} name="slug">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
value="${ifDefined(this.instance?.slug)}"
|
|
|
|
class="pf-c-form-control"
|
|
|
|
required
|
|
|
|
/>
|
2021-04-03 17:26:43 +00:00
|
|
|
<p class="pf-c-form__helper-text">${t`Internal application name, used in URLs.`}</p>
|
2021-03-29 19:29:27 +00:00
|
|
|
</ak-form-element-horizontal>
|
2022-04-02 21:08:58 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Group`} name="group">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
value="${ifDefined(this.instance?.group)}"
|
|
|
|
class="pf-c-form-control"
|
|
|
|
/>
|
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
${t`Optionally enter a group name. Applications with identical groups are shown grouped together.`}
|
|
|
|
</p>
|
|
|
|
</ak-form-element-horizontal>
|
2021-08-03 15:52:21 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Provider`} name="provider">
|
2022-12-29 12:15:09 +00:00
|
|
|
<ak-search-select
|
|
|
|
.fetchObjects=${async (query?: string): Promise<Provider[]> => {
|
|
|
|
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}
|
|
|
|
>
|
|
|
|
</ak-search-select>
|
2021-08-03 15:52:21 +00:00
|
|
|
<p class="pf-c-form__helper-text">
|
2023-01-11 12:37:49 +00:00
|
|
|
${t`Select a provider that this application should use.`}
|
2021-08-03 15:52:21 +00:00
|
|
|
</p>
|
2021-03-29 19:29:27 +00:00
|
|
|
</ak-form-element-horizontal>
|
2021-03-31 12:14:56 +00:00
|
|
|
<ak-form-element-horizontal
|
2021-04-03 17:26:43 +00:00
|
|
|
label=${t`Policy engine mode`}
|
2021-03-31 12:14:56 +00:00
|
|
|
?required=${true}
|
2021-08-03 15:52:21 +00:00
|
|
|
name="policyEngineMode"
|
|
|
|
>
|
2023-01-02 13:51:44 +00:00
|
|
|
<ak-radio
|
|
|
|
.options=${[
|
|
|
|
{
|
|
|
|
label: "ANY",
|
|
|
|
value: PolicyEngineMode.Any,
|
|
|
|
default: true,
|
|
|
|
description: html`${t`Any policy must match to grant access`}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "ALL",
|
|
|
|
value: PolicyEngineMode.All,
|
|
|
|
description: html`${t`All policies must match to grant access`}`,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
.value=${this.instance?.policyEngineMode}
|
|
|
|
>
|
|
|
|
</ak-radio>
|
2021-03-31 12:14:56 +00:00
|
|
|
</ak-form-element-horizontal>
|
2023-01-11 12:37:49 +00:00
|
|
|
<ak-form-group>
|
2021-08-03 15:52:21 +00:00
|
|
|
<span slot="header"> ${t`UI settings`} </span>
|
2021-04-04 16:58:52 +00:00
|
|
|
<div slot="body" class="pf-c-form">
|
2021-08-03 15:52:21 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Launch URL`} name="metaLaunchUrl">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
value="${ifDefined(this.instance?.metaLaunchUrl)}"
|
|
|
|
class="pf-c-form-control"
|
|
|
|
/>
|
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
${t`If left empty, authentik will try to extract the launch URL based on the selected provider.`}
|
|
|
|
</p>
|
2021-04-04 16:58:52 +00:00
|
|
|
</ak-form-element-horizontal>
|
2022-09-18 18:38:22 +00:00
|
|
|
<ak-form-element-horizontal name="openInNewTab">
|
2023-01-11 12:37:49 +00:00
|
|
|
<label class="pf-c-switch">
|
2022-09-18 18:38:22 +00:00
|
|
|
<input
|
2023-01-11 12:37:49 +00:00
|
|
|
class="pf-c-switch__input"
|
2022-09-18 18:38:22 +00:00
|
|
|
type="checkbox"
|
2022-12-21 11:13:11 +00:00
|
|
|
?checked=${first(this.instance?.openInNewTab, false)}
|
2022-09-18 18:38:22 +00:00
|
|
|
/>
|
2023-01-11 12:37:49 +00:00
|
|
|
<span class="pf-c-switch__toggle">
|
|
|
|
<span class="pf-c-switch__toggle-icon">
|
|
|
|
<i class="fas fa-check" aria-hidden="true"></i>
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
<span class="pf-c-switch__label">${t`Open in new tab`}</span>
|
|
|
|
</label>
|
2022-06-05 12:32:22 +00:00
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
${t`If checked, the launch URL will open in a new browser tab or window from the user's application library.`}
|
|
|
|
</p>
|
|
|
|
</ak-form-element-horizontal>
|
2023-04-20 16:48:56 +00:00
|
|
|
${rootInterface()?.config?.capabilities.includes(CapabilitiesEnum.CanSaveMedia)
|
2023-03-23 13:05:14 +00:00
|
|
|
? html`<ak-form-element-horizontal label=${t`Icon`} name="metaIcon">
|
|
|
|
<input type="file" value="" class="pf-c-form-control" />
|
|
|
|
${this.instance?.metaIcon
|
|
|
|
? html`
|
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
${t`Currently set to:`} ${this.instance?.metaIcon}
|
|
|
|
</p>
|
|
|
|
`
|
|
|
|
: html``}
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
${this.instance?.metaIcon
|
|
|
|
? html`
|
|
|
|
<ak-form-element-horizontal>
|
|
|
|
<label class="pf-c-switch">
|
|
|
|
<input
|
|
|
|
class="pf-c-switch__input"
|
|
|
|
type="checkbox"
|
|
|
|
@change=${(ev: Event) => {
|
|
|
|
const target =
|
|
|
|
ev.target as HTMLInputElement;
|
|
|
|
this.clearIcon = target.checked;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<span class="pf-c-switch__toggle">
|
|
|
|
<span class="pf-c-switch__toggle-icon">
|
|
|
|
<i
|
|
|
|
class="fas fa-check"
|
|
|
|
aria-hidden="true"
|
|
|
|
></i>
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
<span class="pf-c-switch__label">
|
|
|
|
${t`Clear icon`}
|
|
|
|
</span>
|
|
|
|
</label>
|
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
${t`Delete currently set icon.`}
|
|
|
|
</p>
|
|
|
|
</ak-form-element-horizontal>
|
|
|
|
`
|
|
|
|
: html``}`
|
2023-05-03 15:13:34 +00:00
|
|
|
: html`<ak-form-element-horizontal label=${t`Icon`} name="metaIcon">
|
2023-03-23 13:05:14 +00:00
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
value="${first(this.instance?.metaIcon, "")}"
|
|
|
|
class="pf-c-form-control"
|
|
|
|
/>
|
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
${t`Either input a full URL, a relative path, or use 'fa://fa-test' to use the Font Awesome icon "fa-test".`}
|
|
|
|
</p>
|
|
|
|
</ak-form-element-horizontal>`}
|
2021-08-03 15:52:21 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Publisher`} name="metaPublisher">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
value="${ifDefined(this.instance?.metaPublisher)}"
|
|
|
|
class="pf-c-form-control"
|
|
|
|
/>
|
2021-04-04 16:58:52 +00:00
|
|
|
</ak-form-element-horizontal>
|
2021-11-23 22:15:30 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Description`} name="metaDescription">
|
|
|
|
<textarea class="pf-c-form-control">
|
|
|
|
${ifDefined(this.instance?.metaDescription)}</textarea
|
|
|
|
>
|
|
|
|
</ak-form-element-horizontal>
|
2021-04-04 16:58:52 +00:00
|
|
|
</div>
|
|
|
|
</ak-form-group>
|
2021-03-29 19:29:27 +00:00
|
|
|
</form>`;
|
|
|
|
}
|
|
|
|
}
|