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/tokens/TokenListPage.ts

78 lines
2.5 KiB
TypeScript
Raw Normal View History

2021-02-19 17:59:24 +00:00
import { gettext } from "django";
import { customElement, html, property, TemplateResult } from "lit-element";
import { AKResponse } from "../../api/Client";
import { TablePage } from "../../elements/table/TablePage";
import "../../elements/buttons/Dropdown";
import "../../elements/buttons/TokenCopyButton";
import "../../elements/forms/DeleteForm";
2021-02-19 17:59:24 +00:00
import { TableColumn } from "../../elements/table/Table";
2021-03-02 14:12:26 +00:00
import { PAGE_SIZE } from "../../constants";
import { CoreApi, Token } from "authentik-api";
import { DEFAULT_CONFIG } from "../../api/Config";
2021-02-19 17:59:24 +00:00
@customElement("ak-token-list")
export class TokenListPage extends TablePage<Token> {
searchEnabled(): boolean {
return true;
}
pageTitle(): string {
return gettext("Tokens");
}
pageDescription(): string {
return gettext("Tokens are used throughout authentik for Email validation stages, Recovery keys and API access.");
}
pageIcon(): string {
return "pf-icon pf-icon-security";
2021-02-19 17:59:24 +00:00
}
@property()
order = "expires";
apiEndpoint(page: number): Promise<AKResponse<Token>> {
return new CoreApi(DEFAULT_CONFIG).coreTokensList({
2021-02-19 17:59:24 +00:00
ordering: this.order,
page: page,
pageSize: PAGE_SIZE,
2021-02-19 17:59:24 +00:00
search: this.search || "",
});
}
columns(): TableColumn[] {
return [
new TableColumn("Identifier", "identifier"),
new TableColumn("User", "user"),
new TableColumn("Expires?", "expiring"),
new TableColumn("Expiry date", "expires"),
new TableColumn(""),
];
}
row(item: Token): TemplateResult[] {
return [
html`${item.identifier}`,
html`${item.user?.username}`,
2021-02-19 17:59:24 +00:00
html`${item.expiring ? "Yes" : "No"}`,
html`${item.expiring ? item.expires?.toLocaleString() : "-"}`,
2021-02-19 17:59:24 +00:00
html`
<ak-forms-delete
.obj=${item}
objectLabel=${gettext("Token")}
.delete=${() => {
return new CoreApi(DEFAULT_CONFIG).coreTokensDelete({
identifier: item.identifier
});
}}>
<button slot="trigger" class="pf-c-button pf-m-danger">
${gettext("Delete")}
</button>
</ak-forms-delete>
2021-02-19 17:59:24 +00:00
<ak-token-copy-button identifier="${item.identifier}">
${gettext("Copy Key")}
2021-02-19 17:59:24 +00:00
</ak-token-copy-button>
`,
];
}
}