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

159 lines
5.9 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/forms/ModalForm";
2021-02-19 17:43:57 +00:00
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 "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";
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 "pf-icon pf-icon-user";
2021-02-19 17:43:57 +00:00
}
@property()
order = "last_login";
2021-02-19 17:43:57 +00:00
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`<a href="#/identity/users/${item.pk}">
2021-02-19 17:43:57 +00:00
<div>${item.username}</div>
<small>${item.name}</small>
</a>`,
html`${item.isActive ? "Yes" : "No"}`,
html`${item.lastLogin?.toLocaleString()}`,
2021-02-19 17:43:57 +00:00
html`
<ak-forms-modal>
<span slot="submit">
${gettext("Update")}
</span>
<span slot="header">
${gettext("Update User")}
</span>
<ak-user-form slot="form" .user=${item}>
</ak-user-form>
<button slot="trigger" class="pf-m-secondary pf-c-button">
2021-02-19 17:43:57 +00:00
${gettext("Edit")}
</button>
</ak-forms-modal>
2021-02-19 17:43:57 +00:00
<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>
<ak-user-active-form
.obj=${item}
objectLabel=${gettext("User")}
.delete=${() => {
return new CoreApi(DEFAULT_CONFIG).coreUsersPartialUpdate({
id: item.pk || 0,
data: {
username: item.username,
name: item.name,
isActive: !item.isActive,
}
});
}}>
<button slot="trigger" class="pf-c-dropdown__menu-item">
${item.isActive ? gettext("Disable") : gettext("Enable")}
</button>
</ak-user-active-form>
2021-02-19 17:43:57 +00:00
</li>
<li class="pf-c-divider" role="separator"></li>
<li>
<ak-forms-delete
.obj=${item}
objectLabel=${gettext("User")}
.delete=${() => {
return new CoreApi(DEFAULT_CONFIG).coreUsersDelete({
id: item.pk || 0
});
}}>
<button slot="trigger" class="pf-c-dropdown__menu-item">
2021-02-19 17:43:57 +00:00
${gettext("Delete")}
</button>
</ak-forms-delete>
2021-02-19 17:43:57 +00:00
</li>
</ul>
</ak-dropdown>
<ak-action-button
.apiRequest=${() => {
return new CoreApi(DEFAULT_CONFIG).coreUsersRecovery({
id: item.pk || 0,
}).then(rec => {
showMessage({
level: MessageLevel.success,
message: gettext("Successfully generated recovery link"),
description: rec.link
});
});
}}>
2021-02-19 17:43:57 +00:00
${gettext("Reset Password")}
</ak-action-button>
<a class="pf-c-button pf-m-tertiary" href="${`/-/impersonation/${item.pk}/`}">
2021-02-19 17:43:57 +00:00
${gettext("Impersonate")}
</a>`,
];
}
renderToolbar(): TemplateResult {
return html`
<ak-forms-modal>
<span slot="submit">
${gettext("Create")}
</span>
<span slot="header">
${gettext("Create User")}
</span>
<ak-user-form slot="form">
</ak-user-form>
<button slot="trigger" class="pf-c-button pf-m-primary">
2021-02-19 17:43:57 +00:00
${gettext("Create")}
</button>
</ak-forms-modal>
2021-02-19 17:43:57 +00:00
${super.renderToolbar()}
`;
}
2021-02-19 17:43:57 +00:00
}