import { gettext } from "django"; import { customElement, html, property, TemplateResult } from "lit-element"; import { AKResponse } from "../../api/Client"; import "../../elements/forms/DeleteForm"; import "../../elements/buttons/ModalButton"; import "../../elements/buttons/Dropdown"; import "../../elements/buttons/TokenCopyButton"; import { Table, TableColumn } from "../../elements/table/Table"; import { PAGE_SIZE } from "../../constants"; import { CoreApi, Token } from "authentik-api"; import { DEFAULT_CONFIG } from "../../api/Config"; import { AdminURLManager } from "../../api/legacy"; @customElement("ak-token-user-list") export class UserTokenList extends Table { searchEnabled(): boolean { return true; } expandable = true; @property() order = "expires"; apiEndpoint(page: number): Promise> { return new CoreApi(DEFAULT_CONFIG).coreTokensList({ ordering: this.order, page: page, pageSize: PAGE_SIZE, search: this.search || "", }); } columns(): TableColumn[] { return [ new TableColumn("Identifier", "identifier"), new TableColumn(""), ]; } renderToolbar(): TemplateResult { return html` ${gettext("Create")}
${super.renderToolbar()} `; } renderExpanded(item: Token): TemplateResult { return html`
${gettext("User")}
${item.user.username}
${gettext("Expiring")}
${item.expiring ? "Yes" : "No"}
${gettext("Expiring")}
${item.expiring ? item.expires?.toLocaleString() : "-"}
`; } row(item: Token): TemplateResult[] { return [ html`${item.identifier}`, html` ${gettext("Edit")}
{ return new CoreApi(DEFAULT_CONFIG).coreTokensDelete({ identifier: item.identifier }); }}> ${gettext("Copy Key")} `, ]; } }