4a91a7d2e2
* fix repo in api client Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * web: re-organise files to match their interface Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * core: include version in script tags Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * cleanup maybe broken Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * revert rename Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * web: get rid of Client.ts Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * move more to common Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * more moving Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * format Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * unfuck files that vscode fucked, thanks Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * move more Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * finish moving (maybe) Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * ok more moving Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * fix more stuff that vs code destroyed Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * get rid "web" prefix for virtual package Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * fix locales Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * use custom base element Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * fix css file Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * don't run autoDetectLanguage when importing locale Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * fix circular dependencies Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> * web: fix build Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
344 lines
17 KiB
TypeScript
344 lines
17 KiB
TypeScript
import "@goauthentik/admin/users/ServiceAccountForm";
|
|
import "@goauthentik/admin/users/UserActiveForm";
|
|
import "@goauthentik/admin/users/UserForm";
|
|
import "@goauthentik/admin/users/UserPasswordForm";
|
|
import "@goauthentik/admin/users/UserResetEmailForm";
|
|
import { DEFAULT_CONFIG, config, tenant } from "@goauthentik/common/api/config";
|
|
import { MessageLevel } from "@goauthentik/common/messages";
|
|
import { uiConfig } from "@goauthentik/common/ui/config";
|
|
import { me } from "@goauthentik/common/users";
|
|
import { first } from "@goauthentik/common/utils";
|
|
import { PFColor } from "@goauthentik/elements/Label";
|
|
import { PFSize } from "@goauthentik/elements/Spinner";
|
|
import "@goauthentik/elements/TreeView";
|
|
import "@goauthentik/elements/buttons/ActionButton";
|
|
import "@goauthentik/elements/forms/DeleteBulkForm";
|
|
import "@goauthentik/elements/forms/ModalForm";
|
|
import { showMessage } from "@goauthentik/elements/messages/MessageContainer";
|
|
import { getURLParam } from "@goauthentik/elements/router/RouteMatch";
|
|
import { PaginatedResponse } from "@goauthentik/elements/table/Table";
|
|
import { TableColumn } from "@goauthentik/elements/table/Table";
|
|
import { TablePage } from "@goauthentik/elements/table/TablePage";
|
|
|
|
import { t } from "@lingui/macro";
|
|
|
|
import { CSSResult, TemplateResult, html } from "lit";
|
|
import { customElement, property } from "lit/decorators.js";
|
|
import { until } from "lit/directives/until.js";
|
|
|
|
import AKGlobal from "@goauthentik/common/styles/authentik.css";
|
|
import PFAlert from "@patternfly/patternfly/components/Alert/alert.css";
|
|
import PFCard from "@patternfly/patternfly/components/Card/card.css";
|
|
import PFDescriptionList from "@patternfly/patternfly/components/DescriptionList/description-list.css";
|
|
|
|
import { CapabilitiesEnum, CoreApi, ResponseError, User } from "@goauthentik/api";
|
|
|
|
@customElement("ak-user-list")
|
|
export class UserListPage extends TablePage<User> {
|
|
expandable = true;
|
|
checkbox = true;
|
|
|
|
searchEnabled(): boolean {
|
|
return true;
|
|
}
|
|
pageTitle(): string {
|
|
return t`Users`;
|
|
}
|
|
pageDescription(): string {
|
|
return "";
|
|
}
|
|
pageIcon(): string {
|
|
return "pf-icon pf-icon-user";
|
|
}
|
|
|
|
@property()
|
|
order = "last_login";
|
|
|
|
@property()
|
|
activePath = getURLParam<string>("path", "/");
|
|
|
|
static get styles(): CSSResult[] {
|
|
return super.styles.concat(PFDescriptionList, PFCard, PFAlert, AKGlobal);
|
|
}
|
|
|
|
async apiEndpoint(page: number): Promise<PaginatedResponse<User>> {
|
|
return new CoreApi(DEFAULT_CONFIG).coreUsersList({
|
|
ordering: this.order,
|
|
page: page,
|
|
pageSize: (await uiConfig()).pagination.perPage,
|
|
search: this.search || "",
|
|
pathStartswith: getURLParam("path", ""),
|
|
});
|
|
}
|
|
|
|
columns(): TableColumn[] {
|
|
return [
|
|
new TableColumn(t`Name`, "username"),
|
|
new TableColumn(t`Active`, "active"),
|
|
new TableColumn(t`Last login`, "last_login"),
|
|
new TableColumn(t`Actions`),
|
|
];
|
|
}
|
|
|
|
renderToolbarSelected(): TemplateResult {
|
|
const disabled = this.selectedElements.length < 1;
|
|
return html`<ak-forms-delete-bulk
|
|
objectLabel=${t`User(s)`}
|
|
.objects=${this.selectedElements}
|
|
.metadata=${(item: User) => {
|
|
return [
|
|
{ key: t`Username`, value: item.username },
|
|
{ key: t`ID`, value: item.pk.toString() },
|
|
{ key: t`UID`, value: item.uid },
|
|
];
|
|
}}
|
|
.usedBy=${(item: User) => {
|
|
return new CoreApi(DEFAULT_CONFIG).coreUsersUsedByList({
|
|
id: item.pk,
|
|
});
|
|
}}
|
|
.delete=${(item: User) => {
|
|
return new CoreApi(DEFAULT_CONFIG).coreUsersDestroy({
|
|
id: item.pk,
|
|
});
|
|
}}
|
|
>
|
|
${until(
|
|
me().then((user) => {
|
|
const shouldShowWarning = this.selectedElements.find((el) => {
|
|
return el.pk === user.user.pk || el.pk == user.original?.pk;
|
|
});
|
|
if (shouldShowWarning) {
|
|
return html`
|
|
<div slot="notice" class="pf-c-form__alert">
|
|
<div class="pf-c-alert pf-m-inline pf-m-warning">
|
|
<div class="pf-c-alert__icon">
|
|
<i class="fas fa-exclamation-circle"></i>
|
|
</div>
|
|
<h4 class="pf-c-alert__title">
|
|
${t`Warning: You're about to delete the user you're logged in as (${shouldShowWarning.username}). Proceed at your own risk.`}
|
|
</h4>
|
|
</div>
|
|
</div>
|
|
`;
|
|
}
|
|
return html``;
|
|
}),
|
|
)}
|
|
<button ?disabled=${disabled} slot="trigger" class="pf-c-button pf-m-danger">
|
|
${t`Delete`}
|
|
</button>
|
|
</ak-forms-delete-bulk>`;
|
|
}
|
|
|
|
row(item: User): TemplateResult[] {
|
|
return [
|
|
html`<a href="#/identity/users/${item.pk}">
|
|
<div>${item.username}</div>
|
|
<small>${item.name}</small>
|
|
</a>`,
|
|
html`<ak-label color=${item.isActive ? PFColor.Green : PFColor.Red}>
|
|
${item.isActive ? t`Yes` : t`No`}
|
|
</ak-label>`,
|
|
html`${first(item.lastLogin?.toLocaleString(), t`-`)}`,
|
|
html`<ak-forms-modal>
|
|
<span slot="submit"> ${t`Update`} </span>
|
|
<span slot="header"> ${t`Update User`} </span>
|
|
<ak-user-form slot="form" .instancePk=${item.pk}> </ak-user-form>
|
|
<button slot="trigger" class="pf-c-button pf-m-plain">
|
|
<i class="fas fa-edit"></i>
|
|
</button>
|
|
</ak-forms-modal>
|
|
${until(
|
|
config().then((config) => {
|
|
if (config.capabilities.includes(CapabilitiesEnum.Impersonate)) {
|
|
return html`<a
|
|
class="pf-c-button pf-m-tertiary"
|
|
href="${`/-/impersonation/${item.pk}/`}"
|
|
>
|
|
${t`Impersonate`}
|
|
</a>`;
|
|
}
|
|
return html``;
|
|
}),
|
|
)}`,
|
|
];
|
|
}
|
|
|
|
renderExpanded(item: User): TemplateResult {
|
|
return html`<td role="cell" colspan="3">
|
|
<div class="pf-c-table__expandable-row-content">
|
|
<dl class="pf-c-description-list pf-m-horizontal">
|
|
<div class="pf-c-description-list__group">
|
|
<dt class="pf-c-description-list__term">
|
|
<span class="pf-c-description-list__text">${t`User status`}</span>
|
|
</dt>
|
|
<dd class="pf-c-description-list__description">
|
|
<div class="pf-c-description-list__text">
|
|
${item.isActive ? t`Active` : t`Inactive`}
|
|
</div>
|
|
<div class="pf-c-description-list__text">
|
|
${item.isSuperuser ? t`Superuser` : t`Regular user`}
|
|
</div>
|
|
</dd>
|
|
</div>
|
|
<div class="pf-c-description-list__group">
|
|
<dt class="pf-c-description-list__term">
|
|
<span class="pf-c-description-list__text">${t`Change status`}</span>
|
|
</dt>
|
|
<dd class="pf-c-description-list__description">
|
|
<div class="pf-c-description-list__text">
|
|
<ak-user-active-form
|
|
.obj=${item}
|
|
objectLabel=${t`User`}
|
|
.delete=${() => {
|
|
return new CoreApi(
|
|
DEFAULT_CONFIG,
|
|
).coreUsersPartialUpdate({
|
|
id: item.pk || 0,
|
|
patchedUserRequest: {
|
|
isActive: !item.isActive,
|
|
},
|
|
});
|
|
}}
|
|
>
|
|
<button slot="trigger" class="pf-c-button pf-m-warning">
|
|
${item.isActive ? t`Deactivate` : t`Activate`}
|
|
</button>
|
|
</ak-user-active-form>
|
|
</div>
|
|
</dd>
|
|
</div>
|
|
<div class="pf-c-description-list__group">
|
|
<dt class="pf-c-description-list__term">
|
|
<span class="pf-c-description-list__text">${t`Recovery`}</span>
|
|
</dt>
|
|
<dd class="pf-c-description-list__description">
|
|
<div class="pf-c-description-list__text">
|
|
<ak-forms-modal size=${PFSize.Medium}>
|
|
<span slot="submit">${t`Update password`}</span>
|
|
<span slot="header">${t`Update password`}</span>
|
|
<ak-user-password-form
|
|
slot="form"
|
|
.instancePk=${item.pk}
|
|
></ak-user-password-form>
|
|
<button slot="trigger" class="pf-c-button pf-m-secondary">
|
|
${t`Set password`}
|
|
</button>
|
|
</ak-forms-modal>
|
|
${until(
|
|
tenant().then((tenant) => {
|
|
if (!tenant.flowRecovery) {
|
|
return html`
|
|
<p>
|
|
${t`To let a user directly reset a their password, configure a recovery flow on the currently active tenant.`}
|
|
</p>
|
|
`;
|
|
}
|
|
return html`
|
|
<ak-action-button
|
|
class="pf-m-secondary"
|
|
.apiRequest=${() => {
|
|
return new CoreApi(DEFAULT_CONFIG)
|
|
.coreUsersRecoveryRetrieve({
|
|
id: item.pk || 0,
|
|
})
|
|
.then((rec) => {
|
|
showMessage({
|
|
level: MessageLevel.success,
|
|
message: t`Successfully generated recovery link`,
|
|
description: rec.link,
|
|
});
|
|
})
|
|
.catch((ex: ResponseError) => {
|
|
ex.response.json().then(() => {
|
|
showMessage({
|
|
level: MessageLevel.error,
|
|
message: t`No recovery flow is configured.`,
|
|
});
|
|
});
|
|
});
|
|
}}
|
|
>
|
|
${t`Copy recovery link`}
|
|
</ak-action-button>
|
|
${item.email
|
|
? html`<ak-forms-modal
|
|
.closeAfterSuccessfulSubmit=${false}
|
|
>
|
|
<span slot="submit">
|
|
${t`Send link`}
|
|
</span>
|
|
<span slot="header">
|
|
${t`Send recovery link to user`}
|
|
</span>
|
|
<ak-user-reset-email-form
|
|
slot="form"
|
|
.user=${item}
|
|
>
|
|
</ak-user-reset-email-form>
|
|
<button
|
|
slot="trigger"
|
|
class="pf-c-button pf-m-secondary"
|
|
>
|
|
${t`Email recovery link`}
|
|
</button>
|
|
</ak-forms-modal>`
|
|
: html`<span
|
|
>${t`Recovery link cannot be emailed, user has no email address saved.`}</span
|
|
>`}
|
|
`;
|
|
}),
|
|
)}
|
|
</div>
|
|
</dd>
|
|
</div>
|
|
</dl>
|
|
</div>
|
|
</td>
|
|
<td></td>
|
|
<td></td>`;
|
|
}
|
|
|
|
renderObjectCreate(): TemplateResult {
|
|
return html`
|
|
<ak-forms-modal>
|
|
<span slot="submit"> ${t`Create`} </span>
|
|
<span slot="header"> ${t`Create User`} </span>
|
|
<ak-user-form slot="form"> </ak-user-form>
|
|
<button slot="trigger" class="pf-c-button pf-m-primary">${t`Create`}</button>
|
|
</ak-forms-modal>
|
|
<ak-forms-modal .closeAfterSuccessfulSubmit=${false} .cancelText=${t`Close`}>
|
|
<span slot="submit"> ${t`Create`} </span>
|
|
<span slot="header"> ${t`Create Service account`} </span>
|
|
<ak-user-service-account slot="form"> </ak-user-service-account>
|
|
<button slot="trigger" class="pf-c-button pf-m-secondary">
|
|
${t`Create Service account`}
|
|
</button>
|
|
</ak-forms-modal>
|
|
`;
|
|
}
|
|
|
|
renderSidebarBefore(): TemplateResult {
|
|
return html`<div class="pf-c-sidebar__panel pf-m-width-25">
|
|
<div class="pf-c-card">
|
|
<div class="pf-c-card__title">${t`User folders`}</div>
|
|
<div class="pf-c-card__body">
|
|
${until(
|
|
new CoreApi(DEFAULT_CONFIG)
|
|
.coreUsersPathsRetrieve({
|
|
search: this.search,
|
|
})
|
|
.then((paths) => {
|
|
return html`<ak-treeview
|
|
.items=${paths.paths}
|
|
activePath=${this.activePath}
|
|
></ak-treeview>`;
|
|
}),
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>`;
|
|
}
|
|
}
|