import { t } from "@lingui/macro"; import { CSSResult, LitElement, TemplateResult, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { until } from "lit/directives/until.js"; import AKGlobal from "../../authentik.css"; 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, User } from "@goauthentik/api"; import { DEFAULT_CONFIG, config } from "../../api/Config"; import { EVENT_REFRESH } from "../../constants"; import "../../elements/CodeMirror"; import { PFColor } from "../../elements/Label"; import "../../elements/PageHeader"; import { PFSize } from "../../elements/Spinner"; import "../../elements/Tabs"; import "../../elements/buttons/ActionButton"; import "../../elements/buttons/SpinnerButton"; import "../../elements/charts/UserChart"; import "../../elements/events/ObjectChangelog"; import "../../elements/events/UserEvents"; import "../../elements/forms/ModalForm"; import { MessageLevel } from "../../elements/messages/Message"; import { showMessage } from "../../elements/messages/MessageContainer"; import "../../elements/oauth/UserRefreshList"; import "../../elements/user/SessionList"; import "../../elements/user/UserConsentList"; import "../groups/RelatedGroupList"; import "./UserActiveForm"; import "./UserForm"; import "./UserPasswordForm"; @customElement("ak-user-view") export class UserViewPage extends LitElement { @property({ type: Number }) set userId(id: number) { new CoreApi(DEFAULT_CONFIG) .coreUsersRetrieve({ id: id, }) .then((user) => { this.user = user; }); } @property({ attribute: false }) user?: User; static get styles(): CSSResult[] { return [ PFBase, PFPage, PFFlex, PFButton, PFDisplay, PFGrid, PFContent, PFCard, PFDescriptionList, PFSizing, AKGlobal, ]; } constructor() { super(); this.addEventListener(EVENT_REFRESH, () => { if (!this.user?.pk) return; this.userId = this.user?.pk; }); } render(): TemplateResult { return html` ${this.renderBody()}`; } renderBody(): TemplateResult { if (!this.user) { return html``; } return html`
${t`User Info`}
${t`Username`}
${this.user.username}
${t`Name`}
${this.user.name}
${t`Email`}
${this.user.email || "-"}
${t`Last login`}
${this.user.lastLogin?.toLocaleString()}
${t`Active`}
${t`Superuser`}
${until( config().then((config) => { if (config.capabilities.includes(CapabilitiesEnum.Impersonate)) { return html` `; } return html``; }), )}
${t`Actions over the last 24 hours`}
${t`Changelog`}
`; } }