import { t } from "@lingui/macro"; import { CSSResult, customElement, html, property, TemplateResult } from "lit-element"; import { AKResponse } from "../../../api/Client"; import PFDescriptionList from "@patternfly/patternfly/components/DescriptionList/description-list.css"; import "../../../elements/forms/DeleteBulkForm"; import "../../../elements/forms/ModalForm"; 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, IntentEnum, Token } from "@goauthentik/api"; import { DEFAULT_CONFIG } from "../../../api/Config"; import "./UserTokenForm"; import { IntentToLabel } from "../../tokens/TokenListPage"; @customElement("ak-user-token-list") export class UserTokenList extends Table { searchEnabled(): boolean { return true; } expandable = true; checkbox = 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(t`Identifier`, "identifier"), new TableColumn("")]; } static get styles(): CSSResult[] { return super.styles.concat(PFDescriptionList); } renderToolbar(): TemplateResult { return html` ${t`Create`} ${t`Create Token`} ${t`Create`} ${t`Create App password`} ${super.renderToolbar()} `; } renderExpanded(item: Token): TemplateResult { return html`
${t`User`}
${item.user?.username}
${t`Expiring`}
${item.expiring ? t`Yes` : t`No`}
${t`Expiring`}
${item.expiring ? item.expires?.toLocaleString() : "-"}
${t`Intent`}
${IntentToLabel(item.intent || IntentEnum.Api)}
`; } renderToolbarSelected(): TemplateResult { const disabled = this.selectedElements.length < 1; return html` { return new CoreApi(DEFAULT_CONFIG).coreTokensDestroy({ identifier: item.identifier, }); }} > `; } row(item: Token): TemplateResult[] { return [ html`${item.identifier}`, html` ${t`Update`} ${t`Update Token`} ${t`Copy Key`} `, ]; } }