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/users/UserListPage.ts

119 lines
4.6 KiB
TypeScript
Raw Normal View History

2021-02-19 17:43:57 +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/ModalButton";
import "../../elements/buttons/Dropdown";
import "../../elements/buttons/ActionButton";
2021-02-19 17:43:57 +00:00
import { TableColumn } from "../../elements/table/Table";
2021-03-02 14:12:26 +00:00
import { PAGE_SIZE } from "../../constants";
import { CoreApi, User } from "../../api";
import { DEFAULT_CONFIG } from "../../api/Config";
import { AdminURLManager } from "../../api/legacy";
2021-02-19 17:43:57 +00:00
@customElement("ak-user-list")
export class UserListPage extends TablePage<User> {
searchEnabled(): boolean {
return true;
}
pageTitle(): string {
return gettext("Users");
}
pageDescription(): string {
return "";
}
pageIcon(): string {
return gettext("pf-icon pf-icon-user");
}
@property()
order = "username";
apiEndpoint(page: number): Promise<AKResponse<User>> {
return new CoreApi(DEFAULT_CONFIG).coreUsersList({
2021-02-19 17:43:57 +00:00
ordering: this.order,
page: page,
pageSize: PAGE_SIZE,
2021-02-19 17:43:57 +00:00
search: this.search || "",
});
}
columns(): TableColumn[] {
return [
new TableColumn("Name", "username"),
new TableColumn("Active", "active"),
new TableColumn("Last login", "last_login"),
new TableColumn(""),
];
}
row(item: User): TemplateResult[] {
return [
html`<div>
<div>${item.username}</div>
<small>${item.name}</small>
</div>`,
html`${item.isActive ? "Yes" : "No"}`,
html`${item.lastLogin?.toLocaleString()}`,
2021-02-19 17:43:57 +00:00
html`
<ak-modal-button href="${AdminURLManager.users(`${item.pk}/update/`)}">
2021-02-19 17:43:57 +00:00
<ak-spinner-button slot="trigger" class="pf-m-secondary">
${gettext("Edit")}
</ak-spinner-button>
<div slot="modal"></div>
</ak-modal-button>
<ak-dropdown class="pf-c-dropdown">
<button class="pf-c-dropdown__toggle pf-m-primary" type="button">
<span class="pf-c-dropdown__toggle-text">${gettext(item.isActive ? "Disable" : "Enable")}</span>
2021-02-19 17:43:57 +00:00
<i class="fas fa-caret-down pf-c-dropdown__toggle-icon" aria-hidden="true"></i>
</button>
<ul class="pf-c-dropdown__menu" hidden>
<li>
${item.isActive ?
html`<ak-modal-button href="${AdminURLManager.users(`${item.pk}/disable/`)}">
2021-02-19 17:43:57 +00:00
<button slot="trigger" class="pf-c-dropdown__menu-item">
${gettext("Disable")}
</button>
<div slot="modal"></div>
</ak-modal-button>`:
html`<ak-modal-button href="${AdminURLManager.users(`${item.pk}/enable/`)}">
2021-02-19 17:43:57 +00:00
<button slot="trigger" class="pf-c-dropdown__menu-item">
${gettext("Enable")}
</button>
<div slot="modal"></div>
</ak-modal-button>`}
</li>
<li class="pf-c-divider" role="separator"></li>
<li>
<ak-modal-button href="${AdminURLManager.users(`${item.pk}/delete/`)}">
2021-02-19 17:43:57 +00:00
<button slot="trigger" class="pf-c-dropdown__menu-item">
${gettext("Delete")}
</button>
<div slot="modal"></div>
</ak-modal-button>
</li>
</ul>
</ak-dropdown>
<ak-action-button method="GET" url="${AdminURLManager.users(`${item.pk}/reset/`)}">
2021-02-19 17:43:57 +00:00
${gettext("Reset Password")}
</ak-action-button>
2021-02-19 17:43:57 +00:00
<a class="pf-c-button pf-m-tertiary" href="${`-/impersonation/${item.pk}/`}">
${gettext("Impersonate")}
</a>`,
];
}
renderToolbar(): TemplateResult {
return html`
<ak-modal-button href=${AdminURLManager.users("create/")}>
2021-02-19 17:43:57 +00:00
<ak-spinner-button slot="trigger" class="pf-m-primary">
${gettext("Create")}
</ak-spinner-button>
<div slot="modal"></div>
</ak-modal-button>
${super.renderToolbar()}
`;
}
}