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";
|
2021-03-01 19:33:00 +00:00
|
|
|
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";
|
2021-03-16 20:32:39 +00:00
|
|
|
import { CoreApi, User } from "authentik-api";
|
2021-03-08 10:14:00 +00:00
|
|
|
import { DEFAULT_CONFIG } from "../../api/Config";
|
|
|
|
import { AdminURLManager } from "../../api/legacy";
|
2021-03-18 11:14:27 +00:00
|
|
|
import "../../elements/forms/DeleteForm";
|
2021-03-18 12:09:00 +00:00
|
|
|
import "./UserActiveForm";
|
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 {
|
2021-03-20 15:06:56 +00:00
|
|
|
return "pf-icon pf-icon-user";
|
2021-02-19 17:43:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@property()
|
2021-03-20 17:39:12 +00:00
|
|
|
order = "last_login";
|
2021-02-19 17:43:57 +00:00
|
|
|
|
|
|
|
apiEndpoint(page: number): Promise<AKResponse<User>> {
|
2021-03-08 10:14:00 +00:00
|
|
|
return new CoreApi(DEFAULT_CONFIG).coreUsersList({
|
2021-02-19 17:43:57 +00:00
|
|
|
ordering: this.order,
|
|
|
|
page: page,
|
2021-03-08 10:14:00 +00:00
|
|
|
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 [
|
2021-03-20 15:37:31 +00:00
|
|
|
html`<a href="#/identity/users/${item.pk}">
|
2021-02-19 17:43:57 +00:00
|
|
|
<div>${item.username}</div>
|
|
|
|
<small>${item.name}</small>
|
2021-03-20 15:37:31 +00:00
|
|
|
</a>`,
|
2021-03-08 10:14:00 +00:00
|
|
|
html`${item.isActive ? "Yes" : "No"}`,
|
|
|
|
html`${item.lastLogin?.toLocaleString()}`,
|
2021-02-19 17:43:57 +00:00
|
|
|
html`
|
2021-03-08 10:14:00 +00:00
|
|
|
<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">
|
2021-03-08 10:14:00 +00:00
|
|
|
<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>
|
2021-03-18 12:09:00 +00:00
|
|
|
<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>
|
2021-03-18 11:14:27 +00:00
|
|
|
<ak-forms-delete
|
|
|
|
.obj=${item}
|
|
|
|
objectLabel=${gettext("User")}
|
|
|
|
.delete=${() => {
|
|
|
|
return new CoreApi(DEFAULT_CONFIG).coreUsersDelete({
|
|
|
|
id: item.pk || 0
|
|
|
|
});
|
|
|
|
}}>
|
2021-03-18 12:09:00 +00:00
|
|
|
<button slot="trigger" class="pf-c-dropdown__menu-item">
|
2021-02-19 17:43:57 +00:00
|
|
|
${gettext("Delete")}
|
|
|
|
</button>
|
2021-03-18 11:14:27 +00:00
|
|
|
</ak-forms-delete>
|
2021-02-19 17:43:57 +00:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</ak-dropdown>
|
2021-03-08 10:14:00 +00:00
|
|
|
<ak-action-button method="GET" url="${AdminURLManager.users(`${item.pk}/reset/`)}">
|
2021-02-19 17:43:57 +00:00
|
|
|
${gettext("Reset Password")}
|
2021-03-01 19:33:00 +00:00
|
|
|
</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`
|
2021-03-08 10:14:00 +00:00
|
|
|
<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()}
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|