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 } from "../../api/Config"; import "../../elements/forms/DeleteForm"; import "./UserActiveForm"; import "./UserForm"; import { showMessage } from "../../elements/messages/MessageContainer"; import { MessageLevel } from "../../elements/messages/Message"; @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"; apiEndpoint(page: number): Promise> { return new CoreApi(DEFAULT_CONFIG).coreUsersList({ ordering: this.order, page: page, pageSize: PAGE_SIZE, search: this.search || "", }); } columns(): TableColumn[] { return [ new TableColumn(t`Name`, t`username`), new TableColumn(t`Active`, t`active`), new TableColumn(t`Last login`, t`last_login`), new TableColumn(""), ]; } row(item: User): TemplateResult[] { return [ html`
${item.username}
${item.name}
`, html`${item.isActive ? t`Yes` : t`No`}`, html`${item.lastLogin?.toLocaleString()}`, html` ${t`Update`} ${t`Update User`} { return new CoreApi(DEFAULT_CONFIG).coreUsersRecovery({ id: item.pk || 0, }).then(rec => { showMessage({ level: MessageLevel.success, message: t`Successfully generated recovery link`, description: rec.link }); }); }}> ${t`Reset Password`} ${t`Impersonate`} `, ]; } renderToolbar(): TemplateResult { return html` ${t`Create`} ${t`Create User`} ${super.renderToolbar()} `; } }