import "@goauthentik/admin/groups/RelatedGroupList"; import "@goauthentik/admin/users/UserActiveForm"; import "@goauthentik/admin/users/UserChart"; import "@goauthentik/admin/users/UserForm"; import "@goauthentik/admin/users/UserPasswordForm"; import { me } from "@goauthentik/app/common/users"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { EVENT_REFRESH } from "@goauthentik/common/constants"; import { MessageLevel } from "@goauthentik/common/messages"; import "@goauthentik/components/events/ObjectChangelog"; import "@goauthentik/components/events/UserEvents"; import { AKElement, rootInterface } from "@goauthentik/elements/Base"; import "@goauthentik/elements/CodeMirror"; import { PFColor } from "@goauthentik/elements/Label"; import "@goauthentik/elements/PageHeader"; import { PFSize } from "@goauthentik/elements/Spinner"; import "@goauthentik/elements/Tabs"; import "@goauthentik/elements/buttons/ActionButton"; import "@goauthentik/elements/buttons/SpinnerButton"; import "@goauthentik/elements/forms/ModalForm"; import { showMessage } from "@goauthentik/elements/messages/MessageContainer"; import "@goauthentik/elements/oauth/UserRefreshList"; import "@goauthentik/elements/user/SessionList"; import "@goauthentik/elements/user/UserConsentList"; import { msg, str } from "@lit/localize"; import { CSSResult, TemplateResult, css, html } from "lit"; import { customElement, property, state } from "lit/decorators.js"; import PFButton from "@patternfly/patternfly/components/Button/button.css"; import PFCard from "@patternfly/patternfly/components/Card/card.css"; import PFContent from "@patternfly/patternfly/components/Content/content.css"; import PFDescriptionList from "@patternfly/patternfly/components/DescriptionList/description-list.css"; import PFPage from "@patternfly/patternfly/components/Page/page.css"; import PFGrid from "@patternfly/patternfly/layouts/Grid/grid.css"; import PFBase from "@patternfly/patternfly/patternfly-base.css"; import PFDisplay from "@patternfly/patternfly/utilities/Display/display.css"; import PFFlex from "@patternfly/patternfly/utilities/Flex/flex.css"; import PFSizing from "@patternfly/patternfly/utilities/Sizing/sizing.css"; import { CapabilitiesEnum, CoreApi, SessionUser, User } from "@goauthentik/api"; import "./UserDevicesList"; @customElement("ak-user-view") export class UserViewPage extends AKElement { @property({ type: Number }) set userId(id: number) { me().then((me) => { this.me = me; new CoreApi(DEFAULT_CONFIG) .coreUsersRetrieve({ id: id, }) .then((user) => { this.user = user; }); }); } @property({ attribute: false }) user?: User; @state() me?: SessionUser; static get styles(): CSSResult[] { return [ PFBase, PFPage, PFFlex, PFButton, PFDisplay, PFGrid, PFContent, PFCard, PFDescriptionList, PFSizing, css` .pf-c-description-list__description ak-action-button { margin-right: 6px; margin-bottom: 6px; } .ak-button-collection { max-width: 12em; } `, ]; } constructor() { super(); this.addEventListener(EVENT_REFRESH, () => { if (!this.user?.pk) return; this.userId = this.user?.pk; }); } render(): TemplateResult { return html` ${this.renderBody()}`; } renderUserCard(): TemplateResult { if (!this.user) { return html``; } const canImpersonate = rootInterface()?.config?.capabilities.includes(CapabilitiesEnum.CanImpersonate) && this.user.pk !== this.me?.user.pk; return html`
${msg("User Info")}
${msg("Username")}
${this.user.username}
${msg("Name")}
${this.user.name}
${msg("Email")}
${this.user.email || "-"}
${msg("Last login")}
${this.user.lastLogin?.toLocaleString()}
${msg("Active")}
${msg("Superuser")}
${msg("Actions")}
${msg("Update")} ${msg("Update User")} { return new CoreApi(DEFAULT_CONFIG).coreUsersPartialUpdate({ id: this.user?.pk || 0, patchedUserRequest: { isActive: !this.user?.isActive, }, }); }} > ${canImpersonate ? html` { return new CoreApi(DEFAULT_CONFIG) .coreUsersImpersonateCreate({ id: this.user?.pk || 0, }) .then(() => { window.location.href = "/"; }); }} > ${msg("Impersonate")} ` : html``}
${msg("Recovery")}
${msg("Update password")} ${msg("Update password")} { return new CoreApi(DEFAULT_CONFIG) .coreUsersRecoveryRetrieve({ id: this.user?.pk || 0, }) .then((rec) => { showMessage({ level: MessageLevel.success, message: msg( "Successfully generated recovery link", ), description: rec.link, }); }) .catch(() => { showMessage({ level: MessageLevel.error, message: msg( "To create a recovery link, the current tenant needs to have a recovery flow configured.", ), description: "", }); }); }} > ${msg("Reset Password")}
`; } renderBody(): TemplateResult { if (!this.user) { return html``; } return html`
${this.renderUserCard()}
${msg("Actions over the last week (per 8 hours)")}
${msg("Notes")}
${Object.hasOwn(this.user?.attributes || {}, "notes") ? html`${this.user.attributes?.notes}` : html`

${msg( "Edit the notes attribute of this user to add notes here.", )}

`}
${msg("Changelog")}
`; } }