import { AdminInterface } from "@goauthentik/admin/AdminInterface"; 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 { me } from "@goauthentik/app/common/users"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { MessageLevel } from "@goauthentik/common/messages"; import { DefaultUIConfig, uiConfig } from "@goauthentik/common/ui/config"; import { first } from "@goauthentik/common/utils"; import { rootInterface } from "@goauthentik/elements/Base"; 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, updateURLParams } 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 "@patternfly/elements/pf-tooltip/pf-tooltip.js"; import { msg, str } from "@lit/localize"; import { CSSResult, TemplateResult, html } from "lit"; import { customElement, property, state } from "lit/decorators.js"; 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, SessionUser, User, UserPath, } from "@goauthentik/api"; @customElement("ak-user-list") export class UserListPage extends TablePage { expandable = true; checkbox = true; searchEnabled(): boolean { return true; } pageTitle(): string { return msg("Users"); } pageDescription(): string { return ""; } pageIcon(): string { return "pf-icon pf-icon-user"; } @property() order = "last_login"; @property() activePath; @state() hideDeactivated = getURLParam("hideDeactivated", false); @state() userPaths?: UserPath; @state() me?: SessionUser; static get styles(): CSSResult[] { return super.styles.concat(PFDescriptionList, PFCard, PFAlert); } constructor() { super(); this.activePath = getURLParam("path", "/"); uiConfig().then((c) => { if (c.defaults.userPath !== new DefaultUIConfig().defaults.userPath) { this.activePath = c.defaults.userPath; } }); } async apiEndpoint(page: number): Promise> { const users = await new CoreApi(DEFAULT_CONFIG).coreUsersList({ ordering: this.order, page: page, pageSize: (await uiConfig()).pagination.perPage, search: this.search || "", pathStartswith: getURLParam("path", ""), isActive: this.hideDeactivated ? true : undefined, }); this.userPaths = await new CoreApi(DEFAULT_CONFIG).coreUsersPathsRetrieve({ search: this.search, }); this.me = await me(); return users; } columns(): TableColumn[] { return [ new TableColumn(msg("Name"), "username"), new TableColumn(msg("Active"), "is_active"), new TableColumn(msg("Last login"), "last_login"), new TableColumn(msg("Actions")), ]; } renderToolbarSelected(): TemplateResult { const disabled = this.selectedElements.length < 1; const currentUser = rootInterface()?.user; const shouldShowWarning = this.selectedElements.find((el) => { return el.pk === currentUser?.user.pk || el.pk == currentUser?.original?.pk; }); return html` { return [ { key: msg("Username"), value: item.username }, { key: msg("ID"), value: item.pk.toString() }, { key: msg("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, }); }} > ${shouldShowWarning ? html`

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

` : html``}
`; } renderToolbarAfter(): TemplateResult { return html` 
`; } row(item: User): TemplateResult[] { const canImpersonate = rootInterface()?.config?.capabilities.includes(CapabilitiesEnum.CanImpersonate) && item.pk !== this.me?.user.pk; return [ html`
${item.username}
${item.name}
`, html` ${item.isActive ? msg("Yes") : msg("No")} `, html`${first(item.lastLogin?.toLocaleString(), msg("-"))}`, html` ${msg("Update")} ${msg("Update User")} ${canImpersonate ? html` { return new CoreApi(DEFAULT_CONFIG) .coreUsersImpersonateCreate({ id: item.pk, }) .then(() => { window.location.href = "/"; }); }} > ${msg("Impersonate")} ` : html``}`, ]; } renderExpanded(item: User): TemplateResult { return html`
${msg("User status")}
${item.isActive ? msg("Active") : msg("Inactive")}
${item.isSuperuser ? msg("Superuser") : msg("Regular user")}
${msg("Change status")}
{ return new CoreApi( DEFAULT_CONFIG, ).coreUsersPartialUpdate({ id: item.pk, patchedUserRequest: { isActive: !item.isActive, }, }); }} >
${msg("Recovery")}
${msg("Update password")} ${msg("Update password")} ${rootInterface()?.tenant?.flowRecovery ? html` { return new CoreApi(DEFAULT_CONFIG) .coreUsersRecoveryRetrieve({ id: item.pk, }) .then((rec) => { showMessage({ level: MessageLevel.success, message: msg( "Successfully generated recovery link", ), description: rec.link, }); }) .catch((ex: ResponseError) => { ex.response.json().then(() => { showMessage({ level: MessageLevel.error, message: msg( "No recovery flow is configured.", ), }); }); }); }} > ${msg("Copy recovery link")} ${item.email ? html` ${msg("Send link")} ${msg("Send recovery link to user")} ` : html`${msg( "Recovery link cannot be emailed, user has no email address saved.", )}`} ` : html`

${msg( "To let a user directly reset a their password, configure a recovery flow on the currently active tenant.", )}

`}
`; } renderObjectCreate(): TemplateResult { return html` ${msg("Create")} ${msg("Create User")} ${msg("Create")} ${msg("Create Service account")} `; } renderSidebarBefore(): TemplateResult { return html`
${msg("User folders")}
`; } }