import { t } from "@lingui/macro"; import { customElement, html, property, TemplateResult } from "lit-element"; import { AKResponse } from "../../api/Client"; import { TablePage } from "../../elements/table/TablePage"; import "../../elements/forms/ModalForm"; import "../../elements/buttons/Dropdown"; import "../../elements/buttons/ActionButton"; import { TableColumn } from "../../elements/table/Table"; import { PAGE_SIZE } from "../../constants"; import { CoreApi, User } from "authentik-api"; import { DEFAULT_CONFIG, tenant } from "../../api/Config"; import "../../elements/forms/DeleteForm"; import "./UserActiveForm"; import "./UserForm"; import { showMessage } from "../../elements/messages/MessageContainer"; import { MessageLevel } from "../../elements/messages/Message"; import { first } from "../../utils"; import { until } from "lit-html/directives/until"; @customElement("ak-user-list") export class UserListPage extends TablePage { searchEnabled(): boolean { return true; } pageTitle(): string { return t`Users`; } pageDescription(): string { return ""; } pageIcon(): string { return "pf-icon pf-icon-user"; } @property() order = "last_login"; @property({ type: Boolean }) hideServiceAccounts = true; apiEndpoint(page: number): Promise> { return new CoreApi(DEFAULT_CONFIG).coreUsersList({ ordering: this.order, page: page, pageSize: PAGE_SIZE, search: this.search || "", attributes: this.hideServiceAccounts ? JSON.stringify({ "goauthentik.io/user/service-account__isnull": "true", }) : undefined, }); } columns(): TableColumn[] { return [ new TableColumn(t`Name`, "username"), new TableColumn(t`Active`, "active"), new TableColumn(t`Last login`, "last_login"), new TableColumn(t`Actions`), ]; } row(item: User): TemplateResult[] { return [ html`
${item.username}
${item.name}
`, html`${item.isActive ? t`Yes` : t`No`}`, html`${first(item.lastLogin?.toLocaleString(), "-")}`, html` ${t`Update`} ${t`Update User`} ${until( tenant().then((te) => { if (te.flowRecovery) { return html` { return new CoreApi(DEFAULT_CONFIG) .coreUsersRecoveryRetrieve({ id: item.pk || 0, }) .then((rec) => { showMessage({ level: MessageLevel.success, message: t`Successfully generated recovery link`, description: rec.link, }); }) .catch((ex: Response) => { ex.json().then(() => { showMessage({ level: MessageLevel.error, message: t`No recovery flow is configured.`, }); }); }); }} > ${t`Reset Password`} `; } return html``; }), )} ${t`Impersonate`} `, ]; } renderToolbar(): TemplateResult { return html` ${t`Create`} ${t`Create User`} ${super.renderToolbar()} `; } renderToolbarAfter(): TemplateResult { return html` 
{ this.hideServiceAccounts = !this.hideServiceAccounts; this.page = 1; this.fetch(); }} />
`; } }