diff --git a/web/src/admin/users/UserViewPage.ts b/web/src/admin/users/UserViewPage.ts index f397be61ba..c10aef94b8 100644 --- a/web/src/admin/users/UserViewPage.ts +++ b/web/src/admin/users/UserViewPage.ts @@ -30,7 +30,11 @@ import "#elements/ak-mdx/ak-mdx"; import { DEFAULT_CONFIG } from "#common/api/config"; import { AKRefreshEvent } from "#common/events"; import { userTypeToLabel } from "#common/labels"; -import { formatDisambiguatedUserDisplayName, formatUserDisplayName } from "#common/users"; +import { + formatDisambiguatedUserDisplayName, + formatUserDisplayName, + startAccountLockdown, +} from "#common/users"; import { AKElement } from "#elements/Base"; import { listen } from "#elements/decorators/listen"; @@ -182,18 +186,7 @@ export class UserViewPage extends WithLicenseSummary( return; } - return this.#api - .coreUsersAccountLockdownCreate({ - userAccountLockdownRequest: { - user: this.user.pk, - }, - }) - .then((response) => { - if (response.to) { - window.location.assign(response.to); - } - }) - .catch(showAPIErrorMessage); + return startAccountLockdown(this.user.pk).catch(showAPIErrorMessage); }; protected renderActionButtons(user: User) { diff --git a/web/src/common/users.ts b/web/src/common/users.ts index 90214aef72..60bdfd1de2 100644 --- a/web/src/common/users.ts +++ b/web/src/common/users.ts @@ -157,6 +157,18 @@ export function redirectToAuthFlow(nextPathname = "/flows/-/default/authenticati window.location.assign(authFlowRedirectURL); } +/** + * Start account lockdown and follow the returned flow redirect. + */ +export async function startAccountLockdown(user?: number): Promise { + const response = await new CoreApi(DEFAULT_CONFIG).coreUsersAccountLockdownCreate({ + userAccountLockdownRequest: user !== undefined ? { user } : {}, + }); + if (response.to) { + window.location.assign(response.to); + } +} + /** * Retrieve the current user session. * diff --git a/web/src/user/user-settings/UserSettingsPage.ts b/web/src/user/user-settings/UserSettingsPage.ts index 42ab01517f..94967694f6 100644 --- a/web/src/user/user-settings/UserSettingsPage.ts +++ b/web/src/user/user-settings/UserSettingsPage.ts @@ -1,6 +1,4 @@ import "#elements/Tabs"; -import "#elements/forms/ModalForm"; -import "#elements/buttons/ActionButton/ak-action-button"; import "#elements/user/SessionList"; import "#elements/user/UserConsentList"; import "#elements/user/sources/SourceSettings"; @@ -11,6 +9,7 @@ import "#user/user-settings/tokens/UserTokenList"; import { DEFAULT_CONFIG } from "#common/api/config"; import { EVENT_REFRESH } from "#common/constants"; +import { startAccountLockdown } from "#common/users"; import { AKSkipToContent } from "#elements/a11y/ak-skip-to-content"; import { AKElement } from "#elements/Base"; @@ -22,7 +21,7 @@ import { ifPresent } from "#elements/utils/attributes"; import Styles from "#user/user-settings/styles.css"; -import { CoreApi, StagesApi, UserSetting } from "@goauthentik/api"; +import { StagesApi, UserSetting } from "@goauthentik/api"; import { msg } from "@lit/localize"; import { CSSResult, html, nothing } from "lit"; @@ -58,7 +57,6 @@ export class UserSettingsPage extends WithLicenseSummary(WithSession(AKElement)) Styles, ]; - protected coreAPI = new CoreApi(DEFAULT_CONFIG); protected stagesAPI = new StagesApi(DEFAULT_CONFIG); @state() @@ -83,16 +81,7 @@ export class UserSettingsPage extends WithLicenseSummary(WithSession(AKElement)) } protected lockAccount = () => { - return this.coreAPI - .coreUsersAccountLockdownCreate({ - userAccountLockdownRequest: {}, - }) - .then((response) => { - if (response.to) { - window.location.assign(response.to); - } - }) - .catch(showAPIErrorMessage); + return startAccountLockdown().catch(showAPIErrorMessage); }; protected renderSecuritySettings(): SlottedTemplateResult {