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 { 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("path", "/"); static get styles(): CSSResult[] { return super.styles.concat(PFDescriptionList, PFCard, PFAlert, AKGlobal); } async apiEndpoint(page: number): Promise> { 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` { 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`

${t`Warning: You're about to delete the user you're logged in as (${shouldShowWarning.username}). Proceed at your own risk.`}

`; } return html``; }), )}
`; } row(item: User): TemplateResult[] { return [ html`
${item.username}
${item.name}
`, html` ${item.isActive ? t`Yes` : t`No`} `, html`${first(item.lastLogin?.toLocaleString(), t`-`)}`, html` ${t`Update`} ${t`Update User`} ${until( config().then((config) => { if (config.capabilities.includes(CapabilitiesEnum.Impersonate)) { return html` ${t`Impersonate`} `; } return html``; }), )}`, ]; } renderExpanded(item: User): TemplateResult { return html`
${t`User status`}
${item.isActive ? t`Active` : t`Inactive`}
${item.isSuperuser ? t`Superuser` : t`Regular user`}
${t`Change status`}
{ return new CoreApi( DEFAULT_CONFIG, ).coreUsersPartialUpdate({ id: item.pk || 0, patchedUserRequest: { isActive: !item.isActive, }, }); }} >
${t`Recovery`}
${t`Update password`} ${t`Update password`} ${until( tenant().then((tenant) => { if (!tenant.flowRecovery) { return html`

${t`To let a user directly reset a their password, configure a recovery flow on the currently active tenant.`}

`; } return html` { 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`} ${item.email ? html` ${t`Send link`} ${t`Send recovery link to user`} ` : html`${t`Recovery link cannot be emailed, user has no email address saved.`}`} `; }), )}
`; } renderObjectCreate(): TemplateResult { return html` ${t`Create`} ${t`Create User`} ${t`Create`} ${t`Create Service account`} `; } renderSidebarBefore(): TemplateResult { return html`
${t`User folders`}
${until( new CoreApi(DEFAULT_CONFIG) .coreUsersPathsRetrieve({ search: this.search, }) .then((paths) => { return html``; }), )}
`; } }