Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

GDGT-3403: Show the Authentication account tab as active (#84884)

Will Fry9e8175a34e74
diff --git a/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/AdminAuthCard/AdminAuthCard.tsx b/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/AdminAuthCard/AdminAuthCard.tsx
index 2ee5fcdb1af..cf5b141ba1b 100644
--- a/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/AdminAuthCard/AdminAuthCard.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/AdminAuthCard/AdminAuthCard.tsx
@@ -21,17 +21,14 @@ import {
Text,
Tooltip,
} from "metabase/ui";
+import * as Urls from "metabase/urls";
import {
useGetMfaAdminOverviewQuery,
useGetMfaStatusQuery,
} from "metabase-enterprise/api";
import type { MfaAdminOverview } from "metabase-types/api";
-import {
- ACCOUNT_AUTHENTICATION_PATH,
- ENROLLED_USERS_PATH,
- UNENROLLED_USERS_PATH,
-} from "../../constants";
+import { ENROLLED_USERS_PATH, UNENROLLED_USERS_PATH } from "../../constants";
const ENFORCEMENT_OPTIONS = ["optional", "required", "required-date"] as const;
type EnforcementOption = (typeof ENFORCEMENT_OPTIONS)[number];
@@ -213,7 +210,7 @@ export function AdminAuthCard() {
<Anchor
key="enroll"
component={Link}
- to={ACCOUNT_AUTHENTICATION_PATH}
+ to={Urls.accountAuthentication()}
>{t`Set up two-factor authentication`}</Anchor>
)} for your own account before requiring it, so you don't log yourself out.`}
</Text>
diff --git a/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/constants.ts b/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/constants.ts
index 572052f3e83..bfd5d6ee903 100644
--- a/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/constants.ts
+++ b/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/constants.ts
@@ -4,5 +4,3 @@ export const RECOVERY_CODE_LENGTH = 11;
export const AUTHENTICATION_PATH = "/admin/settings/authentication";
export const ENROLLED_USERS_PATH = `${AUTHENTICATION_PATH}/2fa/enrolled`;
export const UNENROLLED_USERS_PATH = `${AUTHENTICATION_PATH}/2fa/unenrolled`;
-
-export const ACCOUNT_AUTHENTICATION_PATH = "/account/authentication";
diff --git a/frontend/src/metabase/account/app/components/AccountHeader/AccountHeader.tsx b/frontend/src/metabase/account/app/components/AccountHeader/AccountHeader.tsx
index bd3ed7836be..0d548241b52 100644
--- a/frontend/src/metabase/account/app/components/AccountHeader/AccountHeader.tsx
+++ b/frontend/src/metabase/account/app/components/AccountHeader/AccountHeader.tsx
@@ -5,6 +5,7 @@ import { hasAuthenticationSettings } from "metabase/account/utils";
import { UserAvatar } from "metabase/common/components/UserAvatar";
import { useSetting } from "metabase/settings";
import { Box, Flex, Tabs, Title, rem } from "metabase/ui";
+import * as Urls from "metabase/urls";
import { getFullName } from "metabase/utils/user";
import type { User } from "metabase-types/api";
@@ -26,12 +27,12 @@ export const AccountHeader = ({
const tabs = useMemo(
() => [
- { name: t`Profile`, value: "/account/profile" },
+ { name: t`Profile`, value: Urls.accountSettings() },
...(hasAuthenticationTab
- ? [{ name: t`Authentication`, value: "/account/password" }]
+ ? [{ name: t`Authentication`, value: Urls.accountAuthentication() }]
: []),
- { name: t`Login History`, value: "/account/login-history" },
- { name: t`Notifications`, value: "/account/notifications" },
+ { name: t`Login History`, value: Urls.accountLoginHistory() },
+ { name: t`Notifications`, value: Urls.accountNotifications() },
],
[hasAuthenticationTab],
);
diff --git a/frontend/src/metabase/account/app/components/AccountHeader/AccountHeader.unit.spec.tsx b/frontend/src/metabase/account/app/components/AccountHeader/AccountHeader.unit.spec.tsx
index 452fbc75ea8..9494b6b3ac6 100644
--- a/frontend/src/metabase/account/app/components/AccountHeader/AccountHeader.unit.spec.tsx
+++ b/frontend/src/metabase/account/app/components/AccountHeader/AccountHeader.unit.spec.tsx
@@ -18,13 +18,22 @@ const getUser = (opts?: Partial<User>) =>
type SetupOpts = {
user?: User;
isMfaEnabled?: boolean;
+ path?: string;
};
-function setup({ user = getUser(), isMfaEnabled = false }: SetupOpts = {}) {
- const onChangeLocation = jest.fn();
+function setup({
+ user = getUser(),
+ isMfaEnabled = false,
+ path,
+}: SetupOpts = {}) {
+ const onChangeLocation = jest.fn<void, [string]>();
renderWithProviders(
- <AccountHeader user={user} onChangeLocation={onChangeLocation} />,
+ <AccountHeader
+ user={user}
+ path={path}
+ onChangeLocation={onChangeLocation}
+ />,
{
storeInitialState: createMockState({
settings: mockSettings({
@@ -61,6 +70,14 @@ describe("AccountHeader", () => {
});
describe("authentication tab", () => {
+ it("should be selected on the authentication page", () => {
+ setup({ path: "/account/authentication" });
+
+ expect(
+ screen.getByRole("tab", { name: "Authentication" }),
+ ).toHaveAttribute("aria-selected", "true");
+ });
+
it.each(["active", "inactive"] as const)(
"should show the tab for an SSO user with an %s Slack account",
(status) => {
diff --git a/frontend/src/metabase/account/routes.tsx b/frontend/src/metabase/account/routes.tsx
index 92e6c84d889..1a67ae4b7af 100644
--- a/frontend/src/metabase/account/routes.tsx
+++ b/frontend/src/metabase/account/routes.tsx
@@ -2,6 +2,7 @@ import type { Store } from "@reduxjs/toolkit";
import type { State } from "metabase/redux/store";
import { Route, type RouteComponent, redirect } from "metabase/router";
+import * as Urls from "metabase/urls";
import { getNotificationRoutes } from "./notifications/routes";
@@ -49,8 +50,14 @@ export const getAccountRoutes = (
<Route path="authentication" lazy={userPasswordApp} />
<Route path="login-history" lazy={loginHistoryApp} />
{/* Legacy path redirects */}
- <Route path="security" element={redirect("/account/authentication")} />
- <Route path="password" element={redirect("/account/authentication")} />
+ <Route
+ path="security"
+ element={redirect(Urls.accountAuthentication())}
+ />
+ <Route
+ path="password"
+ element={redirect(Urls.accountAuthentication())}
+ />
{getNotificationRoutes()}
</Route>
</Route>
diff --git a/frontend/src/metabase/urls/misc.ts b/frontend/src/metabase/urls/misc.ts
index 2f8f26c45eb..6c4443b91b8 100644
--- a/frontend/src/metabase/urls/misc.ts
+++ b/frontend/src/metabase/urls/misc.ts
@@ -2,6 +2,18 @@ export function accountSettings() {
return "/account/profile";
}
+export function accountAuthentication() {
+ return "/account/authentication";
+}
+
+export function accountLoginHistory() {
+ return "/account/login-history";
+}
+
+export function accountNotifications() {
+ return "/account/notifications";
+}
+
export function unauthorized() {
return "/unauthorized";
}