Skip to content

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

Move SSO user provisioning a toggle card under server settings (#82232)

Andrei Chernykh0c76874681f7
diff --git a/e2e/test/scenarios/admin-2/sso/jwt.cy.spec.js b/e2e/test/scenarios/admin-2/sso/jwt.cy.spec.js
index 5227e2ce63b..598fc5976f2 100644
--- a/e2e/test/scenarios/admin-2/sso/jwt.cy.spec.js
+++ b/e2e/test/scenarios/admin-2/sso/jwt.cy.spec.js
@@ -47,12 +47,15 @@ describe("scenarios > admin > settings > SSO > JWT", () => {
enableJwtAuth();
cy.visit("/admin/settings/authentication/jwt");
- cy.findByTestId("jwt-user-provisioning-enabled?-setting")
- .findByText(/^Disabled/)
- .click();
+ cy.findByRole("switch", { name: "User provisioning" })
+ .should("be.checked")
+ .click({ force: true });
cy.wait("@updateSetting");
H.undoToast().findByText("Changes saved").should("be.visible");
+ cy.findByRole("switch", { name: "User provisioning" }).should(
+ "not.be.checked",
+ );
});
it("should allow to reset jwt settings", () => {
diff --git a/e2e/test/scenarios/admin-2/sso/ldap.cy.spec.js b/e2e/test/scenarios/admin-2/sso/ldap.cy.spec.js
index a6db5fbb49b..d1d8332ce7e 100644
--- a/e2e/test/scenarios/admin-2/sso/ldap.cy.spec.js
+++ b/e2e/test/scenarios/admin-2/sso/ldap.cy.spec.js
@@ -182,11 +182,14 @@ describe(
H.setupLdap();
cy.visit("/admin/settings/authentication/ldap");
- cy.findByTestId("ldap-user-provisioning-enabled?-setting")
- .findByText(/^Disabled/)
- .click();
+ cy.findByRole("switch", { name: "User provisioning" })
+ .should("be.checked")
+ .click({ force: true });
H.undoToast().findByText("Changes saved").should("be.visible");
+ cy.findByRole("switch", { name: "User provisioning" }).should(
+ "not.be.checked",
+ );
});
it("should show the login form when ldap is enabled but password login isn't (metabase#25661)", () => {
diff --git a/e2e/test/scenarios/admin-2/sso/saml.cy.spec.js b/e2e/test/scenarios/admin-2/sso/saml.cy.spec.js
index 626e7cf7a81..1d55f19f67c 100644
--- a/e2e/test/scenarios/admin-2/sso/saml.cy.spec.js
+++ b/e2e/test/scenarios/admin-2/sso/saml.cy.spec.js
@@ -78,11 +78,14 @@ describe("scenarios > admin > settings > SSO > SAML", () => {
setupSaml();
cy.visit("/admin/settings/authentication/saml");
- cy.findByTestId("saml-user-provisioning-enabled?-setting")
- .findByText(/^Disabled/)
- .click();
+ cy.findByRole("switch", { name: "User provisioning" })
+ .should("be.checked")
+ .click({ force: true });
cy.wait("@updateSetting");
H.undoToast().findByText("Changes saved").should("exist");
+ cy.findByRole("switch", { name: "User provisioning" }).should(
+ "not.be.checked",
+ );
});
describe("Group Mappings Widget", () => {
diff --git a/enterprise/frontend/src/metabase-enterprise/auth/components/Ldap.tsx b/enterprise/frontend/src/metabase-enterprise/auth/components/Ldap.tsx
index c10cdd83307..21e5d113899 100644
--- a/enterprise/frontend/src/metabase-enterprise/auth/components/Ldap.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/auth/components/Ldap.tsx
@@ -1,22 +1,16 @@
import { t } from "ttag";
-import { SettingsSection } from "metabase/admin/components/SettingsSection";
-import { AdminSettingInput } from "metabase/admin/settings/components/widgets/AdminSettingInput";
import { getExtraFormFieldProps } from "metabase/admin/settings/utils";
import { FormTextInput } from "metabase/forms";
import { useAdminSetting } from "metabase/settings";
-import { provisioningOptions } from "metabase-enterprise/auth/utils";
+import { UserProvisioningSection } from "metabase-enterprise/auth/components/UserProvisioningSection";
export function LdapUserProvisioning() {
return (
- <SettingsSection>
- <AdminSettingInput
- name="ldap-user-provisioning-enabled?"
- title={t`User provisioning`}
- inputType="radio"
- options={provisioningOptions("LDAP")}
- />
- </SettingsSection>
+ <UserProvisioningSection
+ settingKey="ldap-user-provisioning-enabled?"
+ providerName="LDAP"
+ />
);
}
diff --git a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsJWTForm/SettingsJWTForm.tsx b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsJWTForm/SettingsJWTForm.tsx
index 292ba2bc2d5..9063d67f959 100644
--- a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsJWTForm/SettingsJWTForm.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsJWTForm/SettingsJWTForm.tsx
@@ -9,7 +9,6 @@ import {
SettingsPageWrapper,
SettingsSection,
} from "metabase/admin/components/SettingsSection";
-import { AdminSettingInput } from "metabase/admin/settings/components/widgets/AdminSettingInput";
import { getExtraFormFieldProps } from "metabase/admin/settings/utils";
import { LeaveRouteConfirmModal } from "metabase/common/components/LeaveConfirmModal";
import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
@@ -29,7 +28,7 @@ import {
useGetAdminSettingsDetailsQuery,
} from "metabase/settings";
import { Box, Flex, Stack } from "metabase/ui";
-import { provisioningOptions } from "metabase-enterprise/auth/utils";
+import { UserProvisioningSection } from "metabase-enterprise/auth/components/UserProvisioningSection";
import type {
EnterpriseSettings,
SettingDefinition,
@@ -142,16 +141,6 @@ export const SettingsJWTForm = () => {
return (
<SettingsPageWrapper title={t`JWT`}>
- {jwtEnabled && (
- <SettingsSection>
- <AdminSettingInput
- name="jwt-user-provisioning-enabled?"
- title={t`User provisioning`}
- inputType="radio"
- options={provisioningOptions("JWT")}
- />
- </SettingsSection>
- )}
<FormProvider
initialValues={getFormValues(settingDetails)}
onSubmit={saveSettings}
@@ -186,6 +175,12 @@ export const SettingsJWTForm = () => {
/>
</Stack>
</SettingsSection>
+ {/* the card saves on its own, so it stays out of the form's values */}
+ <UserProvisioningSection
+ settingKey="jwt-user-provisioning-enabled?"
+ providerName="JWT"
+ disabled={!isServerConfigured}
+ />
<CollapsibleSettingsSection
title={t`User attribute configuration`}
description={t`You can send additional user attributes to ${applicationName} by adding the attributes as key/value pairs to your JWT`}
diff --git a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsJWTForm/SettingsJWTForm.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsJWTForm/SettingsJWTForm.unit.spec.tsx
index b933d16ff59..18d194efee9 100644
--- a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsJWTForm/SettingsJWTForm.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsJWTForm/SettingsJWTForm.unit.spec.tsx
@@ -15,6 +15,7 @@ import {
within,
} from "__support__/ui";
import { settingsApi } from "metabase/settings";
+import { PROVISIONING_WRITE_DEBOUNCE_MS } from "metabase-enterprise/auth/components/UserProvisioningSection";
import type { SettingDefinition } from "metabase-types/api";
import { createMockGroup, createMockSettings } from "metabase-types/api/mocks";
@@ -39,8 +40,12 @@ const setup = async ({
groupMappings,
groupSyncEnvConfigured,
groupMappingsEnvConfigured,
+ userProvisioning,
+ userProvisioningEnvConfigured,
saveStatus,
saveDelayMs,
+ provisioningSaveStatus,
+ provisioningSaveDelayMs,
cascadeStatus,
cascadeDelayMs,
}: {
@@ -54,14 +59,32 @@ const setup = async ({
groupMappings?: Record<string, number[]>;
groupSyncEnvConfigured?: boolean;
groupMappingsEnvConfigured?: boolean;
+ userProvisioning?: boolean;
+ userProvisioningEnvConfigured?: boolean;
saveStatus?: number;
saveDelayMs?: number;
+ provisioningSaveStatus?: number;
+ provisioningSaveDelayMs?: number;
cascadeStatus?: number;
cascadeDelayMs?: number;
} = {}) => {
const settingDefinitions: SettingDefinition[] = [
{ key: "use-tenants", value: useTenants ?? false },
{ key: "jwt-enabled", value: jwtEnabled ?? false },
+ ...(userProvisioningEnvConfigured
+ ? ([
+ {
+ key: "jwt-user-provisioning-enabled?",
+ is_env_setting: true,
+ env_name: "MB_JWT_USER_PROVISIONING_ENABLED",
+ },
+ ] as const)
+ : ([
+ {
+ key: "jwt-user-provisioning-enabled?",
+ value: userProvisioning ?? true,
+ },
+ ] as const)),
...(groupSyncEnvConfigured
? ([
{
@@ -106,6 +129,7 @@ const setup = async ({
const sessionSettings = createMockSettings({
"use-tenants": useTenants,
"jwt-enabled": jwtEnabled,
+ "jwt-user-provisioning-enabled?": userProvisioning ?? true,
"jwt-group-sync": groupSync ?? false,
"jwt-group-mappings": groupMappings ?? {},
});
@@ -151,6 +175,22 @@ const setup = async ({
{ name: "update-settings", delay: saveDelayMs },
);
}
+ if (provisioningSaveStatus != null || provisioningSaveDelayMs != null) {
+ // the single-key write behaves the same way for the provisioning switch
+ const status = provisioningSaveStatus ?? 204;
+ fetchMock.removeRoute("update-setting");
+ fetchMock.put(
+ new RegExp("/api/setting/(.+)"),
+ ({ url, options }) => {
+ if (status < 300) {
+ const key = decodeURIComponent(url.split("/api/setting/")[1]);
+ settingsStore[key] = JSON.parse(String(options.body)).value;
+ }
+ return { status };
+ },
+ { name: "update-setting", delay: provisioningSaveDelayMs },
+ );
+ }
setupGenerateRandomTokenEndpoint("1234abcd");
fetchMock.get("path:/api/permissions/group", GROUPS);
@@ -163,7 +203,7 @@ const setup = async ({
delay: cascadeDelayMs,
});
- const { store } = renderWithProviders(<SettingsJWTForm />, {
+ const { store, unmount } = renderWithProviders(<SettingsJWTForm />, {
withUndos: true,
storeInitialState: createMockState({
settings: createMockSettingsState(sessionSettings),
@@ -171,7 +211,7 @@ const setup = async ({
});
await screen.findByText("Server settings");
- return { store, settingsStore };
+ return { store, settingsStore, unmount };
};
const expandUserAttributeSection = async () => {
@@ -227,7 +267,11 @@ describe("SettingsJWTForm", () => {
const attributeHeader = screen.getByRole("button", {
name: /User attribute configuration/,
});
+ const provisioningToggle = screen.getByRole("switch", {
+ name: "User provisioning",
+ });
expect(attributeHeader).toBeDisabled();
+ expect(provisioningToggle).toBeDisabled();
await fillServerSettings();
await userEvent.click(
@@ -248,6 +292,7 @@ describe("SettingsJWTForm", () => {
"jwt-group-mappings": {},
});
await waitFor(() => expect(attributeHeader).toBeEnabled());
+ expect(provisioningToggle).toBeEnabled();
expect(screen.getByRole("radio", { name: "Automatic" })).toBeChecked();
expect(screen.getByRole("radio", { name: "Automatic" })).toBeEnabled();
expect(
@@ -377,26 +422,222 @@ describe("SettingsJWTForm", () => {
expect(body).toHaveProperty("jwt-attribute-tenant", "Cat");
});
- it("User provisioning should not appear if JWT has not been enabled", async () => {
- await setup({ jwtEnabled: false });
+ describe("user provisioning", () => {
+ afterEach(() => {
+ jest.useRealTimers();
+ });
+
+ it("sits right below the server settings", async () => {
+ await setup();
+
+ const cardTitles = screen
+ .getAllByRole("heading", { level: 2 })
+ .map((heading) => heading.textContent);
+ expect(cardTitles).toEqual([
+ "Server settings",
+ "User provisioning",
+ "User attribute configuration",
+ "Group mapping",
+ ]);
+ });
+
+ it("stays editable while JWT is paused but configured", async () => {
+ await setup({ jwtEnabled: false, configured: true });
- const saveButton = await screen.findByRole("button", {
- name: "Save and enable",
+ expect(
+ screen.getByRole("switch", { name: "User provisioning" }),
+ ).toBeEnabled();
});
- expect(saveButton).toBeDisabled();
- expect(screen.queryByText(/user provisioning/i)).not.toBeInTheDocument();
- });
+ it("saves right away without touching the page form", async () => {
+ await setup({ jwtEnabled: true, configured: true });
+ const toggle = screen.getByRole("switch", { name: "User provisioning" });
+ expect(toggle).toBeChecked();
- it("User provisioning should appear if JWT has been enabled", async () => {
- await setup({ jwtEnabled: true });
+ // the title is the switch's label, so clicking it toggles too
+ await userEvent.click(
+ screen.getByText("User provisioning", { selector: "label" }),
+ );
- const saveButton = await screen.findByRole("button", {
- name: "Save changes",
+ expect(toggle).not.toBeChecked();
+ expect(await screen.findByText("Changes saved")).toBeInTheDocument();
+ const puts = await findRequests("PUT");
+ expect(puts).toHaveLength(1);
+ expect(puts[0].url).toMatch(
+ /\/api\/setting\/jwt-user-provisioning-enabled%3F$/,
+ );
+ expect(puts[0].body).toEqual({ value: false });
+ expect(
+ screen.getByRole("button", { name: "Save changes" }),
+ ).toBeDisabled();
+ });
+
+ it("reverts the switch and reports the error when the save fails", async () => {
+ await setup({
+ jwtEnabled: true,
+ configured: true,
+ provisioningSaveStatus: 500,
+ provisioningSaveDelayMs: 100,
+ });
+ const toggle = screen.getByRole("switch", { name: "User provisioning" });
+
+ await userEvent.click(toggle);
+
+ // the switch flips right away and only comes back once the write fails
+ expect(toggle).not.toBeChecked();
+ expect(await screen.findByText(/error saving/i)).toBeInTheDocument();
+ expect(toggle).toBeChecked();
+ expect(toggle).toBeEnabled();
+ });
+
+ it("keeps Enter on the switch from submitting the page form", async () => {
+ jest.useFakeTimers();
+ const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
+ await setup({ jwtEnabled: true, configured: true });
+ await user.type(
+ screen.getByRole("textbox", { name: /JWT Identity Provider URI/ }),
+ "-edited",
+ );
+ const submitButton = screen.getByRole("button", { name: "Save changes" });
+ expect(submitButton).toBeEnabled();
+ const toggle = screen.getByRole("switch", { name: "User provisioning" });
+
+ toggle.focus();
+ await user.keyboard("{Enter}");
+
+ // give a submission time to reach the network before ruling it out
+ await act(() => jest.advanceTimersByTimeAsync(1000));
+ expect(await findRequests("PUT")).toHaveLength(0);
+ expect(toggle).toBeChecked();
+ expect(submitButton).toBeEnabled();
});
- expect(saveButton).toBeDisabled();
- expect(screen.getByText(/user provisioning/i)).toBeInTheDocument();
+ it("sends one write for a burst of clicks", async () => {
+ jest.useFakeTimers();
+ const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
+ await setup({ jwtEnabled: true, configured: true });
+ const toggle = screen.getByRole("switch", { name: "User provisioning" });
+
+ await user.click(toggle);
+ await user.click(toggle);
+ await user.click(toggle);
+
+ expect(toggle).not.toBeChecked();
+ await act(() =>
+ jest.advanceTimersByTimeAsync(PROVISIONING_WRITE_DEBOUNCE_MS),
+ );
+ expect(await screen.findByText("Changes saved")).toBeInTheDocument();
+ const puts = await findRequests("PUT");
+ expect(puts).toHaveLength(1);
+ expect(puts[0].body).toEqual({ value: false });
+ });
+
+ it("writes a pending toggle when the page is left before the debounce fires", async () => {
+ jest.useFakeTimers();
+ const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
+ const { unmount } = await setup({ jwtEnabled: true, configured: true });
+ const toggle = screen.getByRole("switch", { name: "User provisioning" });
+
+ await user.click(toggle);
+ unmount();
+
+ await waitFor(async () => {
+ expect(await findRequests("PUT")).toHaveLength(1);
+ });
+ const puts = await findRequests("PUT");
+ expect(puts[0].body).toEqual({ value: false });
+ });
+
+ it("keeps the switch focused and enabled while the write is in flight", async () => {
+ await setup({
+ jwtEnabled: true,
+ configured: true,
+ provisioningSaveDelayMs: 100,
+ });
+ const toggle = screen.getByRole("switch", { name: "User provisioning" });
+
+ toggle.focus();
+ await userEvent.keyboard(" ");
+
+ expect(toggle).not.toBeChecked();
+ expect(toggle).toBeEnabled();
+ expect(toggle).toHaveFocus();
+ expect(await screen.findByText("Changes saved")).toBeInTheDocument();
+ expect(toggle).toHaveFocus();
+ });
+
+ it("keeps the written value while an older properties refetch lands", async () => {
+ jest.useFakeTimers();
+ const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
+ const { store, settingsStore } = await setup({
+ jwtEnabled: true,
+ configured: true,
+ });
+ const toggle = screen.getByRole("switch", { name: "User provisioning" });
+ const loadRequests = fetchMock.callHistory.calls(
+ "get-session-properties",
+ ).length;
+ // a refetch that started before the click answers after the write has gone out
+ const staleSnapshot = { ...settingsStore };
+ fetchMock.removeRoute("get-session-properties");
+ fetchMock.get("path:/api/session/properties", staleSnapshot, {
+ name: "stale-session-properties",
+ delay: PROVISIONING_WRITE_DEBOUNCE_MS + 100,
+ repeat: 1,
+ });
+ fetchMock.get(
+ "path:/api/session/properties",
+ () => ({ ...settingsStore }),
+ { name: "get-session-properties", delay: 200 },
+ );
+ act(() => {
+ store.dispatch(settingsApi.util.invalidateTags(["session-properties"]));
+ });
+ await waitFor(() =>
+ expect(
+ fetchMock.callHistory.calls("stale-session-properties"),
+ ).toHaveLength(1),
+ );
+ // a click in the same millisecond would look like it came after the refetch
+ act(() => {
+ jest.advanceTimersByTime(5);
+ });
+
+ await user.click(toggle);
+
+ expect(toggle).not.toBeChecked();
+ // the write goes out, then the stale answer lands while the write's own refetch is still pending
+ await act(() =>
+ jest.advanceTimersByTimeAsync(PROVISIONING_WRITE_DEBOUNCE_MS + 100),
+ );
+ expect(await screen.findByText("Changes saved")).toBeInTheDocument();
+ expect(toggle).not.toBeChecked();
+ // the refetch after the write is the only one left to land
+ await waitFor(() =>
+ expect(
+ fetchMock.callHistory.calls("get-session-properties"),
+ ).toHaveLength(loadRequests + 1),
+ );
+ await act(() => jest.advanceTimersByTimeAsync(200));
+ expect(toggle).not.toBeChecked();
+ });
+
+ it("locks the switch to the value set through an env var", async () => {
+ await setup({
+ jwtEnabled: true,
+ configured: true,
+ userProvisioning: true,
+ userProvisioningEnvConfigured: true,
+ });
+
+ // the effective value comes from the session properties, the admin list nils it
+ const toggle = screen.getByRole("switch", { name: "User provisioning" });
+ expect(toggle).toBeDisabled();
+ expect(toggle).toBeChecked();
+ expect(toggle).toHaveAccessibleDescription(
+ /Using MB_JWT_USER_PROVISIONING_ENABLED/,
+ );
+ });
});
describe("group mapping", () => {
diff --git a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsOIDCForm/SettingsOIDCForm.tsx b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsOIDCForm/SettingsOIDCForm.tsx
index 44b71188d60..12408b2b674 100644
--- a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsOIDCForm/SettingsOIDCForm.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsOIDCForm/SettingsOIDCForm.tsx
@@ -11,7 +11,6 @@ import {
SettingsPageWrapper,
SettingsSection,
} from "metabase/admin/components/SettingsSection";
-import { AdminSettingInput } from "metabase/admin/settings/components/widgets/AdminSettingInput";
import { GroupMappingsWidgetView } from "metabase/admin/settings/components/widgets/GroupMappingsWidget/GroupMappingsWidgetView";
import { SETTINGS_FIELD_DESCRIPTION_PROPS } from "metabase/admin/settings/utils";
import {
@@ -43,7 +42,7 @@ import {
useGetCustomOidcProvidersQuery,
useUpdateCustomOidcMutation,
} from "metabase-enterprise/api";
-import { provisioningOptions } from "metabase-enterprise/auth/utils";
+import { UserProvisioningSection } from "metabase-enterprise/auth/components/UserProvisioningSection";
import type { Group, GroupId } from "metabase-types/api";
const DEFAULT_SCOPES = ["openid", "email", "profile"];
@@ -367,15 +366,6 @@ export function SettingsOIDCForm() {
return (
<SettingsPageWrapper title={t`OpenID Connect`}>
- <SettingsSection>
- <AdminSettingInput
- name="oidc-user-provisioning-enabled?"
- title={t`User provisioning`}
- inputType="radio"
- options={provisioningOptions("OIDC")}
- />
- </SettingsSection>
-
<FormProvider
initialValues={initialValues}
onSubmit={handleSubmit}
@@ -436,6 +426,12 @@ export function SettingsOIDCForm() {
</Stack>
</SettingsSection>
+ {/* the card saves on its own, so it stays out of the form's values */}
+ <UserProvisioningSection
+ settingKey="oidc-user-provisioning-enabled?"
+ providerName="OIDC"
+ />
+
{isExisting && (
<SettingsSection
title={t`Group mapping`}
diff --git a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsOIDCForm/SettingsOIDCForm.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsOIDCForm/SettingsOIDCForm.unit.spec.tsx
index 2f89546cea7..08eaa857516 100644
--- a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsOIDCForm/SettingsOIDCForm.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsOIDCForm/SettingsOIDCForm.unit.spec.tsx
@@ -3,8 +3,8 @@ import fetchMock from "fetch-mock";
import {
findRequests,
- setupPropertiesEndpoints,
setupSettingsEndpoints,
+ setupStatefulSettingsEndpoints,
} from "__support__/server-mocks";
import { renderWithProviders, screen, waitFor } from "__support__/ui";
import type { CustomOidcConfig } from "metabase-enterprise/api";
@@ -48,7 +48,8 @@ function setupEndpoints({
} = {}) {
const settings = createMockSettings();
setupSettingsEndpoints([]);
- setupPropertiesEndpoints(settings);
+ // the provisioning switch reads its value back after saving, so the properties mock has to remember writes
+ setupStatefulSettingsEndpoints(settings);
fetchMock.get("path:/api/permissions/group", GROUPS);
fetchMock.get("path:/api/ee/sso/oidc", providers, {
@@ -71,7 +72,7 @@ async function getOidcPutCalls() {
const setup = async (options?: { providers?: CustomOidcConfig[] }) => {
setupEndpoints(options);
- renderWithProviders(<SettingsOIDCForm />);
+ renderWithProviders(<SettingsOIDCForm />, { withUndos: true });
await screen.findByText("OpenID Connect");
};
@@ -289,3 +290,46 @@ describe("SettingsOIDCForm - Group Sync", () => {
});
});
});
+
+describe("SettingsOIDCForm - user provisioning", () => {
+ it("sits right below the server settings", async () => {
+ await setup({ providers: [EXISTING_PROVIDER] });
+
+ const cardTitles = screen
+ .getAllByRole("heading", { level: 2 })
+ .map((heading) => heading.textContent);
+ expect(cardTitles).toEqual([
+ "Server settings",
+ "User provisioning",
+ "Group mapping",
+ "Optional settings",
+ "Attribute mapping",
+ ]);
+ });
+
+ it("stays editable before a provider is saved", async () => {
+ await setup({ providers: [] });
+
+ const toggle = screen.getByRole("switch", { name: "User provisioning" });
+ await waitFor(() => expect(toggle).toBeEnabled());
+ });
+
+ it("saves right away without touching the page form", async () => {
+ await setup({ providers: [EXISTING_PROVIDER] });
+ const toggle = screen.getByRole("switch", { name: "User provisioning" });
+ await waitFor(() => expect(toggle).toBeEnabled());
+ expect(toggle).toBeChecked();
+
+ await userEvent.click(toggle);
+
+ await waitFor(() => expect(toggle).not.toBeChecked());
+ expect(await screen.findByText("Changes saved")).toBeInTheDocument();
+ const puts = await findRequests("PUT");
+ expect(puts).toHaveLength(1);
+ expect(puts[0].url).toMatch(
+ /\/api\/setting\/oidc-user-provisioning-enabled%3F$/,
+ );
+ expect(puts[0].body).toEqual({ value: false });
+ expect(screen.getByRole("button", { name: "Save changes" })).toBeDisabled();
+ });
+});
diff --git a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsSAMLForm/SettingsSAMLForm.tsx b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsSAMLForm/SettingsSAMLForm.tsx
index f1bbb0c221a..f839dff048b 100644
--- a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsSAMLForm/SettingsSAMLForm.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsSAMLForm/SettingsSAMLForm.tsx
@@ -11,8 +11,6 @@ import {
SettingsPageWrapper,
SettingsSection,
} from "metabase/admin/components/SettingsSection";
-import { SettingHeader } from "metabase/admin/settings/components/SettingHeader";
-import { AdminSettingInput } from "metabase/admin/settings/components/widgets/AdminSettingInput";
import { GroupMappingsWidget } from "metabase/admin/settings/components/widgets/GroupMappingsWidget";
import {
SETTINGS_FIELD_DESCRIPTION_PROPS,
@@ -40,12 +38,11 @@ import {
} from "metabase/settings";
import { Flex, Stack, Text, Title } from "metabase/ui";
import { useUpdateSamlMutation } from "metabase-enterprise/api";
-import { provisioningOptions } from "metabase-enterprise/auth/utils";
+import { UserProvisioningSection } from "metabase-enterprise/auth/components/UserProvisioningSection";
import type { EnterpriseSettings } from "metabase-types/api";
export type SAMLFormSettings = Pick<
EnterpriseSettings,
- | "saml-user-provisioning-enabled?"
| "saml-attribute-email"
| "saml-attribute-firstname"
| "saml-attribute-lastname"
@@ -88,6 +85,7 @@ export function SettingsSAMLForm() {
);
const siteUrl = useSetting("site-url");
+ const scimEnabled = useSetting("scim-enabled");
if (isLoadingDetails || isLoadingValues) {
return <LoadingAndErrorWrapper loading />;
@@ -105,6 +103,14 @@ export function SettingsSAMLForm() {
settingValues["saml-keystore-path"] || settingValues["saml-keystore-alias"],
);
+ // the backend keeps SAML provisioning off while SCIM owns provisioning
+ const scimNote = scimEnabled && (
+ <Markdown>
+ {t`You cannot enable SAML user provisioning while user provisioning is [managed by SCIM]` +
+ "(/admin/settings/authentication/user-provisioning)."}
+ </Markdown>
+ );
+
return (
<SettingsPageWrapper
title={t`SAML`}
@@ -115,7 +121,6 @@ export function SettingsSAMLForm() {
>{t`documentation`}</ExternalLink>
)}.`}
>
- {isEnabled && <SamlUserProvisioning />}
<FormProvider
initialValues={getFormValues(settingValues ?? {})}
onSubmit={handleSubmit}
@@ -227,6 +232,13 @@ export function SettingsSAMLForm() {
</Stack>
</SettingsSection>
+ {/* the card saves on its own, so it stays out of the form's values */}
+ <UserProvisioningSection
+ settingKey="saml-user-provisioning-enabled?"
+ providerName="SAML"
+ lockedNote={scimNote}
+ />
+
<CollapsibleSettingsSection
title={t`Sign SSO requests (optional)`}
defaultOpened={hasKeystoreSettings}
@@ -311,7 +323,6 @@ const getFormValues = (
allSettings: Partial<EnterpriseSettings>,
): SAMLFormSettings => {
const samlSettings = _.pick(allSettings, [
- "saml-user-provisioning-enabled?",
"saml-attribute-email",
"saml-attribute-firstname",
"saml-attribute-lastname",
@@ -327,42 +338,6 @@ const getFormValues = (
"saml-group-sync",
]);
- if (samlSettings["saml-user-provisioning-enabled?"] == null) {
- // cast empty to false
- samlSettings["saml-user-provisioning-enabled?"] = false;
- }
// cast undefined to null
return _.mapObject(samlSettings, (val) => val ?? null) as SAMLFormSettings;
};
-
-function SamlUserProvisioning() {
- const scimEnabled = useSetting("scim-enabled");
-
- if (scimEnabled) {
- return (
- <SettingsSection>
- <SettingHeader
- id="saml-user-provisioning-enabled?"
- title={t`User provisioning`}
- description={
- <Markdown>
- {t`You cannot enable SAML user provisioning while user provisioning is [managed by SCIM]` +
- "(/admin/settings/authentication/user-provisioning)."}
- </Markdown>
- }
- />
- </SettingsSection>
- );
- }
-
- return (
- <SettingsSection>
- <AdminSettingInput
- name="saml-user-provisioning-enabled?"
- title={t`User provisioning`}
- inputType="radio"
- options={provisioningOptions("SAML")}
- />
- </SettingsSection>
- );
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsSAMLForm/SettingsSAMLForm.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsSAMLForm/SettingsSAMLForm.unit.spec.tsx
index 48f879b9d68..15ba90d88b4 100644
--- a/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsSAMLForm/SettingsSAMLForm.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/auth/components/SettingsSAMLForm/SettingsSAMLForm.unit.spec.tsx
@@ -3,13 +3,14 @@ import fetchMock from "fetch-mock";
import {
findRequests,
- setupPropertiesEndpoints,
setupSettingsEndpoints,
+ setupStatefulSettingsEndpoints,
} from "__support__/server-mocks";
import { renderWithProviders, screen, waitFor } from "__support__/ui";
+import type { EnterpriseSettings, SettingDefinition } from "metabase-types/api";
import { createMockGroup, createMockSettings } from "metabase-types/api/mocks";
-import { type SAMLFormSettings, SettingsSAMLForm } from "./SettingsSAMLForm";
+import { SettingsSAMLForm } from "./SettingsSAMLForm";
const GROUPS = [
createMockGroup(),
@@ -20,20 +21,18 @@ const GROUPS = [
];
const setup = async (
- settingValues?: Partial<SAMLFormSettings> & { "saml-enabled"?: boolean },
+ settingValues?: Partial<EnterpriseSettings>,
+ settingDefinitions: SettingDefinition[] = [],
) => {
const settings = createMockSettings(settingValues ?? {});
- setupSettingsEndpoints([]);
- setupPropertiesEndpoints(settings);
+ setupSettingsEndpoints(settingDefinitions);
+ // the provisioning switch reads its value back after saving, so the properties mock has to remember writes
+ setupStatefulSettingsEndpoints(settings);
fetchMock.get("path:/api/permissions/group", GROUPS);
fetchMock.put("path:/api/saml/settings", { status: 204 });
- renderWithProviders(
- <>
- <SettingsSAMLForm />
- </>,
- );
+ renderWithProviders(<SettingsSAMLForm />, { withUndos: true });
await screen.findByText("Configure your identity provider (IdP)");
await waitFor(async () => {
@@ -113,4 +112,99 @@ describe("SettingsSAMLForm", () => {
expect(body["saml-identity-provider-certificate"]).toBe(fields[1].value);
expect(body["saml-identity-provider-issuer"]).toBe(fields[2].value);
});
+
+ describe("user provisioning", () => {
+ const CONFIGURED = {
+ "saml-enabled": true,
+ "saml-identity-provider-uri": "https://example.test",
+ "saml-identity-provider-certificate": fields[1].value,
+ "saml-identity-provider-issuer": fields[2].value,
+ };
+
+ it("sits right below the identity provider settings", async () => {
+ await setup(CONFIGURED);
+
+ const cardTitles = screen
+ .getAllByRole("heading", { level: 2 })
+ .map((heading) => heading.textContent);
+ expect(cardTitles).toEqual([
+ "Configure your identity provider (IdP)",
+ "Tell Metabase about your identity provider",
+ "User provisioning",
+ "Sign SSO requests (optional)",
+ "Group mapping",
+ ]);
+ });
+
+ it("stays editable before the identity provider is set up", async () => {
+ await setup();
+
+ expect(
+ screen.getByRole("switch", { name: "User provisioning" }),
+ ).toBeEnabled();
+ });
+
+ it("saves right away without touching the page form", async () => {
+ await setup({ ...CONFIGURED, "saml-user-provisioning-enabled?": true });
+ const toggle = screen.getByRole("switch", { name: "User provisioning" });
+ expect(toggle).toBeEnabled();
+ expect(toggle).toBeChecked();
+
+ await userEvent.click(toggle);
+
+ await waitFor(() => expect(toggle).not.toBeChecked());
+ expect(await screen.findByText("Changes saved")).toBeInTheDocument();
+ const puts = await findRequests("PUT");
+ expect(puts).toHaveLength(1);
+ expect(puts[0].url).toMatch(
+ /\/api\/setting\/saml-user-provisioning-enabled%3F$/,
+ );
+ expect(puts[0].body).toEqual({ value: false });
+ expect(
+ screen.getByRole("button", { name: "Save changes" }),
+ ).toBeDisabled();
+ });
+
+ it("locks the switch while SCIM manages provisioning", async () => {
+ await setup({
+ ...CONFIGURED,
+ "scim-enabled": true,
+ "saml-user-provisioning-enabled?": false,
+ });
+
+ const toggle = screen.getByRole("switch", { name: "User provisioning" });
+ expect(toggle).toBeDisabled();
+ expect(toggle).not.toBeChecked();
+ expect(
+ screen.getByRole("link", { name: "managed by SCIM" }),
+ ).toHaveAttribute(
+ "href",
+ "/admin/settings/authentication/user-provisioning",
+ );
+ });
+
+ it("shows the SCIM note instead of the env line when both apply", async () => {
+ await setup(
+ {
+ ...CONFIGURED,
+ "scim-enabled": true,
+ "saml-user-provisioning-enabled?": false,
+ },
+ [
+ {
+ key: "saml-user-provisioning-enabled?",
+ is_env_setting: true,
+ env_name: "MB_SAML_USER_PROVISIONING_ENABLED",
+ },
+ ],
+ );
+
+ const toggle = screen.getByRole("switch", { name: "User provisioning" });
+ expect(toggle).toBeDisabled();
+ expect(toggle).toHaveAccessibleDescription(/managed by SCIM/);
+ expect(
+ screen.queryByText("Using MB_SAML_USER_PROVISIONING_ENABLED"),
+ ).not.toBeInTheDocument();
+ });
+ });
});
diff --git a/enterprise/frontend/src/metabase-enterprise/auth/components/UserProvisioningSection/UserProvisioningSection.module.css b/enterprise/frontend/src/metabase-enterprise/auth/components/UserProvisioningSection/UserProvisioningSection.module.css
new file mode 100644
index 00000000000..b83ca750e36
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/auth/components/UserProvisioningSection/UserProvisioningSection.module.css
@@ -0,0 +1,8 @@
+/* the title is the switch's label, so it borrows the switch's pointer */
+.titleLabel {
+ cursor: pointer;
+}
+
+.titleLabel.disabled {
+ cursor: default;
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/auth/components/UserProvisioningSection/UserProvisioningSection.tsx b/enterprise/frontend/src/metabase-enterprise/auth/components/UserProvisioningSection/UserProvisioningSection.tsx
new file mode 100644
index 00000000000..b26c55a3de8
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/auth/components/UserProvisioningSection/UserProvisioningSection.tsx
@@ -0,0 +1,145 @@
+import { useDebouncedCallback } from "@mantine/hooks";
+import cx from "classnames";
+import { useEffect, useId, useState } from "react";
+import { t } from "ttag";
+
+import {
+ SETTINGS_CARD_DESCRIPTION_PROPS,
+ SETTINGS_CARD_TITLE_PROPS,
+ SettingsSection,
+} from "metabase/admin/components/SettingsSection";
+import { useSelector } from "metabase/redux";
+import { getApplicationName } from "metabase/selectors/whitelabel";
+import { useAdminSetting } from "metabase/settings";
+import { Box, Flex, Switch, Text, Title } from "metabase/ui";
+
+import S from "./UserProvisioningSection.module.css";
+
+// a burst of clicks ends in a single write for the last value
+export const PROVISIONING_WRITE_DEBOUNCE_MS = 300;
+
+type PendingWrite = { value: boolean; at: number };
+
+export type UserProvisioningSettingKey =
+ | "jwt-user-provisioning-enabled?"
+ | "ldap-user-provisioning-enabled?"
+ | "oidc-user-provisioning-enabled?"
+ | "saml-user-provisioning-enabled?";
+
+export function UserProvisioningSection({
+ settingKey,
+ providerName,
+ disabled = false,
+ lockedNote,
+}: {
+ settingKey: UserProvisioningSettingKey;
+ // the sign-in method as the description names it
+ providerName: string;
+ // greys the card out on pages that stay read-only until their server settings are saved
+ disabled?: boolean;
+ // says why the switch cannot be toggled and keeps it disabled while shown
+ lockedNote?: React.ReactNode;
+}) {
+ const inputId = useId();
+ const descriptionId = useId();
+ const applicationName = useSelector(getApplicationName);
+ const {
+ value,
+ settingDetails,
+ updateSetting,
+ isLoading,
+ isFetching,
+ startedTimeStamp,
+ } = useAdminSetting(settingKey);
+ // the last written value, shown until a refetch that started after the write lands
+ const [pendingWrite, setPendingWrite] = useState<PendingWrite | null>(null);
+ const envName = settingDetails?.is_env_setting
+ ? settingDetails.env_name
+ : undefined;
+ const hasLockedNote = Boolean(lockedNote);
+ const isLocked = envName != null || hasLockedNote;
+ // the lock is only known once the settings list has loaded
+ const isDisabled = disabled || isLocked || isLoading;
+
+ useEffect(() => {
+ // an older refetch can still answer with the previous value, so only a later one counts
+ if (
+ pendingWrite != null &&
+ !isFetching &&
+ startedTimeStamp != null &&
+ startedTimeStamp >= pendingWrite.at
+ ) {
+ setPendingWrite(null);
+ }
+ }, [pendingWrite, isFetching, startedTimeStamp]);
+
+ // leaving the page flushes a write that is still waiting on the debounce
+ const saveProvisioningSetting = useDebouncedCallback(
+ async (pending: PendingWrite) => {
+ const { error } = await updateSetting({
+ key: settingKey,
+ value: pending.value,
+ });
+ if (error) {
+ setPendingWrite((current) => (current === pending ? null : current));
+ }
+ },
+ { delay: PROVISIONING_WRITE_DEBOUNCE_MS, flushOnUnmount: true },
+ );
+
+ const handleChange = (enabled: boolean) => {
+ const pending = { value: enabled, at: Date.now() };
+ setPendingWrite(pending);
+ saveProvisioningSetting(pending);
+ };
+
+ // the card sits inside the page form, so Enter must not reach its submit button
+ const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
+ if (event.key === "Enter") {
+ event.preventDefault();
+ }
+ };
+
+ return (
+ <SettingsSection disabled={disabled}>
+ <Flex justify="space-between" align="flex-start" gap="lg">
+ <Box>
+ <Title {...SETTINGS_CARD_TITLE_PROPS}>
+ {/* the title doubles as the switch's label, so clicking it toggles too */}
+ <Text
+ component="label"
+ htmlFor={inputId}
+ className={cx(S.titleLabel, isDisabled && S.disabled)}
+ inherit
+ >
+ {t`User provisioning`}
+ </Text>
+ </Title>
+ {/* the notes sit inside the description, so assistive tech hears why the switch is locked */}
+ <Box id={descriptionId}>
+ <Text c="text-secondary" {...SETTINGS_CARD_DESCRIPTION_PROPS}>
+ {t`Allow ${providerName} sign-in to create accounts for new users and reactivate deactivated accounts. When disabled, only users with active ${applicationName} accounts can sign in.`}
+ </Text>
+ {/* a caller's note explains the lock, so the env line steps aside */}
+ {envName != null && !hasLockedNote && (
+ <Text c="text-secondary" mt="sm">{t`Using ${envName}`}</Text>
+ )}
+ {hasLockedNote && (
+ <Box c="text-secondary" mt="sm">
+ {lockedNote}
+ </Box>
+ )}
+ </Box>
+ </Box>
+ <Switch
+ id={inputId}
+ aria-describedby={descriptionId}
+ checked={pendingWrite?.value ?? value ?? false}
+ disabled={isDisabled}
+ onChange={(event) => handleChange(event.currentTarget.checked)}
+ onKeyDown={handleKeyDown}
+ />
+ </Flex>
+ </SettingsSection>
+ );
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/auth/components/UserProvisioningSection/index.ts b/enterprise/frontend/src/metabase-enterprise/auth/components/UserProvisioningSection/index.ts
new file mode 100644
index 00000000000..477bad3eefb
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/auth/components/UserProvisioningSection/index.ts
@@ -0,0 +1 @@
+export * from "./UserProvisioningSection";
diff --git a/enterprise/frontend/src/metabase-enterprise/auth/utils.ts b/enterprise/frontend/src/metabase-enterprise/auth/utils.ts
index 04f04c2c756..072098ce0ac 100644
--- a/enterprise/frontend/src/metabase-enterprise/auth/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/auth/utils.ts
@@ -1,5 +1,3 @@
-import { t } from "ttag";
-
import { hasAnySsoFeature, useGetSettingsQuery } from "metabase/settings";
export const getSSOUrl = (siteUrl: string, redirectUrl?: string): string => {
@@ -28,15 +26,3 @@ export function useHasAnySsoFeature() {
return hasAnySsoFeature(features);
}
-
-export function provisioningOptions(
- label: string,
-): { label: string; value: string }[] {
- const trueLabel = t`Enabled: When a user logs in via ${label}, automatically create an account for them if they don't have one, or reactivate their existing account.`;
- // eslint-disable-next-line metabase/no-literal-metabase-strings -- Emphasizes the difference between Metabase accounts and SSO accounts
- const falseLabel = t`Disabled: Only users with active Metabase accounts can log in using ${label}.`;
- return [
- { value: "true", label: trueLabel },
- { value: "false", label: falseLabel },
- ];
-}
diff --git a/frontend/src/metabase/admin/settings/components/SettingsLdapForm.enterprise.unit.spec.tsx b/frontend/src/metabase/admin/settings/components/SettingsLdapForm.enterprise.unit.spec.tsx
new file mode 100644
index 00000000000..0d94acb0970
--- /dev/null
+++ b/frontend/src/metabase/admin/settings/components/SettingsLdapForm.enterprise.unit.spec.tsx
@@ -0,0 +1,131 @@
+import userEvent from "@testing-library/user-event";
+import fetchMock from "fetch-mock";
+
+import { setupEnterpriseOnlyPlugin } from "__support__/enterprise";
+import {
+ findRequests,
+ setupStatefulSettingsEndpoints,
+} from "__support__/server-mocks";
+import { mockSettings } from "__support__/settings";
+import { renderWithProviders, screen, waitFor } from "__support__/ui";
+import type { EnterpriseSettings, SettingDefinition } from "metabase-types/api";
+import {
+ createMockGroup,
+ createMockSettings,
+ createMockTokenFeatures,
+} from "metabase-types/api/mocks";
+
+import { SettingsLdapForm } from "./SettingsLdapForm";
+
+const setup = async (
+ settingValues?: Partial<EnterpriseSettings>,
+ {
+ settingDefinitions = [],
+ detailsDelayMs,
+ }: { settingDefinitions?: SettingDefinition[]; detailsDelayMs?: number } = {},
+) => {
+ const settings = createMockSettings({
+ "token-features": createMockTokenFeatures({ sso_ldap: true }),
+ ...settingValues,
+ });
+ // the auth plugin reads the token features from the global settings when it registers the LDAP cards
+ const settingsState = mockSettings(settings);
+ setupEnterpriseOnlyPlugin("auth");
+ // the page renders before the admin list lands, so the list can be made to lag
+ fetchMock.get("path:/api/setting", settingDefinitions, {
+ name: "settings-list",
+ delay: detailsDelayMs,
+ });
+ // the provisioning switch reads its value back after saving, so the properties mock has to remember writes
+ setupStatefulSettingsEndpoints(settings);
+ fetchMock.get("path:/api/permissions/group", [createMockGroup()]);
+ fetchMock.put("path:/api/ldap/settings", { status: 204 });
+
+ renderWithProviders(<SettingsLdapForm />, {
+ withUndos: true,
+ storeInitialState: { settings: settingsState },
+ });
+
+ await screen.findByText("Server settings");
+};
+
+describe("SettingsLdapForm (EE)", () => {
+ describe("user provisioning", () => {
+ it("sits right below the server settings", async () => {
+ await setup();
+
+ const cardTitles = screen
+ .getAllByRole("heading", { level: 2 })
+ .map((heading) => heading.textContent);
+ expect(cardTitles).toEqual([
+ "Server settings",
+ "User provisioning",
+ "User schema",
+ "Attributes",
+ "Group mapping",
+ ]);
+ });
+
+ it("stays editable before the LDAP host is saved", async () => {
+ await setup({ "ldap-host": null });
+
+ const toggle = screen.getByRole("switch", { name: "User provisioning" });
+ await waitFor(() => expect(toggle).toBeEnabled());
+ });
+
+ it("keeps the switch disabled until the settings list says whether an env var owns it", async () => {
+ await setup(
+ {
+ "ldap-host": "ldap.example.test",
+ "ldap-user-provisioning-enabled?": true,
+ },
+ {
+ settingDefinitions: [
+ {
+ key: "ldap-user-provisioning-enabled?",
+ is_env_setting: true,
+ env_name: "MB_LDAP_USER_PROVISIONING_ENABLED",
+ },
+ ],
+ detailsDelayMs: 300,
+ },
+ );
+ const toggle = screen.getByRole("switch", { name: "User provisioning" });
+ expect(toggle).toBeDisabled();
+
+ expect(
+ await screen.findByText("Using MB_LDAP_USER_PROVISIONING_ENABLED"),
+ ).toBeInTheDocument();
+ expect(toggle).toBeDisabled();
+ expect(toggle).toBeChecked();
+ expect(toggle).toHaveAccessibleDescription(
+ /Using MB_LDAP_USER_PROVISIONING_ENABLED/,
+ );
+ });
+
+ it("saves right away without touching the page form", async () => {
+ await setup({
+ "ldap-enabled": true,
+ "ldap-host": "ldap.example.test",
+ "ldap-user-provisioning-enabled?": true,
+ });
+ const toggle = screen.getByRole("switch", { name: "User provisioning" });
+ await waitFor(() => expect(toggle).toBeEnabled());
+ expect(toggle).toBeChecked();
+
+ await userEvent.click(toggle);
+
+ await waitFor(() => expect(toggle).not.toBeChecked());
+ expect(await screen.findByText("Changes saved")).toBeInTheDocument();
+ const puts = await findRequests("PUT");
+ expect(puts).toHaveLength(1);
+ expect(puts[0].url).toMatch(
+ /\/api\/setting\/ldap-user-provisioning-enabled%3F$/,
+ );
+ expect(puts[0].body).toEqual({ value: false });
+ expect(
+ screen.getByRole("button", { name: "Save changes" }),
+ ).toBeDisabled();
+ });
+ });
+});
diff --git a/frontend/src/metabase/admin/settings/components/SettingsLdapForm.tsx b/frontend/src/metabase/admin/settings/components/SettingsLdapForm.tsx
index 375b3c6dd67..e0f6de4d6c9 100644
--- a/frontend/src/metabase/admin/settings/components/SettingsLdapForm.tsx
+++ b/frontend/src/metabase/admin/settings/components/SettingsLdapForm.tsx
@@ -84,7 +84,6 @@ export const SettingsLdapForm = () => {
return (
<SettingsPageWrapper title={t`LDAP`}>
- <PLUGIN_LDAP_FORM_FIELDS.LdapUserProvisioning />
<FormProvider
initialValues={getFormValues(settingValues)}
onSubmit={handleSubmit}
@@ -152,6 +151,8 @@ export const SettingsLdapForm = () => {
/>
</Stack>
</SettingsSection>
+ {/* the card saves on its own, so it stays out of the form's values */}
+ <PLUGIN_LDAP_FORM_FIELDS.LdapUserProvisioning />
<SettingsSection
title={t`User schema`}
titleProps={SETTINGS_CARD_TITLE_PROPS}
diff --git a/frontend/src/metabase/admin/settings/components/SettingsLdapForm.unit.spec.tsx b/frontend/src/metabase/admin/settings/components/SettingsLdapForm.unit.spec.tsx
index 95944a81892..4ca707d7b89 100644
--- a/frontend/src/metabase/admin/settings/components/SettingsLdapForm.unit.spec.tsx
+++ b/frontend/src/metabase/admin/settings/components/SettingsLdapForm.unit.spec.tsx
@@ -127,4 +127,13 @@ describe("SettingsLdapForm", () => {
ATTRS["ldap-attribute-lastname"],
);
});
+
+ it("does not offer user provisioning on OSS", async () => {
+ await setup();
+
+ expect(screen.queryByText("User provisioning")).not.toBeInTheDocument();
+ expect(
+ screen.queryByRole("switch", { name: "User provisioning" }),
+ ).not.toBeInTheDocument();
+ });
});