This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/web/src/pages/sources/SourcesListPage.ts

154 lines
5.8 KiB
TypeScript
Raw Normal View History

import { t } from "@lingui/macro";
2021-02-09 16:04:55 +00:00
import { customElement, html, property, TemplateResult } from "lit-element";
import { AKResponse } from "../../api/Client";
2021-02-09 09:22:49 +00:00
import { TableColumn } from "../../elements/table/Table";
import { TablePage } from "../../elements/table/TablePage";
2021-02-09 16:04:55 +00:00
import "../../elements/buttons/SpinnerButton";
2021-02-10 19:12:15 +00:00
import "../../elements/buttons/Dropdown";
import "../../elements/forms/DeleteForm";
import "../../elements/forms/ModalForm";
import "../../elements/forms/ProxyForm";
2021-02-10 19:12:15 +00:00
import { until } from "lit-html/directives/until";
2021-03-02 14:12:26 +00:00
import { PAGE_SIZE } from "../../constants";
import { Source, SourcesApi } from "authentik-api";
import { DEFAULT_CONFIG } from "../../api/Config";
import { ifDefined } from "lit-html/directives/if-defined";
import "./ldap/LDAPSourceForm";
import "./saml/SAMLSourceForm";
import "./oauth/OAuthSourceForm";
import "./plex/PlexSourceForm";
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 {
return t`Sources`;
2021-02-09 09:22:49 +00:00
}
pageDescription(): string | undefined {
return t`Sources of identities, which can either be synced into authentik's database, like LDAP, or can be used by users to authenticate and enroll themselves, like OAuth and social logins`;
2021-02-09 09:22:49 +00:00
}
pageIcon(): string {
return "pf-icon pf-icon-middleware";
}
searchEnabled(): boolean {
return true;
}
checkbox = true;
2021-02-09 09:22:49 +00:00
@property()
order = "name";
2021-02-09 16:04:55 +00:00
apiEndpoint(page: number): Promise<AKResponse<Source>> {
return new SourcesApi(DEFAULT_CONFIG).sourcesAllList({
2021-02-09 09:22:49 +00:00
ordering: this.order,
page: page,
pageSize: PAGE_SIZE,
2021-02-09 09:22:49 +00:00
search: this.search || "",
});
}
columns(): TableColumn[] {
return [new TableColumn(t`Name`, "name"), new TableColumn(t`Type`), new TableColumn("")];
2021-02-09 09:22:49 +00:00
}
renderToolbarSelected(): TemplateResult {
const disabled = this.selectedElements.length !== 1;
const item = this.selectedElements[0];
return html`<ak-forms-delete
.obj=${item}
objectLabel=${t`Source`}
.usedBy=${() => {
return new SourcesApi(DEFAULT_CONFIG).sourcesAllUsedByList({
slug: item.slug,
});
}}
.delete=${() => {
return new SourcesApi(DEFAULT_CONFIG).sourcesAllDestroy({
slug: item.slug,
});
}}
>
<button ?disabled=${disabled} slot="trigger" class="pf-c-button pf-m-danger">
${t`Delete`}
</button>
</ak-forms-delete>`;
}
2021-02-09 09:22:49 +00:00
row(item: Source): TemplateResult[] {
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>
${item.enabled ? html`` : html`<small>${t`Disabled`}</small>`}
2021-02-09 09:22:49 +00:00
</a>`,
html`${item.verboseName}`,
html` <ak-forms-modal>
<span slot="submit"> ${t`Update`} </span>
<span slot="header"> ${t`Update ${item.verboseName}`} </span>
<ak-proxy-form
slot="form"
.args=${{
instancePk: item.slug,
}}
type=${ifDefined(item.component)}
>
</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
];
}
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 {
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
}