2021-04-03 17:26:43 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-02-19 17:43:57 +00:00
|
|
|
import { customElement, html, property, TemplateResult } from "lit-element";
|
|
|
|
import { AKResponse } from "../../api/Client";
|
|
|
|
import { TablePage } from "../../elements/table/TablePage";
|
|
|
|
|
2021-03-29 14:16:27 +00:00
|
|
|
import "../../elements/forms/ModalForm";
|
2021-02-19 17:43:57 +00:00
|
|
|
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";
|
2021-03-18 11:14:27 +00:00
|
|
|
import "../../elements/forms/DeleteForm";
|
2021-03-18 12:09:00 +00:00
|
|
|
import "./UserActiveForm";
|
2021-03-29 14:16:27 +00:00
|
|
|
import "./UserForm";
|
|
|
|
import { showMessage } from "../../elements/messages/MessageContainer";
|
|
|
|
import { MessageLevel } from "../../elements/messages/Message";
|
2021-04-10 18:19:23 +00:00
|
|
|
import { first } from "../../utils";
|
2021-02-19 17:43:57 +00:00
|
|
|
|
|
|
|
@customElement("ak-user-list")
|
|
|
|
export class UserListPage extends TablePage<User> {
|
|
|
|
searchEnabled(): boolean {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
pageTitle(): string {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Users`;
|
2021-02-19 17:43:57 +00:00
|
|
|
}
|
|
|
|
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 [
|
2021-04-04 14:56:16 +00:00
|
|
|
new TableColumn(t`Name`, "username"),
|
|
|
|
new TableColumn(t`Active`, "active"),
|
|
|
|
new TableColumn(t`Last login`, "last_login"),
|
2021-02-19 17:43:57 +00:00
|
|
|
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-04-03 17:59:22 +00:00
|
|
|
html`${item.isActive ? t`Yes` : t`No`}`,
|
2021-04-10 18:19:23 +00:00
|
|
|
html`${first(item.lastLogin?.toLocaleString(), "-")}`,
|
2021-02-19 17:43:57 +00:00
|
|
|
html`
|
2021-03-29 14:16:27 +00:00
|
|
|
<ak-forms-modal>
|
|
|
|
<span slot="submit">
|
2021-04-03 17:26:43 +00:00
|
|
|
${t`Update`}
|
2021-03-29 14:16:27 +00:00
|
|
|
</span>
|
|
|
|
<span slot="header">
|
2021-04-03 17:26:43 +00:00
|
|
|
${t`Update User`}
|
2021-03-29 14:16:27 +00:00
|
|
|
</span>
|
|
|
|
<ak-user-form slot="form" .user=${item}>
|
|
|
|
</ak-user-form>
|
|
|
|
<button slot="trigger" class="pf-m-secondary pf-c-button">
|
2021-04-03 17:26:43 +00:00
|
|
|
${t`Edit`}
|
2021-03-29 14:16:27 +00:00
|
|
|
</button>
|
|
|
|
</ak-forms-modal>
|
2021-02-19 17:43:57 +00:00
|
|
|
<ak-dropdown class="pf-c-dropdown">
|
2021-04-04 18:52:06 +00:00
|
|
|
<button class="pf-m-primary pf-c-dropdown__toggle" type="button">
|
2021-04-03 17:26:43 +00:00
|
|
|
<span class="pf-c-dropdown__toggle-text">${item.isActive ? t`Disable` : t`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}
|
2021-04-03 17:26:43 +00:00
|
|
|
objectLabel=${t`User`}
|
2021-03-18 12:09:00 +00:00
|
|
|
.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">
|
2021-04-03 17:26:43 +00:00
|
|
|
${item.isActive ? t`Disable` : t`Enable`}
|
2021-03-18 12:09:00 +00:00
|
|
|
</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}
|
2021-04-03 17:26:43 +00:00
|
|
|
objectLabel=${t`User`}
|
2021-03-18 11:14:27 +00:00
|
|
|
.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-04-03 17:26:43 +00:00
|
|
|
${t`Delete`}
|
2021-02-19 17:43:57 +00:00
|
|
|
</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-29 14:16:27 +00:00
|
|
|
<ak-action-button
|
|
|
|
.apiRequest=${() => {
|
|
|
|
return new CoreApi(DEFAULT_CONFIG).coreUsersRecovery({
|
|
|
|
id: item.pk || 0,
|
|
|
|
}).then(rec => {
|
|
|
|
showMessage({
|
|
|
|
level: MessageLevel.success,
|
2021-04-03 17:26:43 +00:00
|
|
|
message: t`Successfully generated recovery link`,
|
2021-03-29 14:16:27 +00:00
|
|
|
description: rec.link
|
|
|
|
});
|
2021-04-16 08:09:46 +00:00
|
|
|
}).catch((ex: Response) => {
|
|
|
|
ex.json().then(() => {
|
|
|
|
showMessage({
|
|
|
|
level: MessageLevel.error,
|
|
|
|
message: t`No recovery flow is configured.`,
|
|
|
|
});
|
|
|
|
});
|
2021-03-29 14:16:27 +00:00
|
|
|
});
|
|
|
|
}}>
|
2021-04-03 17:26:43 +00:00
|
|
|
${t`Reset Password`}
|
2021-03-01 19:33:00 +00:00
|
|
|
</ak-action-button>
|
2021-03-22 12:44:17 +00:00
|
|
|
<a class="pf-c-button pf-m-tertiary" href="${`/-/impersonation/${item.pk}/`}">
|
2021-04-03 17:26:43 +00:00
|
|
|
${t`Impersonate`}
|
2021-02-19 17:43:57 +00:00
|
|
|
</a>`,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
renderToolbar(): TemplateResult {
|
|
|
|
return html`
|
2021-03-29 14:16:27 +00:00
|
|
|
<ak-forms-modal>
|
|
|
|
<span slot="submit">
|
2021-04-03 17:26:43 +00:00
|
|
|
${t`Create`}
|
2021-03-29 14:16:27 +00:00
|
|
|
</span>
|
|
|
|
<span slot="header">
|
2021-04-03 17:26:43 +00:00
|
|
|
${t`Create User`}
|
2021-03-29 14:16:27 +00:00
|
|
|
</span>
|
|
|
|
<ak-user-form slot="form">
|
|
|
|
</ak-user-form>
|
|
|
|
<button slot="trigger" class="pf-c-button pf-m-primary">
|
2021-04-03 17:26:43 +00:00
|
|
|
${t`Create`}
|
2021-03-29 14:16:27 +00:00
|
|
|
</button>
|
|
|
|
</ak-forms-modal>
|
2021-02-19 17:43:57 +00:00
|
|
|
${super.renderToolbar()}
|
|
|
|
`;
|
|
|
|
}
|
2021-03-29 14:16:27 +00:00
|
|
|
|
2021-02-19 17:43:57 +00:00
|
|
|
}
|