Skip to content

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

Whitelist allowed settings pages for Settings Managers (#83775)

Kevin Kelleherf318e39d8c97
diff --git a/docs/permissions/application.md b/docs/permissions/application.md
index 7c23cc897dd..2f2ec7dcb68 100644
--- a/docs/permissions/application.md
+++ b/docs/permissions/application.md
@@ -26,8 +26,6 @@ Settings access defines which groups can view and edit the settings under the Ad
- [Localization](../configuring-metabase/localization.md)
- [Appearance](../configuring-metabase/appearance.md)
- [Public sharing](../embedding/public-links.md)
-- [Embedding in other applications](../embedding/start.md)
-- [Caching](../configuring-metabase/caching.md)
## Monitoring access
diff --git a/frontend/src/metabase/admin/routes.tsx b/frontend/src/metabase/admin/routes.tsx
index d7288929bdd..336b26db02b 100644
--- a/frontend/src/metabase/admin/routes.tsx
+++ b/frontend/src/metabase/admin/routes.tsx
@@ -344,7 +344,7 @@ export const getRoutes = (
path="settings"
element={createElement(createAdminRouteGuard("settings"))}
>
- {getSettingsRoutes(store, IsAdmin)}
+ {getSettingsRoutes(store)}
</Route>
{/* PERMISSIONS */}
<Route path="permissions" element={<IsAdmin />}>
@@ -411,10 +411,12 @@ export const getRoutes = (
</Route>
{PLUGIN_SECURITY_CENTER.isEnabled && (
- <Route
- path="security-center"
- lazy={PLUGIN_SECURITY_CENTER.securityCenterPage}
- />
+ <Route element={<IsAdmin />}>
+ <Route
+ path="security-center"
+ lazy={PLUGIN_SECURITY_CENTER.securityCenterPage}
+ />
+ </Route>
)}
<Route element={createElement(createAdminRouteGuard("help"))}>
diff --git a/frontend/src/metabase/admin/routes.unit.spec.tsx b/frontend/src/metabase/admin/routes.unit.spec.tsx
index 0611884863f..9ea0018cd98 100644
--- a/frontend/src/metabase/admin/routes.unit.spec.tsx
+++ b/frontend/src/metabase/admin/routes.unit.spec.tsx
@@ -125,7 +125,7 @@ describe("admin routes", () => {
});
it("resolves every page in the settings tree", async () => {
- const loaders = lazyLoaders(getSettingsRoutes(createStore(), Guard));
+ const loaders = lazyLoaders(getSettingsRoutes(createStore()));
expect(loaders.length).toBeGreaterThan(20);
diff --git a/frontend/src/metabase/admin/settings/SettingsPageGuard.tsx b/frontend/src/metabase/admin/settings/SettingsPageGuard.tsx
new file mode 100644
index 00000000000..289f8217a01
--- /dev/null
+++ b/frontend/src/metabase/admin/settings/SettingsPageGuard.tsx
@@ -0,0 +1,17 @@
+import {
+ getSettingsSlug,
+ getUserIsAdmin,
+ isSettingsManagerPath,
+} from "metabase/current-user";
+import { useSelector } from "metabase/redux";
+import { Navigate, Outlet, useLocation } from "metabase/router";
+
+export function SettingsPageGuard() {
+ const isAdmin = useSelector(getUserIsAdmin);
+ const { pathname } = useLocation();
+ return isAdmin || isSettingsManagerPath(getSettingsSlug(pathname)) ? (
+ <Outlet />
+ ) : (
+ <Navigate to="/unauthorized" replace />
+ );
+}
diff --git a/frontend/src/metabase/admin/settings/components/SettingsNav/SettingsNav.tsx b/frontend/src/metabase/admin/settings/components/SettingsNav/SettingsNav.tsx
index 3578fb2a2bb..e79e4a42059 100644
--- a/frontend/src/metabase/admin/settings/components/SettingsNav/SettingsNav.tsx
+++ b/frontend/src/metabase/admin/settings/components/SettingsNav/SettingsNav.tsx
@@ -3,9 +3,7 @@ import { t } from "ttag";
import { AdminNavWrapper } from "metabase/admin/components/AdminNav";
import { UpsellGem } from "metabase/common/components/upsells/components/UpsellGem";
import { useHasTokenFeature } from "metabase/common/hooks";
-import { getUserIsAdmin } from "metabase/current-user";
import { PLUGIN_REMOTE_SYNC, PLUGIN_SECURITY_CENTER } from "metabase/plugins";
-import { useSelector } from "metabase/redux";
import { getPlan, isProPlan, useSetting } from "metabase/settings";
import { Box, Divider, Flex } from "metabase/ui";
@@ -26,7 +24,6 @@ export function SettingsNav() {
const hasPythonTransforms = useHasTokenFeature("transforms-python");
const isHosted = useSetting("is-hosted?");
const tokenFeatures = useSetting("token-features");
- const isAdmin = useSelector(getUserIsAdmin);
const isPro = isProPlan(getPlan(tokenFeatures));
const { isEnabled: isSecurityCenterEnabled, SecurityCenterPromoCard } =
PLUGIN_SECURITY_CENTER;
@@ -79,10 +76,8 @@ export function SettingsNav() {
label={t`Localization`}
icon="pinmap"
/>
- {/* do not allow users with "Settings access" permissions to access custom viz pages */}
- {isAdmin && <CustomVisualizationsNav />}
- {/* do not allow users with "Settings access" permissions to access data apps pages */}
- {isAdmin && <DataAppsNav />}
+ <CustomVisualizationsNav />
+ <DataAppsNav />
<SettingsNavItem path="maps" label={t`Maps`} icon="map" />
<SettingsNavItem
path={!hasWhitelabel ? "whitelabel" : undefined}
diff --git a/frontend/src/metabase/admin/settings/components/SettingsNav/SettingsNav.unit.spec.tsx b/frontend/src/metabase/admin/settings/components/SettingsNav/SettingsNav.unit.spec.tsx
index e3c22819468..d4223bd1beb 100644
--- a/frontend/src/metabase/admin/settings/components/SettingsNav/SettingsNav.unit.spec.tsx
+++ b/frontend/src/metabase/admin/settings/components/SettingsNav/SettingsNav.unit.spec.tsx
@@ -1,4 +1,5 @@
import userEvent from "@testing-library/user-event";
+import fetchMock from "fetch-mock";
import { setupSettingEndpoint } from "__support__/server-mocks";
import { createMockSettingsState } from "__support__/state";
@@ -16,11 +17,13 @@ import { SettingsNav } from "./SettingsNav";
const setup = async ({
initialRoute,
+ isAdmin = true,
isHosted,
customVizDevModeEnabled,
tokenFeatures,
}: {
initialRoute: string;
+ isAdmin?: boolean;
isHosted?: boolean;
customVizDevModeEnabled?: boolean;
tokenFeatures?: Partial<TokenFeatures>;
@@ -46,7 +49,7 @@ const setup = async ({
withRouter: true,
initialRoute,
storeInitialState: {
- currentUser: createMockUser({ is_superuser: true }),
+ currentUser: createMockUser({ is_superuser: isAdmin }),
settings: createMockSettingsState(settings),
},
});
@@ -144,6 +147,82 @@ describe("SettingsNav", () => {
expect(screen.queryByText("Updates")).not.toBeInTheDocument();
});
+ it("should show only allowlisted pages to settings managers", async () => {
+ await setup({
+ initialRoute: "/admin/settings/general",
+ isAdmin: false,
+ tokenFeatures: {
+ "custom-viz": false,
+ "custom-viz-available": false,
+ },
+ });
+
+ expect(await screen.findByText("General")).toBeInTheDocument();
+ expect(screen.getByText("Domains")).toBeInTheDocument();
+ expect(screen.getByText("Email")).toBeInTheDocument();
+ expect(screen.getByText("Slack")).toBeInTheDocument();
+ expect(screen.getByText("Webhooks")).toBeInTheDocument();
+ expect(screen.getByText("Localization")).toBeInTheDocument();
+ expect(screen.getByText("Maps")).toBeInTheDocument();
+ expect(screen.getByText("Appearance")).toBeInTheDocument();
+ expect(screen.getByText("Uploads")).toBeInTheDocument();
+ expect(screen.getByText("Public sharing")).toBeInTheDocument();
+
+ expect(screen.queryByText("Authentication")).not.toBeInTheDocument();
+ expect(screen.queryByText("License")).not.toBeInTheDocument();
+ expect(screen.queryByText("Updates")).not.toBeInTheDocument();
+ expect(screen.queryByText("Cloud")).not.toBeInTheDocument();
+ expect(screen.queryByText("Remote sync")).not.toBeInTheDocument();
+ expect(screen.queryByText("Custom visualizations")).not.toBeInTheDocument();
+ expect(screen.queryByText("Data apps")).not.toBeInTheDocument();
+ expect(screen.queryByText("Python Runner")).not.toBeInTheDocument();
+ expect(screen.queryByText("Branding")).not.toBeInTheDocument();
+ });
+
+ it("should show the Appearance folder to settings managers when whitelabel is enabled", async () => {
+ await setup({
+ initialRoute: "/admin/settings/whitelabel/branding",
+ isAdmin: false,
+ tokenFeatures: { whitelabel: true },
+ });
+
+ expect(await screen.findByText("Appearance")).toBeInTheDocument();
+ expect(screen.getByText("Branding")).toBeInTheDocument();
+ expect(screen.getByText("Conceal Metabase")).toBeInTheDocument();
+ });
+
+ it("should hide Authentication and Python Runner from settings managers even with related tokens", async () => {
+ await setup({
+ initialRoute: "/admin/settings/general",
+ isAdmin: false,
+ tokenFeatures: {
+ scim: true,
+ sso_saml: true,
+ "transforms-python": true,
+ },
+ });
+
+ expect(await screen.findByText("General")).toBeInTheDocument();
+ expect(screen.queryByText("Authentication")).not.toBeInTheDocument();
+ expect(screen.queryByText("Python Runner")).not.toBeInTheDocument();
+ });
+
+ it("should not request version-info for settings managers", async () => {
+ await setup({ initialRoute: "/admin/settings/general", isAdmin: false });
+
+ expect(await screen.findByText("General")).toBeInTheDocument();
+ expect(fetchMock.callHistory.called("path:/api/setting/version-info")).toBe(
+ false,
+ );
+ });
+
+ it("should show License and Updates to admins", async () => {
+ await setup({ initialRoute: "/admin/settings/general" });
+
+ expect(await screen.findByText("License")).toBeInTheDocument();
+ expect(screen.getByText("Updates")).toBeInTheDocument();
+ });
+
it("should show Development nav item when custom viz dev mode is enabled", async () => {
await setup({
initialRoute: "/admin/settings/custom-visualizations",
diff --git a/frontend/src/metabase/admin/settings/components/SettingsNav/SettingsNavItem.tsx b/frontend/src/metabase/admin/settings/components/SettingsNav/SettingsNavItem.tsx
index 057ebb4071f..67e215d8241 100644
--- a/frontend/src/metabase/admin/settings/components/SettingsNav/SettingsNavItem.tsx
+++ b/frontend/src/metabase/admin/settings/components/SettingsNav/SettingsNavItem.tsx
@@ -5,6 +5,8 @@ import {
AdminNavItem,
type AdminNavItemProps,
} from "metabase/admin/components/AdminNav";
+import { getUserIsAdmin, isSettingsManagerPath } from "metabase/current-user";
+import { useSelector } from "metabase/redux";
import { useLocation } from "metabase/router";
/**
@@ -36,6 +38,14 @@ const findBestMatchingChild = (
return best;
};
+function getNavChildPath(child: ReactElement): string | undefined {
+ const props = child.props;
+ if (typeof props !== "object" || props === null || !("path" in props)) {
+ return undefined;
+ }
+ return typeof props.path === "string" ? props.path : undefined;
+}
+
export function SettingsNavItem({
path,
folderPattern,
@@ -43,13 +53,25 @@ export function SettingsNavItem({
children: childrenProp,
...navItemProps
}: AdminNavItemProps & { active?: boolean }) {
+ const isAdmin = useSelector(getUserIsAdmin);
// Unjustified type cast. FIXME
- const children = React.Children.toArray(childrenProp) as ReactElement[];
+ const allChildren = React.Children.toArray(childrenProp) as ReactElement[];
+ const children = isAdmin
+ ? allChildren
+ : allChildren.filter((child) =>
+ isSettingsManagerPath(getNavChildPath(child)),
+ );
const currentPath = useLocation().pathname;
const [isOpen, { toggle: toggleOpen }] = useDisclosure(
folderPattern ? currentPath.includes(folderPattern) : false,
);
+ const isVisible =
+ isAdmin || isSettingsManagerPath(path) || children.length > 0;
+ if (!isVisible) {
+ return null;
+ }
+
const bestChild = findBestMatchingChild(children, currentPath);
const hasActiveDescendant = bestChild != null;
@@ -77,7 +99,7 @@ export function SettingsNavItem({
} as any)
: child,
)
- : childrenProp}
+ : null}
</AdminNavItem>
);
}
diff --git a/frontend/src/metabase/admin/settings/components/SettingsNav/UpdatesNavItem.tsx b/frontend/src/metabase/admin/settings/components/SettingsNav/UpdatesNavItem.tsx
index 07ddcf53333..7e834a4274f 100644
--- a/frontend/src/metabase/admin/settings/components/SettingsNav/UpdatesNavItem.tsx
+++ b/frontend/src/metabase/admin/settings/components/SettingsNav/UpdatesNavItem.tsx
@@ -1,6 +1,7 @@
import { t } from "ttag";
import { getCurrentVersion } from "metabase/admin/app/selectors";
+import { getUserIsAdmin } from "metabase/current-user";
import { useSelector } from "metabase/redux";
import { useGetVersionInfoQuery } from "metabase/settings";
import { Indicator } from "metabase/ui";
@@ -9,7 +10,10 @@ import { newVersionAvailable } from "metabase/utils/version";
import { SettingsNavItem } from "./SettingsNavItem";
export function UpdatesNavItem() {
- const { data: versionInfo } = useGetVersionInfoQuery();
+ const isAdmin = useSelector(getUserIsAdmin);
+ const { data: versionInfo } = useGetVersionInfoQuery(undefined, {
+ skip: !isAdmin,
+ });
const currentVersion = useSelector(getCurrentVersion);
const latestVersion = versionInfo?.latest?.version;
diff --git a/frontend/src/metabase/admin/settings/components/SettingsNav/UpdatesNavItem.unit.spec.tsx b/frontend/src/metabase/admin/settings/components/SettingsNav/UpdatesNavItem.unit.spec.tsx
index 3e804772de8..080d9c4eac3 100644
--- a/frontend/src/metabase/admin/settings/components/SettingsNav/UpdatesNavItem.unit.spec.tsx
+++ b/frontend/src/metabase/admin/settings/components/SettingsNav/UpdatesNavItem.unit.spec.tsx
@@ -10,6 +10,7 @@ import type { SettingKey } from "metabase-types/api";
import {
createMockSettingDefinition,
createMockSettings,
+ createMockUser,
} from "metabase-types/api/mocks";
import { UpdatesNavItem } from "./UpdatesNavItem";
@@ -48,6 +49,7 @@ const setup = async (props: { versionTag: string }) => {
renderWithProviders(<Route path="*" element={<UpdatesNavItem />} />, {
withRouter: true,
storeInitialState: {
+ currentUser: createMockUser({ is_superuser: true }),
settings: createMockSettingsState(settings),
},
});
diff --git a/frontend/src/metabase/admin/settings/components/SettingsPages/UploadSettingsPage.tsx b/frontend/src/metabase/admin/settings/components/SettingsPages/UploadSettingsPage.tsx
index bd902406bc2..deb86812e30 100644
--- a/frontend/src/metabase/admin/settings/components/SettingsPages/UploadSettingsPage.tsx
+++ b/frontend/src/metabase/admin/settings/components/SettingsPages/UploadSettingsPage.tsx
@@ -1,7 +1,9 @@
import { t } from "ttag";
import { UpsellUploads } from "metabase/admin/upsells";
+import { getUserIsAdmin } from "metabase/current-user";
import { PLUGIN_UPLOAD_MANAGEMENT } from "metabase/plugins";
+import { useSelector } from "metabase/redux";
import {
SettingsPageWrapper,
SettingsSection,
@@ -11,6 +13,7 @@ import { Box, Flex } from "metabase/ui";
import { UploadSettingsForm } from "../UploadSettings/UploadSettingsForm";
export function UploadSettingsPage() {
+ const isAdmin = useSelector(getUserIsAdmin);
return (
<SettingsPageWrapper title={t`Uploads`}>
<Flex justify="space-between" gap="xl">
@@ -18,9 +21,11 @@ export function UploadSettingsPage() {
<UploadSettingsForm />
<PLUGIN_UPLOAD_MANAGEMENT.UploadManagementTable />
</SettingsSection>
- <Box>
- <UpsellUploads location="settings-uploads" />
- </Box>
+ {isAdmin && (
+ <Box>
+ <UpsellUploads location="settings-uploads" />
+ </Box>
+ )}
</Flex>
</SettingsPageWrapper>
);
diff --git a/frontend/src/metabase/admin/settings/tests/settings-manager.unit.spec.tsx b/frontend/src/metabase/admin/settings/tests/settings-manager.unit.spec.tsx
new file mode 100644
index 00000000000..5f64acf0d8b
--- /dev/null
+++ b/frontend/src/metabase/admin/settings/tests/settings-manager.unit.spec.tsx
@@ -0,0 +1,55 @@
+import { screen } from "__support__/ui";
+
+import { setup } from "./setup";
+
+describe("Admin Settings Routing - settings managers", () => {
+ it.each([
+ "/license",
+ "/updates",
+ "/authentication",
+ "/authentication/2fa/enrolled",
+ "/custom-visualizations",
+ ])("redirects settings managers from %s to /unauthorized", async (path) => {
+ await setup({
+ isAdmin: false,
+ initialRoute: path,
+ waitForLayout: false,
+ });
+
+ expect(await screen.findByTestId("unauthorized-page")).toBeInTheDocument();
+ });
+
+ it("shows not found to settings managers for unknown settings pages", async () => {
+ await setup({ isAdmin: false, initialRoute: "/not-a-real-page" });
+
+ expect(
+ await screen.findByText(/the page you asked for couldn't be found/i),
+ ).toBeInTheDocument();
+ expect(screen.queryByTestId("unauthorized-page")).not.toBeInTheDocument();
+ });
+
+ it("redirects the settings index to General for settings managers", async () => {
+ await setup({ isAdmin: false, initialRoute: "" });
+
+ expect(await screen.findByText(/site name/i)).toBeInTheDocument();
+ });
+
+ it("renders General for settings managers", async () => {
+ await setup({ isAdmin: false, initialRoute: "/general" });
+
+ expect(await screen.findByText(/site name/i)).toBeInTheDocument();
+ });
+
+ it("renders whitelabel branding for settings managers", async () => {
+ await setup({ isAdmin: false, initialRoute: "/whitelabel/branding" });
+
+ expect(screen.getByTestId("admin-layout-content")).toBeInTheDocument();
+ expect(screen.queryByTestId("unauthorized-page")).not.toBeInTheDocument();
+ });
+
+ it("renders License for admins", async () => {
+ await setup({ isAdmin: true, initialRoute: "/license" });
+
+ expect(await screen.findByText(/Looking for more/i)).toBeInTheDocument();
+ });
+});
diff --git a/frontend/src/metabase/admin/settings/tests/setup.tsx b/frontend/src/metabase/admin/settings/tests/setup.tsx
index 8745b4bcf59..d1c7e0154fe 100644
--- a/frontend/src/metabase/admin/settings/tests/setup.tsx
+++ b/frontend/src/metabase/admin/settings/tests/setup.tsx
@@ -26,7 +26,7 @@ import { mockSettings } from "__support__/settings";
import { createMockState } from "__support__/state";
import { getTestStoreAndWrapper, screen } from "__support__/ui";
import { getSettingsRoutes } from "metabase/admin/settingsRoutes";
-import { Outlet, Route } from "metabase/router";
+import { Route } from "metabase/router";
import type { TokenFeature, TokenFeatures } from "metabase-types/api";
import {
createMockSettings,
@@ -119,12 +119,14 @@ export const setup = async ({
isAdmin = true,
features = {},
initialRoute = "",
+ waitForLayout = true,
}: {
enterprisePlugins?: Parameters<typeof setupEnterpriseOnlyPlugin>[0][] | "*";
hasTokenFeatures?: boolean;
isAdmin?: boolean;
features?: Partial<TokenFeatures>;
initialRoute?: string;
+ waitForLayout?: boolean;
}) => {
const tokenFeatures = createMockTokenFeatures({});
if (hasTokenFeatures) {
@@ -210,14 +212,18 @@ export const setup = async ({
initialRoute: `/admin/settings${initialRoute}`,
});
- const PassThroughGuard = () => <Outlet />;
-
testingLibraryRender(
- <Route path="admin/settings">
- {getSettingsRoutes(store, PassThroughGuard)}
- </Route>,
+ <>
+ <Route path="admin/settings">{getSettingsRoutes(store)}</Route>
+ <Route
+ path="unauthorized"
+ element={<div data-testid="unauthorized-page">Unauthorized</div>}
+ />
+ </>,
{ wrapper },
);
- await screen.findByTestId("admin-layout-content");
+ if (waitForLayout) {
+ await screen.findByTestId("admin-layout-content");
+ }
};
diff --git a/frontend/src/metabase/admin/settingsRoutes.tsx b/frontend/src/metabase/admin/settingsRoutes.tsx
index 8eb2eae1c3a..587ff66b85c 100644
--- a/frontend/src/metabase/admin/settingsRoutes.tsx
+++ b/frontend/src/metabase/admin/settingsRoutes.tsx
@@ -7,10 +7,12 @@ import {
PLUGIN_TRANSFORMS_PYTHON,
} from "metabase/plugins";
import type { State } from "metabase/redux/store";
-import { Outlet, Route, type RouteComponent, redirect } from "metabase/router";
+import { Outlet, Route, redirect } from "metabase/router";
import { getSetting } from "metabase/settings";
import * as Urls from "metabase/urls";
+import { SettingsPageGuard } from "./settings/SettingsPageGuard";
+
/**
* The admin settings pages, in one chunk. Every loader names it, so the section
* arrives in a single request rather than one per page.
@@ -177,10 +179,7 @@ const cloudSettings = () =>
/* webpackChunkName: "admin-settings" */ "./settings/components/SettingsPages/CloudSettingsPage"
).then(({ CloudSettingsPage }) => ({ Component: CloudSettingsPage }));
-export const getSettingsRoutes = (
- store: Store<State>,
- IsAdmin: RouteComponent,
-) => {
+export const getSettingsRoutes = (store: Store<State>) => {
const devModeEnabled = getSetting(
store.getState(),
"custom-viz-plugin-dev-mode-enabled",
@@ -188,88 +187,84 @@ export const getSettingsRoutes = (
return (
<Route lazy={settingsLayout}>
- <Route index element={redirect("general")} />
- <Route path="general" lazy={generalSettings} />
- <Route path="updates" lazy={updatesSettings} />
- <Route path="email" lazy={emailSettings} />
- <Route path="slack" lazy={slackSettings} />
- <Route path="webhooks" lazy={webhooksSettings} />
- <Route
- path="authentication"
- lazy={authenticationSettings("authentication")}
- />
- <Route
- path="authentication/user-provisioning"
- lazy={authenticationSettings("user-provisioning")}
- />
- <Route
- path="authentication/api-keys"
- lazy={authenticationSettings("api-keys")}
- />
- <Route path="authentication/2fa" element={<IsAdmin />}>
+ <Route element={<SettingsPageGuard />}>
+ <Route index element={redirect(Urls.SETTINGS_INDEX_SLUG)} />
+ <Route path="general" lazy={generalSettings} />
+ <Route path="updates" lazy={updatesSettings} />
+ <Route path="email" lazy={emailSettings} />
+ <Route path="slack" lazy={slackSettings} />
+ <Route path="webhooks" lazy={webhooksSettings} />
<Route
- path="enrolled"
- lazy={PLUGIN_MULTI_FACTOR_AUTH.enrolledUsersPage}
+ path="authentication"
+ lazy={authenticationSettings("authentication")}
/>
<Route
- path="unenrolled"
- lazy={PLUGIN_MULTI_FACTOR_AUTH.unenrolledUsersPage}
+ path="authentication/user-provisioning"
+ lazy={authenticationSettings("user-provisioning")}
/>
+ <Route
+ path="authentication/api-keys"
+ lazy={authenticationSettings("api-keys")}
+ />
+ <Route path="authentication/2fa">
+ <Route
+ path="enrolled"
+ lazy={PLUGIN_MULTI_FACTOR_AUTH.enrolledUsersPage}
+ />
+ <Route
+ path="unenrolled"
+ lazy={PLUGIN_MULTI_FACTOR_AUTH.unenrolledUsersPage}
+ />
+ </Route>
+ <Route path="authentication/google" lazy={googleAuth} />
+ <Route path="authentication/ldap" lazy={ldapAuth} />
+ <Route
+ path="authentication/saml"
+ lazy={PLUGIN_AUTH_PROVIDERS.settingsSAMLForm}
+ />
+ <Route
+ path="authentication/jwt"
+ lazy={PLUGIN_AUTH_PROVIDERS.settingsJWTForm}
+ />
+ <Route
+ path="authentication/oidc"
+ lazy={PLUGIN_AUTH_PROVIDERS.settingsOIDCForm}
+ />
+ <Route path="domains" lazy={domainsSettings} />
+ <Route path="remote-sync" lazy={remoteSyncSettings} />
+ <Route path="maps" lazy={mapsSettings} />
+ <Route path="localization" lazy={localizationSettings} />
+ <Route path="custom-visualizations">
+ <Route index lazy={customVisualizationsManage} />
+ <Route path="new" lazy={customVisualizationsForm} />
+ <Route path="edit/:id" lazy={customVisualizationsForm} />
+ {devModeEnabled && (
+ <Route path="development" lazy={customVisualizationsDevelopment} />
+ )}
+ </Route>
+ <Route path={Urls.DATA_APP_URL_SEGMENT}>
+ <Route index lazy={dataAppsManage} />
+ <Route path=":slug/groups" lazy={dataAppGroupsManage} />
+ </Route>
+ <Route path="uploads" lazy={uploadSettings} />
+ <Route
+ path="python-runner"
+ lazy={PLUGIN_TRANSFORMS_PYTHON.pythonRunnerSettingsPage}
+ />
+ <Route path="public-sharing" lazy={publicSharingSettings} />
+ <Route path="license" lazy={licenseSettings} />
+ <Route path="appearance" lazy={appearanceSettings()} />
+ <Route path="whitelabel" lazy={appearanceSettings("branding")} />
+ <Route
+ path="whitelabel/branding"
+ lazy={appearanceSettings("branding")}
+ />
+ <Route
+ path="whitelabel/conceal-metabase"
+ lazy={appearanceSettings("conceal-metabase")}
+ />
+ <Route path="cloud" lazy={cloudSettings} />
</Route>
- <Route path="authentication/google" lazy={googleAuth} />
- <Route path="authentication/ldap" lazy={ldapAuth} />
- <Route
- path="authentication/saml"
- lazy={PLUGIN_AUTH_PROVIDERS.settingsSAMLForm}
- />
- <Route
- path="authentication/jwt"
- lazy={PLUGIN_AUTH_PROVIDERS.settingsJWTForm}
- />
- <Route
- path="authentication/oidc"
- lazy={PLUGIN_AUTH_PROVIDERS.settingsOIDCForm}
- />
- <Route path="domains" lazy={domainsSettings} />
- <Route path="remote-sync" lazy={remoteSyncSettings} />
- <Route path="maps" lazy={mapsSettings} />
- <Route path="localization" lazy={localizationSettings} />
- <Route
- path="custom-visualizations"
- /* do not allow users with "Settings access" permissions to access custom viz pages */
- element={<IsAdmin />}
- >
- <Route index lazy={customVisualizationsManage} />
- <Route path="new" lazy={customVisualizationsForm} />
- <Route path="edit/:id" lazy={customVisualizationsForm} />
- {devModeEnabled && (
- <Route path="development" lazy={customVisualizationsDevelopment} />
- )}
- </Route>
- <Route
- path={
- Urls.DATA_APP_URL_SEGMENT
- } /* do not allow users with "Settings access" permissions to access data apps pages */
- element={<IsAdmin />}
- >
- <Route index lazy={dataAppsManage} />
- <Route path=":slug/groups" lazy={dataAppGroupsManage} />
- </Route>
- <Route path="uploads" lazy={uploadSettings} />
- <Route
- path="python-runner"
- lazy={PLUGIN_TRANSFORMS_PYTHON.pythonRunnerSettingsPage}
- />
- <Route path="public-sharing" lazy={publicSharingSettings} />
- <Route path="license" lazy={licenseSettings} />
- <Route path="appearance" lazy={appearanceSettings()} />
- <Route path="whitelabel" lazy={appearanceSettings("branding")} />
- <Route path="whitelabel/branding" lazy={appearanceSettings("branding")} />
- <Route
- path="whitelabel/conceal-metabase"
- lazy={appearanceSettings("conceal-metabase")}
- />
- <Route path="cloud" lazy={cloudSettings} />
<Route path="*" element={<NotFound />} />
</Route>
);
diff --git a/frontend/src/metabase/current-user/index.ts b/frontend/src/metabase/current-user/index.ts
index dde09776d0b..306699bb80a 100644
--- a/frontend/src/metabase/current-user/index.ts
+++ b/frontend/src/metabase/current-user/index.ts
@@ -22,5 +22,10 @@ export {
getUserIsEntitledAnalyst,
getUserPersonalCollectionId,
} from "./selectors";
+export {
+ SETTINGS_MANAGER_PATHS,
+ getSettingsSlug,
+ isSettingsManagerPath,
+} from "./settings-manager-access";
export { useUserAcknowledgement } from "./use-user-acknowledgement";
export { useUserKeyValue } from "./use-user-key-value";
diff --git a/frontend/src/metabase/current-user/settings-manager-access.ts b/frontend/src/metabase/current-user/settings-manager-access.ts
new file mode 100644
index 00000000000..1c6910e54e7
--- /dev/null
+++ b/frontend/src/metabase/current-user/settings-manager-access.ts
@@ -0,0 +1,36 @@
+import { SETTINGS_INDEX_SLUG } from "metabase/urls";
+
+/**
+ * Pages under /admin/settings that settings managers may open, by slug. Matching is
+ * exact, so a page nested under an allowed one is admin-only until listed here.
+ */
+export const SETTINGS_MANAGER_PATHS: ReadonlySet<string> = new Set([
+ "general",
+ "email",
+ "slack",
+ "webhooks",
+ "localization",
+ "maps",
+ "uploads",
+ "public-sharing",
+ "domains",
+ "appearance",
+ "whitelabel",
+ "whitelabel/branding",
+ "whitelabel/conceal-metabase",
+]);
+
+export function isSettingsManagerPath(slug: string | undefined): boolean {
+ if (slug == null) {
+ return false;
+ }
+ const normalized = slug.replace(/^\/+|\/+$/g, "");
+ const redirected = normalized === "" ? SETTINGS_INDEX_SLUG : normalized;
+ return SETTINGS_MANAGER_PATHS.has(redirected);
+}
+
+/** `/admin/settings/whitelabel/branding/` -> `whitelabel/branding` */
+export function getSettingsSlug(pathname: string): string | undefined {
+ const match = pathname.match(/^\/admin\/settings(?:\/(.*))?$/);
+ return match ? (match[1] ?? "") : undefined;
+}
diff --git a/frontend/src/metabase/current-user/settings-manager-access.unit.spec.ts b/frontend/src/metabase/current-user/settings-manager-access.unit.spec.ts
new file mode 100644
index 00000000000..b627d63c858
--- /dev/null
+++ b/frontend/src/metabase/current-user/settings-manager-access.unit.spec.ts
@@ -0,0 +1,45 @@
+import {
+ getSettingsSlug,
+ isSettingsManagerPath,
+} from "./settings-manager-access";
+
+describe("isSettingsManagerPath", () => {
+ it.each(["", "/", "general", "general/", "whitelabel/branding"] as const)(
+ "allows %j",
+ (slug) => {
+ expect(isSettingsManagerPath(slug)).toBe(true);
+ },
+ );
+
+ it.each([
+ "authentication",
+ "authentication/ldap",
+ "license",
+ "generalized",
+ "general/anything",
+ undefined,
+ ] as const)("rejects %j", (slug) => {
+ expect(isSettingsManagerPath(slug)).toBe(false);
+ });
+});
+
+describe("getSettingsSlug", () => {
+ it("returns an empty slug for /admin/settings", () => {
+ expect(getSettingsSlug("/admin/settings")).toBe("");
+ });
+
+ it("returns an empty slug for /admin/settings/", () => {
+ expect(getSettingsSlug("/admin/settings/")).toBe("");
+ });
+
+ it("strips the settings prefix from a nested path", () => {
+ expect(getSettingsSlug("/admin/settings/whitelabel/branding")).toBe(
+ "whitelabel/branding",
+ );
+ });
+
+ it("returns undefined for paths outside /admin/settings", () => {
+ expect(getSettingsSlug("/admin")).toBeUndefined();
+ expect(getSettingsSlug("/question/1")).toBeUndefined();
+ });
+});
diff --git a/frontend/src/metabase/nav/components/AdminNavbar/AdminNavbar.tsx b/frontend/src/metabase/nav/components/AdminNavbar/AdminNavbar.tsx
index 74d845a5c20..5f05198d255 100644
--- a/frontend/src/metabase/nav/components/AdminNavbar/AdminNavbar.tsx
+++ b/frontend/src/metabase/nav/components/AdminNavbar/AdminNavbar.tsx
@@ -106,7 +106,7 @@ export const AdminNavbar = ({
))}
{/* Security Center is rendered outside adminPaths because it
needs a live query to show an active-advisories badge */}
- {PLUGIN_SECURITY_CENTER.isEnabled && (
+ {PLUGIN_SECURITY_CENTER.isEnabled && isAdmin && (
<PLUGIN_SECURITY_CENTER.SecurityCenterNavItem
currentPath={currentPath}
/>
@@ -116,7 +116,11 @@ export const AdminNavbar = ({
{!isPaidPlan && isAdmin && <StoreLink />}
</Flex>
<Group gap="0.5rem" ms="auto">
- <MobileNavbar adminPaths={adminPaths} currentPath={currentPath} />
+ <MobileNavbar
+ adminPaths={adminPaths}
+ currentPath={currentPath}
+ isAdmin={isAdmin}
+ />
<AppSwitcher />
</Group>
</Flex>
@@ -126,9 +130,14 @@ export const AdminNavbar = ({
interface AdminMobileNavbarProps {
adminPaths: AdminPath[];
currentPath: string;
+ isAdmin: boolean;
}
-const MobileNavbar = ({ adminPaths, currentPath }: AdminMobileNavbarProps) => {
+const MobileNavbar = ({
+ adminPaths,
+ currentPath,
+ isAdmin,
+}: AdminMobileNavbarProps) => {
const [mobileNavOpen, setMobileNavOpen] = useState(false);
const ref = useClickOutside(() => setMobileNavOpen(false));
@@ -174,7 +183,7 @@ const MobileNavbar = ({ adminPaths, currentPath }: AdminMobileNavbarProps) => {
))}
{/* Security Center is rendered outside adminPaths because it
needs a live query to show an active-advisories badge */}
- {PLUGIN_SECURITY_CENTER.isEnabled && (
+ {PLUGIN_SECURITY_CENTER.isEnabled && isAdmin && (
<PLUGIN_SECURITY_CENTER.SecurityCenterMobileNavItem
currentPath={currentPath}
/>
diff --git a/frontend/src/metabase/nav/components/AdminNavbar/AdminNavbar.unit.spec.tsx b/frontend/src/metabase/nav/components/AdminNavbar/AdminNavbar.unit.spec.tsx
index 018993c3194..15a1e1dcde3 100644
--- a/frontend/src/metabase/nav/components/AdminNavbar/AdminNavbar.unit.spec.tsx
+++ b/frontend/src/metabase/nav/components/AdminNavbar/AdminNavbar.unit.spec.tsx
@@ -4,6 +4,7 @@ import { setupBugReportingDetailsEndpoint } from "__support__/server-mocks";
import { mockSettings } from "__support__/settings";
import { createMockState } from "__support__/state";
import { renderWithProviders, screen, waitFor } from "__support__/ui";
+import { PLUGIN_SECURITY_CENTER, reinitialize } from "metabase/plugins";
import type { AdminPath } from "metabase/redux/store";
import { Route } from "metabase/router";
import {
@@ -86,6 +87,32 @@ describe("AdminNavbar", () => {
});
});
+ describe("Security Center tab", () => {
+ function SecurityNavItemStub() {
+ return <li>Security</li>;
+ }
+
+ beforeEach(() => {
+ PLUGIN_SECURITY_CENTER.isEnabled = true;
+ PLUGIN_SECURITY_CENTER.SecurityCenterNavItem = SecurityNavItemStub;
+ PLUGIN_SECURITY_CENTER.SecurityCenterMobileNavItem = SecurityNavItemStub;
+ });
+
+ afterEach(() => {
+ reinitialize();
+ });
+
+ it("hides the Security tab for non-admins when the plugin is enabled", () => {
+ setup({ isAdmin: false });
+ expect(screen.queryByText("Security")).not.toBeInTheDocument();
+ });
+
+ it("shows the Security tab for admins when the plugin is enabled", () => {
+ setup({ isAdmin: true });
+ expect(screen.getByText("Security")).toBeInTheDocument();
+ });
+ });
+
describe("tab shortcuts", () => {
it.each(
ADMIN_PATHS.map(
diff --git a/frontend/src/metabase/palette/constants.ts b/frontend/src/metabase/palette/constants.ts
index 4614e938faf..421691445f3 100644
--- a/frontend/src/metabase/palette/constants.ts
+++ b/frontend/src/metabase/palette/constants.ts
@@ -42,7 +42,6 @@ type AdminSettingsSections = Record<
{
name: string;
hidden?: boolean;
- adminOnly?: boolean;
}
>;
@@ -55,7 +54,6 @@ export const getAdminSettingsSections = (
updates: {
name: t`Updates`,
hidden: settings["token-features"]?.hosting,
- adminOnly: true,
},
email: {
name: t`Email`,
@@ -68,16 +66,13 @@ export const getAdminSettingsSections = (
},
authentication: {
name: t`Authentication`,
- adminOnly: true,
},
"authentication/user-provisioning": {
name: t`User provisioning`,
hidden: !settings["token-features"].scim,
- adminOnly: true,
},
"authentication/api-keys": {
name: t`Api keys`,
- adminOnly: true,
},
domains: {
name: t`Domains`,
diff --git a/frontend/src/metabase/palette/hooks/useCommandPalette.tsx b/frontend/src/metabase/palette/hooks/useCommandPalette.tsx
index 09031c92851..465b6a4d5f3 100644
--- a/frontend/src/metabase/palette/hooks/useCommandPalette.tsx
+++ b/frontend/src/metabase/palette/hooks/useCommandPalette.tsx
@@ -8,7 +8,11 @@ import { ROOT_COLLECTION } from "metabase/common/collections/constants";
import { getCollection } from "metabase/common/collections/utils";
import type { OmniPickerItem } from "metabase/common/components/Pickers";
import { trackSearchClick } from "metabase/common/search/analytics";
-import { canAccessSettings, getUserIsAdmin } from "metabase/current-user";
+import {
+ canAccessSettings,
+ getUserIsAdmin,
+ isSettingsManagerPath,
+} from "metabase/current-user";
import { useGetIcon } from "metabase/hooks/use-icon";
import { useSelector } from "metabase/redux";
import { queryToSearch } from "metabase/router";
@@ -283,12 +287,12 @@ export const useCommandPalette = ({
}
return Object.entries(getAdminSettingsSections(settingValues))
- .filter(([_slug, section]) => {
+ .filter(([slug, section]) => {
if (section.hidden) {
return false;
}
- if (section.adminOnly && !isAdmin) {
+ if (!isAdmin && !isSettingsManagerPath(slug)) {
return false;
}
diff --git a/frontend/src/metabase/urls/admin.ts b/frontend/src/metabase/urls/admin.ts
index ce602cd58d8..4c0e956f8fc 100644
--- a/frontend/src/metabase/urls/admin.ts
+++ b/frontend/src/metabase/urls/admin.ts
@@ -144,8 +144,11 @@ export function dataModelSegmentRevisions(segmentId: SegmentId) {
return `${dataModelSegment(segmentId)}/revisions`;
}
+/** Default `/admin/settings` page. The index route redirects here. */
+export const SETTINGS_INDEX_SLUG = "general";
+
export function generalSettings() {
- return "/admin/settings/general";
+ return `/admin/settings/${SETTINGS_INDEX_SLUG}`;
}
export function domainsSettings() {