2021-04-03 17:26:43 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
2021-09-21 09:19:26 +00:00
|
|
|
import { html, TemplateResult } from "lit";
|
|
|
|
import { customElement, property } from "lit/decorators";
|
2021-09-21 09:31:37 +00:00
|
|
|
import { ifDefined } from "lit/directives/if-defined";
|
|
|
|
import { until } from "lit/directives/until";
|
2021-02-09 09:22:49 +00:00
|
|
|
|
2021-09-21 09:31:37 +00:00
|
|
|
import { Source, SourcesApi } from "@goauthentik/api";
|
|
|
|
|
|
|
|
import { AKResponse } from "../../api/Client";
|
|
|
|
import { DEFAULT_CONFIG } from "../../api/Config";
|
2021-10-14 10:48:52 +00:00
|
|
|
import { uiConfig } from "../../common/config";
|
2021-02-10 19:12:15 +00:00
|
|
|
import "../../elements/buttons/Dropdown";
|
2021-09-21 09:31:37 +00:00
|
|
|
import "../../elements/buttons/SpinnerButton";
|
2021-08-12 20:03:13 +00:00
|
|
|
import "../../elements/forms/DeleteBulkForm";
|
2021-04-02 10:12:14 +00:00
|
|
|
import "../../elements/forms/ModalForm";
|
|
|
|
import "../../elements/forms/ProxyForm";
|
2021-09-21 09:31:37 +00:00
|
|
|
import { TableColumn } from "../../elements/table/Table";
|
|
|
|
import { TablePage } from "../../elements/table/TablePage";
|
2021-04-02 10:12:14 +00:00
|
|
|
import "./ldap/LDAPSourceForm";
|
2021-04-02 13:15:19 +00:00
|
|
|
import "./oauth/OAuthSourceForm";
|
2021-05-02 12:43:51 +00:00
|
|
|
import "./plex/PlexSourceForm";
|
2021-09-21 09:31:37 +00:00
|
|
|
import "./saml/SAMLSourceForm";
|
2021-02-09 16:04:55 +00:00
|
|
|
|
2021-02-09 09:22:49 +00:00
|
|
|
@customElement("ak-source-list")
|
|
|
|
export class SourceListPage extends TablePage<Source> {
|
|
|
|
pageTitle(): string {
|
2021-04-03 22:10:56 +00:00
|
|
|
return t`Sources`;
|
2021-02-09 09:22:49 +00:00
|
|
|
}
|
|
|
|
pageDescription(): string | undefined {
|
2021-08-29 11:49:57 +00:00
|
|
|
return t`Sources of identities, which can either be synced into authentik's database, or can be used by users to authenticate and enroll themselves.`;
|
2021-02-09 09:22:49 +00:00
|
|
|
}
|
|
|
|
pageIcon(): string {
|
|
|
|
return "pf-icon pf-icon-middleware";
|
|
|
|
}
|
|
|
|
searchEnabled(): boolean {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-08-05 10:30:43 +00:00
|
|
|
checkbox = true;
|
|
|
|
|
2021-02-09 09:22:49 +00:00
|
|
|
@property()
|
|
|
|
order = "name";
|
|
|
|
|
2021-10-14 10:48:52 +00:00
|
|
|
async apiEndpoint(page: number): Promise<AKResponse<Source>> {
|
2021-03-08 10:14:00 +00:00
|
|
|
return new SourcesApi(DEFAULT_CONFIG).sourcesAllList({
|
2021-02-09 09:22:49 +00:00
|
|
|
ordering: this.order,
|
|
|
|
page: page,
|
2021-10-14 10:48:52 +00:00
|
|
|
pageSize: (await uiConfig()).pagination.perPage,
|
2021-02-09 09:22:49 +00:00
|
|
|
search: this.search || "",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
columns(): TableColumn[] {
|
2021-08-03 15:52:21 +00:00
|
|
|
return [new TableColumn(t`Name`, "name"), new TableColumn(t`Type`), new TableColumn("")];
|
2021-02-09 09:22:49 +00:00
|
|
|
}
|
|
|
|
|
2021-08-05 10:30:43 +00:00
|
|
|
renderToolbarSelected(): TemplateResult {
|
2021-08-12 20:03:13 +00:00
|
|
|
const disabled = this.selectedElements.length < 1;
|
|
|
|
return html`<ak-forms-delete-bulk
|
|
|
|
objectLabel=${t`Source(s)`}
|
|
|
|
.objects=${this.selectedElements}
|
|
|
|
.usedBy=${(item: Source) => {
|
2021-08-05 10:30:43 +00:00
|
|
|
return new SourcesApi(DEFAULT_CONFIG).sourcesAllUsedByList({
|
|
|
|
slug: item.slug,
|
|
|
|
});
|
|
|
|
}}
|
2021-08-12 20:03:13 +00:00
|
|
|
.delete=${(item: Source) => {
|
2021-08-05 10:30:43 +00:00
|
|
|
return new SourcesApi(DEFAULT_CONFIG).sourcesAllDestroy({
|
|
|
|
slug: item.slug,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<button ?disabled=${disabled} slot="trigger" class="pf-c-button pf-m-danger">
|
|
|
|
${t`Delete`}
|
|
|
|
</button>
|
2021-08-12 20:03:13 +00:00
|
|
|
</ak-forms-delete-bulk>`;
|
2021-08-05 10:30:43 +00:00
|
|
|
}
|
|
|
|
|
2021-02-09 09:22:49 +00:00
|
|
|
row(item: Source): TemplateResult[] {
|
2021-04-09 14:21:17 +00:00
|
|
|
if (item.component === "") {
|
|
|
|
return this.rowInbuilt(item);
|
|
|
|
}
|
2021-02-09 09:22:49 +00:00
|
|
|
return [
|
2021-02-19 18:29:17 +00:00
|
|
|
html`<a href="#/core/sources/${item.slug}">
|
2021-02-09 09:22:49 +00:00
|
|
|
<div>${item.name}</div>
|
2021-04-03 17:26:43 +00:00
|
|
|
${item.enabled ? html`` : html`<small>${t`Disabled`}</small>`}
|
2021-02-09 09:22:49 +00:00
|
|
|
</a>`,
|
2021-03-08 10:14:00 +00:00
|
|
|
html`${item.verboseName}`,
|
2021-08-03 15:52:21 +00:00
|
|
|
html` <ak-forms-modal>
|
2021-08-05 10:30:43 +00:00
|
|
|
<span slot="submit"> ${t`Update`} </span>
|
|
|
|
<span slot="header"> ${t`Update ${item.verboseName}`} </span>
|
|
|
|
<ak-proxy-form
|
|
|
|
slot="form"
|
|
|
|
.args=${{
|
|
|
|
instancePk: item.slug,
|
2021-08-03 15:52:21 +00:00
|
|
|
}}
|
2021-08-05 10:30:43 +00:00
|
|
|
type=${ifDefined(item.component)}
|
2021-08-03 15:52:21 +00:00
|
|
|
>
|
2021-08-05 10:30:43 +00:00
|
|
|
</ak-proxy-form>
|
|
|
|
<button slot="trigger" class="pf-c-button pf-m-plain">
|
|
|
|
<i class="fas fa-edit"></i>
|
|
|
|
</button>
|
|
|
|
</ak-forms-modal>`,
|
2021-02-09 09:22:49 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-04-09 14:21:17 +00:00
|
|
|
rowInbuilt(item: Source): TemplateResult[] {
|
|
|
|
return [
|
|
|
|
html`<span>
|
|
|
|
<div>${item.name}</div>
|
|
|
|
<small>${t`Built-in`}</small>
|
|
|
|
</span>`,
|
|
|
|
html`${t`Built-in`}`,
|
|
|
|
html``,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-02-10 19:12:15 +00:00
|
|
|
renderToolbar(): TemplateResult {
|
2021-08-03 15:52:21 +00:00
|
|
|
return html` <ak-dropdown class="pf-c-dropdown">
|
|
|
|
<button class="pf-m-primary pf-c-dropdown__toggle" type="button">
|
|
|
|
<span class="pf-c-dropdown__toggle-text">${t`Create`}</span>
|
|
|
|
<i class="fas fa-caret-down pf-c-dropdown__toggle-icon" aria-hidden="true"></i>
|
|
|
|
</button>
|
|
|
|
<ul class="pf-c-dropdown__menu" hidden>
|
|
|
|
${until(
|
|
|
|
new SourcesApi(DEFAULT_CONFIG).sourcesAllTypesList().then((types) => {
|
|
|
|
return types.map((type) => {
|
|
|
|
return html`<li>
|
|
|
|
<ak-forms-modal>
|
|
|
|
<span slot="submit"> ${t`Create`} </span>
|
|
|
|
<span slot="header"> ${t`Create ${type.name}`} </span>
|
|
|
|
<ak-proxy-form
|
|
|
|
slot="form"
|
|
|
|
.args=${{
|
|
|
|
modelName: type.modelName,
|
|
|
|
}}
|
|
|
|
type=${type.component}
|
|
|
|
>
|
|
|
|
</ak-proxy-form>
|
|
|
|
<button slot="trigger" class="pf-c-dropdown__menu-item">
|
|
|
|
${type.name}<br />
|
|
|
|
<small>${type.description}</small>
|
|
|
|
</button>
|
|
|
|
</ak-forms-modal>
|
|
|
|
</li>`;
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
html`<ak-spinner></ak-spinner>`,
|
|
|
|
)}
|
|
|
|
</ul>
|
|
|
|
</ak-dropdown>
|
|
|
|
${super.renderToolbar()}`;
|
2021-02-10 19:12:15 +00:00
|
|
|
}
|
2021-02-09 09:22:49 +00:00
|
|
|
}
|