The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Adjusted auth controls for Guest Embed flow Wizard (#66548)
Timofey Kachalovd0b857849796
diff --git a/e2e/test/scenarios/embedding/embedding-smoketests.cy.spec.js b/e2e/test/scenarios/embedding/embedding-smoketests.cy.spec.jsindex b92bc0ec598..9331d4fbd4c 100644--- a/e2e/test/scenarios/embedding/embedding-smoketests.cy.spec.js+++ b/e2e/test/scenarios/embedding/embedding-smoketests.cy.spec.js@@ -54,7 +54,13 @@ describe("scenarios > embedding > smoke tests", { tags: "@OSS" }, () => {it("should not let you use non-guest auth methods", () => {H.visitQuestion(ORDERS_QUESTION_ID);- ensureEmbeddingIsDisabled();+ H.openEmbedJsModal();+ H.embedModalEnableEmbedding();++ H.embedModalContent().within(() => {+ cy.findByLabelText("Guest").should("be.checked");+ cy.findByLabelText("Metabase account (SSO)").should("be.disabled");+ });});});@@ -295,16 +301,6 @@ function resetEmbedding() {H.updateSetting("embedding-secret-key", null);}-function ensureEmbeddingIsDisabled() {- H.openEmbedJsModal();- H.embedModalEnableEmbedding();-- H.embedModalContent().within(() => {- cy.findByLabelText("Single sign-on (SSO)").should("be.disabled");- cy.findByLabelText("Existing Metabase session").should("be.disabled");- });-}-function visitAndEnableSharing(object, unpublishBeforeOpen = true) {const { id, visitFunction } = {question: {diff --git a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/embed-flow-enable-embed-js.cy.spec.ts b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/embed-flow-enable-embed-js.cy.spec.tsindex 0f022e8f09c..fc8f3e0e175 100644--- a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/embed-flow-enable-embed-js.cy.spec.ts+++ b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/embed-flow-enable-embed-js.cy.spec.ts@@ -60,7 +60,9 @@ describe(});cy.log("shows tooltip with fair usage info");- getEmbedSidebar().findByLabelText("info icon").trigger("mouseover");+ embedModalEnableEmbeddingCard()+ .findByLabelText("info icon")+ .trigger("mouseover");H.hovercard().contains(@@ -68,7 +70,9 @@ describe().should("be.visible");- getEmbedSidebar().findByLabelText("info icon").trigger("mouseout");+ embedModalEnableEmbeddingCard()+ .findByLabelText("info icon")+ .trigger("mouseout");cy.findByRole("button", { name: "Agree and enable" }).should("be.visible",diff --git a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/get-code.cy.spec.ts b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/get-code.cy.spec.tsindex 0127061ae8d..2dea47013ab 100644--- a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/get-code.cy.spec.ts+++ b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/get-code.cy.spec.ts@@ -3,13 +3,9 @@ import {ORDERS_DASHBOARD_ID,} from "e2e/support/cypress_sample_instance_data";import { enableJwtAuth } from "e2e/support/helpers/e2e-jwt-helpers";+import { enableSamlAuth } from "e2e/support/helpers/embedding-sdk-testing";-import {- codeBlock,- getEmbedSidebar,- navigateToEmbedOptionsStep,- navigateToGetCodeStep,-} from "./helpers";+import { codeBlock, getEmbedSidebar, navigateToGetCodeStep } from "./helpers";const { H } = cy;@@ -39,6 +35,70 @@ describe(suiteTitle, () => {H.expectNoBadSnowplowEvents();});+ it("should disable SSO radio button (and show info message) when JWT and SAML are not configured", () => {+ navigateToGetCodeStep({+ experience: "dashboard",+ resourceName: DASHBOARD_NAME,+ preselectSso: true,+ });++ getEmbedSidebar().within(() => {+ cy.findByLabelText("Single sign-on").should("be.disabled");+ cy.findByLabelText("Existing session (local testing only)").should(+ "be.enabled",+ );+ cy.findByLabelText("Existing session (local testing only)").should(+ "be.checked",+ );+ cy.findByText(/The code below will only work for local testing/).should(+ "be.visible",+ );+ });+ });++ it("should not display a warning when a user session is selected and JWT is configured", () => {+ enableJwtAuth();++ navigateToGetCodeStep({+ experience: "dashboard",+ resourceName: DASHBOARD_NAME,+ preselectSso: true,+ });++ getEmbedSidebar().within(() => {+ cy.findByLabelText("Existing session (local testing only)").click();+ cy.findByText(/The code below will only work for local testing/).should(+ "not.exist",+ );+ });+ });++ it("should enable SSO radio button when JWT is configured", () => {+ enableJwtAuth();+ navigateToGetCodeStep({+ experience: "dashboard",+ resourceName: DASHBOARD_NAME,+ preselectSso: true,+ });++ getEmbedSidebar().within(() => {+ cy.findByLabelText("Single sign-on").should("not.be.disabled");+ });+ });++ it("should enable SSO radio button when SAML is configured", () => {+ enableSamlAuth();+ navigateToGetCodeStep({+ experience: "dashboard",+ resourceName: DASHBOARD_NAME,+ preselectSso: true,+ });++ getEmbedSidebar().within(() => {+ cy.findByLabelText("Single sign-on").should("not.be.disabled");+ });+ });+it("should display code snippet with syntax highlighting", () => {navigateToGetCodeStep({experience: "dashboard",@@ -54,16 +114,16 @@ describe(suiteTitle, () => {});it("should include useExistingUserSession when user session is selected", () => {- navigateToEmbedOptionsStep({+ enableJwtAuth();+ navigateToGetCodeStep({experience: "dashboard",resourceName: DASHBOARD_NAME,+ preselectSso: true,});getEmbedSidebar().within(() => {- cy.findByLabelText("Existing Metabase session").click();-- cy.findByText("Get code").click();-+ codeBlock().should("not.contain", '"useExistingUserSession": true');+ cy.findByLabelText("Existing session (local testing only)").click();codeBlock().should("contain", '"useExistingUserSession": true');cy.findByText(/Copy code/).click();@@ -71,29 +131,30 @@ describe(suiteTitle, () => {H.expectUnstructuredSnowplowEvent({event: "embed_wizard_code_copied",event_detail:- "experience=dashboard,snippetType=frontend,auth=user-session",+ "experience=dashboard,snippetType=frontend,authSubType=user-session",});});});it("should track embed_wizard_code_copied when copy event triggers", () => {- navigateToEmbedOptionsStep({+ enableJwtAuth();+ navigateToGetCodeStep({experience: "dashboard",resourceName: DASHBOARD_NAME,+ preselectSso: true,});getEmbedSidebar().within(() => {- cy.findByLabelText("Existing Metabase session").click();-- cy.findByText("Get code").click();-+ codeBlock().should("not.contain", '"useExistingUserSession": true');+ cy.findByLabelText("Existing session (local testing only)").click();codeBlock().should("contain", '"useExistingUserSession": true');+codeBlock().trigger("copy");H.expectUnstructuredSnowplowEvent({event: "embed_wizard_code_copied",event_detail:- "experience=dashboard,snippetType=frontend,auth=user-session",+ "experience=dashboard,snippetType=frontend,authSubType=user-session",});});});@@ -101,52 +162,47 @@ describe(suiteTitle, () => {it("should not include useExistingUserSession when SSO is selected", () => {enableJwtAuth();- navigateToEmbedOptionsStep({+ navigateToGetCodeStep({experience: "dashboard",resourceName: DASHBOARD_NAME,+ preselectSso: true,});getEmbedSidebar().within(() => {- cy.findByLabelText("Single sign-on (SSO)").click();-- cy.findByText("Get code").click();-codeBlock().should("not.contain", "useExistingUserSession");cy.findByText(/Copy code/).click();H.expectUnstructuredSnowplowEvent({event: "embed_wizard_code_copied",- event_detail: "experience=dashboard,snippetType=frontend,auth=sso",+ event_detail:+ "experience=dashboard,snippetType=frontend,authSubType=sso",});});});it("should set dashboard-id for regular dashboard experience", () => {- navigateToEmbedOptionsStep({+ navigateToGetCodeStep({experience: "dashboard",resourceName: DASHBOARD_NAME,+ preselectSso: true,});getEmbedSidebar().within(() => {- cy.findByLabelText("Existing Metabase session").click();-- cy.findByText("Get code").click();-codeBlock().should("contain", `dashboard-id="${ORDERS_DASHBOARD_ID}"`);});});it("should set question-id for regular chart experience", () => {- navigateToEmbedOptionsStep({+ enableJwtAuth();+ navigateToGetCodeStep({experience: "chart",resourceName: QUESTION_NAME,+ preselectSso: true,});getEmbedSidebar().within(() => {- cy.findByLabelText("Existing Metabase session").click();-- cy.findByText("Get code").click();+ cy.findByLabelText("Existing session (local testing only)").click();codeBlock().should("contain",diff --git a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/guest-embed-ee.cy.spec.ts b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/guest-embed-ee.cy.spec.tsindex 15610dd1243..1437cac22a7 100644--- a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/guest-embed-ee.cy.spec.ts+++ b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/guest-embed-ee.cy.spec.ts@@ -135,6 +135,8 @@ describe("scenarios > embedding > sdk iframe embed setup > guest-embed", () => {// Experience stepgetEmbedSidebar().within(() => {+ cy.findByLabelText("Guest").should("be.visible").should("be.checked");+cy.findByTestId("upsell-gem").should("not.exist");cy.findByText("Chart").click();@@ -143,7 +145,8 @@ describe("scenarios > embedding > sdk iframe embed setup > guest-embed", () => {H.expectUnstructuredSnowplowEvent({event: "embed_wizard_experience_completed",- event_detail: "custom=chart",+ event_detail:+ "authType=guest-embed,experience=chart,isDefaultExperience=false",});// Entity selection step@@ -167,8 +170,7 @@ describe("scenarios > embedding > sdk iframe embed setup > guest-embed", () => {});// Options step- cy.findByLabelText("Guest").should("be.visible").should("be.checked");-+ cy.findByLabelText("Guest").should("not.exist");cy.findByLabelText("Allow people to drill through on data points").should("be.visible").should("be.disabled");@@ -205,7 +207,7 @@ describe("scenarios > embedding > sdk iframe embed setup > guest-embed", () => {H.expectUnstructuredSnowplowEvent({event: "embed_wizard_options_completed",event_detail:- 'settings=custom,experience=chart,guestEmbedEnabled=true,guestEmbedType=guest-embed,auth=guest-embed,drills=false,withDownloads=false,withTitle=true,isSaveEnabled=false,params={"disabled":0,"locked":1,"enabled":0},theme=default',+ 'settings=custom,experience=chart,guestEmbedEnabled=true,guestEmbedType=guest-embed,authType=guest-embed,drills=false,withDownloads=false,withTitle=true,isSaveEnabled=false,params={"disabled":0,"locked":1,"enabled":0},theme=default',});// Get code step@@ -218,7 +220,7 @@ describe("scenarios > embedding > sdk iframe embed setup > guest-embed", () => {H.expectUnstructuredSnowplowEvent({event: "embed_wizard_code_copied",event_detail:- "experience=chart,snippetType=frontend,guestEmbedEnabled=true,guestEmbedType=guest-embed,auth=guest-embed",+ "experience=chart,snippetType=frontend,guestEmbedEnabled=true,guestEmbedType=guest-embed,authSubType=none",});// Visit embed page@@ -337,7 +339,7 @@ describe("scenarios > embedding > sdk iframe embed setup > guest-embed", () => {});getEmbedSidebar().within(() => {- cy.findByLabelText("Guest").should("be.visible").should("be.checked");+ cy.findByLabelText("Guest").should("not.exist");});H.setEmbeddingParameter("Product ID", "Locked");@@ -351,10 +353,15 @@ describe("scenarios > embedding > sdk iframe embed setup > guest-embed", () => {codeBlock().first().should("not.contain", "hidden-parameters=");codeBlock().first().should("not.contain", "locked-parameters=");+ cy.findByText("Back").click();+ cy.findByText("Back").click();cy.findByText("Back").click();- cy.findByLabelText("Single sign-on (SSO)").click();+ cy.findByLabelText("Guest").should("be.visible").should("be.checked");+ cy.findByLabelText("Metabase account (SSO)").click();+ cy.findByText("Next").click();+ cy.findByText("Next").click();cy.findByText("Get code").click();codeBlock().first().should("contain", "dashboard-id=");diff --git a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/guest-embed-oss.cy.spec.ts b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/guest-embed-oss.cy.spec.tsindex ef40ebdf015..0d7d5a50ad3 100644--- a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/guest-embed-oss.cy.spec.ts+++ b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/guest-embed-oss.cy.spec.ts@@ -127,6 +127,16 @@ describe(// Experience stepgetEmbedSidebar().within(() => {+ cy.findByLabelText("Guest").should("be.visible").should("be.checked");++ ["Metabase account (SSO)"].forEach((text) => {+ cy.findAllByTestId("tooltip-warning")+ .filter(`:contains("${text}")`)+ .within(() => {+ cy.findByTestId("upsell-gem").should("be.visible");+ });+ });+["Exploration", "Browser"].forEach((label) => {cy.findByLabelText(label).should("be.disabled");cy.get("label")@@ -142,7 +152,8 @@ describe(H.expectUnstructuredSnowplowEvent({event: "embed_wizard_experience_completed",- event_detail: "custom=chart",+ event_detail:+ "authType=guest-embed,experience=chart,isDefaultExperience=false",});// Entity selection step@@ -166,9 +177,6 @@ describe(});// Options step- cy.findByLabelText("Guest").should("be.visible").should("be.checked");- cy.findByLabelText("Single sign-on (SSO)").should("be.disabled");-cy.findByLabelText("Allow people to drill through on data points").should("be.visible").should("be.disabled");@@ -181,7 +189,6 @@ describe(.should("be.disabled");[- "Single sign-on (SSO)","Allow people to drill through on data points","Allow downloads","Allow people to save new questions",@@ -232,7 +239,7 @@ describe(H.expectUnstructuredSnowplowEvent({event: "embed_wizard_options_completed",event_detail:- 'settings=custom,experience=chart,guestEmbedEnabled=true,guestEmbedType=guest-embed,auth=guest-embed,drills=false,withDownloads=true,withTitle=true,isSaveEnabled=false,params={"disabled":0,"locked":1,"enabled":0},theme=default',+ 'settings=custom,experience=chart,guestEmbedEnabled=true,guestEmbedType=guest-embed,authType=guest-embed,drills=false,withDownloads=true,withTitle=true,isSaveEnabled=false,params={"disabled":0,"locked":1,"enabled":0},theme=default',});// Get code step@@ -249,7 +256,7 @@ describe(H.expectUnstructuredSnowplowEvent({event: "embed_wizard_code_copied",event_detail:- "experience=chart,snippetType=frontend,guestEmbedEnabled=true,guestEmbedType=guest-embed,auth=guest-embed",+ "experience=chart,snippetType=frontend,guestEmbedEnabled=true,guestEmbedType=guest-embed,authSubType=none",});// Visit embed pagediff --git a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/helpers/index.ts b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/helpers/index.tsindex 1f5bc72a169..c042e04214c 100644--- a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/helpers/index.ts+++ b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/helpers/index.ts@@ -72,24 +72,32 @@ type NavigateToStepOptions =| {experience: "exploration" | "metabot";resourceName?: never;+ preselectSso?: boolean;}| {experience: "dashboard" | "chart" | "browser";resourceName: string;+ preselectSso?: boolean;};export const navigateToEntitySelectionStep = (options: NavigateToStepOptions,) => {- const { experience } = options;+ const { experience, preselectSso } = options;visitNewEmbedPage();cy.log("select an experience");+ const isQuestionOrDashboardExperience =+ experience === "chart" || experience === "dashboard";const hasEntitySelection =experience !== "exploration" && experience !== "metabot";+ if (preselectSso || !isQuestionOrDashboardExperience) {+ cy.findByLabelText("Metabase account (SSO)").click();+ }+const labelByExperience = match(experience).with("chart", () => "Chart").with("exploration", () => "Exploration")diff --git a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-entity.cy.spec.ts b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-entity.cy.spec.tsindex 93e98837541..c39031b18f1 100644--- a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-entity.cy.spec.ts+++ b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-entity.cy.spec.ts@@ -220,6 +220,8 @@ describe(suiteTitle, () => {visitNewEmbedPage();getEmbedSidebar().within(() => {+ cy.findByLabelText("Metabase account (SSO)").click();+cy.findByText("Browser").click();cy.findByText("Next").click();cy.findByText("Select a collection to embed").should("be.visible");@@ -301,6 +303,8 @@ describe(suiteTitle, () => {it("can open a collection picker from browser empty state", () => {getEmbedSidebar().within(() => {+ cy.findByLabelText("Metabase account (SSO)").click();+cy.findByText("Browser").click();cy.findByText("Next").click();diff --git a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-experience.cy.spec.ts b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-experience.cy.spec.tsindex 4fe7b9949f6..28e23a7481d 100644--- a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-experience.cy.spec.ts+++ b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-experience.cy.spec.ts@@ -51,7 +51,8 @@ describe(suiteTitle, () => {H.expectUnstructuredSnowplowEvent({event: "embed_wizard_experience_completed",- event_detail: "default",+ event_detail:+ "authType=guest-embed,experience=dashboard,isDefaultExperience=true",});H.getSimpleEmbedIframeContent().within(() => {@@ -81,7 +82,8 @@ describe(suiteTitle, () => {H.expectUnstructuredSnowplowEvent({event: "embed_wizard_experience_completed",- event_detail: "custom=chart",+ event_detail:+ "authType=guest-embed,experience=chart,isDefaultExperience=false",});H.getSimpleEmbedIframeContent().within(() => {@@ -94,13 +96,16 @@ describe(suiteTitle, () => {visitNewEmbedPage();getEmbedSidebar().within(() => {+ cy.findByLabelText("Metabase account (SSO)").click();+cy.findByText("Exploration").click();cy.findByText("Next").click();});H.expectUnstructuredSnowplowEvent({event: "embed_wizard_experience_completed",- event_detail: "custom=exploration",+ event_detail:+ "authType=sso,experience=exploration,isDefaultExperience=false",});H.waitForSimpleEmbedIframesToLoad();@@ -115,13 +120,16 @@ describe(suiteTitle, () => {visitNewEmbedPage();getEmbedSidebar().within(() => {+ cy.findByLabelText("Metabase account (SSO)").click();+cy.findByText("Browser").click();cy.findByText("Next").click();});H.expectUnstructuredSnowplowEvent({event: "embed_wizard_experience_completed",- event_detail: "custom=browser",+ event_detail:+ "authType=sso,experience=browser,isDefaultExperience=false",});H.getSimpleEmbedIframeContent().within(() => {@@ -174,7 +182,8 @@ describe(suiteTitle, () => {H.expectUnstructuredSnowplowEvent({event: "embed_wizard_experience_completed",- event_detail: "custom=chart",+ event_detail:+ "authType=guest-embed,experience=chart,isDefaultExperience=false",});H.waitForSimpleEmbedIframesToLoad();@@ -209,13 +218,15 @@ describe(suiteTitle, () => {visitNewEmbedPage();getEmbedSidebar().within(() => {+ cy.findByLabelText("Metabase account (SSO)").click();+cy.findByText("Metabot").click();cy.findByText("Next").click();});H.expectUnstructuredSnowplowEvent({event: "embed_wizard_experience_completed",- event_detail: "custom=metabot",+ event_detail: "authType=sso,experience=metabot,isDefaultExperience=false",});H.getSimpleEmbedIframeContent().within(() => {diff --git a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-options.cy.spec.ts b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-options.cy.spec.tsindex 7882c18848a..ece9782ba28 100644--- a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-options.cy.spec.ts+++ b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-options.cy.spec.ts@@ -1,6 +1,4 @@import { mockEmbedJsToDevServer } from "e2e/support/helpers";-import { enableJwtAuth } from "e2e/support/helpers/e2e-jwt-helpers";-import { enableSamlAuth } from "e2e/support/helpers/embedding-sdk-testing";import {codeBlock,@@ -37,8 +35,6 @@ describe("OSS", { tags: "@OSS" }, () => {resourceName: DASHBOARD_NAME,});- assertUpsellForOption("Existing Metabase session");- assertUpsellForOption("Single sign-on (SSO)");assertUpsellForOption("Allow people to drill through on data points");assertUpsellForOption("Allow downloads");assertUpsellForOption("Allow subscriptions");@@ -68,8 +64,6 @@ describe("EE without license", () => {resourceName: DASHBOARD_NAME,});- assertUpsellForOption("Existing Metabase session");- assertUpsellForOption("Single sign-on (SSO)");assertUpsellForOption("Allow people to drill through on data points");assertUpsellForOption("Allow downloads");assertUpsellForOption("Allow subscriptions");@@ -111,69 +105,13 @@ describe(suiteTitle, () => {H.expectNoBadSnowplowEvents();});- it("should select user session auth method by default", () => {+ it("toggles drill-throughs for dashboards when SSO auth method is selected", () => {navigateToEmbedOptionsStep({experience: "dashboard",resourceName: DASHBOARD_NAME,+ preselectSso: true,});- getEmbedSidebar().within(() => {- cy.findByText("Authentication").should("be.visible");-- cy.findByLabelText("Guest").should("be.visible").should("be.checked");- cy.findByLabelText("Existing Metabase session")- .should("be.visible")- .should("not.be.checked");-- cy.findByLabelText("Single sign-on (SSO)")- .should("be.visible")- .should("not.be.checked");- });- });-- it("should disable SSO radio button when JWT and SAML are not configured", () => {- navigateToEmbedOptionsStep({- experience: "dashboard",- resourceName: DASHBOARD_NAME,- });-- getEmbedSidebar().within(() => {- cy.findByLabelText("Single sign-on (SSO)").should("be.disabled");- });- });-- it("should enable SSO radio button when JWT is configured", () => {- enableJwtAuth();- navigateToEmbedOptionsStep({- experience: "dashboard",- resourceName: DASHBOARD_NAME,- });-- getEmbedSidebar().within(() => {- cy.findByLabelText("Single sign-on (SSO)").should("not.be.disabled");- });- });-- it("should enable SSO radio button when SAML is configured", () => {- enableSamlAuth();- navigateToEmbedOptionsStep({- experience: "dashboard",- resourceName: DASHBOARD_NAME,- });-- getEmbedSidebar().within(() => {- cy.findByLabelText("Single sign-on (SSO)").should("not.be.disabled");- });- });-- it("toggles drill-throughs for dashboards when non-authorized auth method is selected", () => {- navigateToEmbedOptionsStep({- experience: "dashboard",- resourceName: DASHBOARD_NAME,- });-- cy.findByLabelText("Existing Metabase session").click();-getEmbedSidebar().findByLabelText("Allow people to drill through on data points").should("be.checked");@@ -202,7 +140,7 @@ describe(suiteTitle, () => {H.expectUnstructuredSnowplowEvent({event: "embed_wizard_options_completed",event_detail:- "settings=custom,experience=dashboard,auth=user-session,drills=false,withDownloads=false,withSubscriptions=false,withTitle=true,isSaveEnabled=false,theme=default",+ "settings=custom,experience=dashboard,authType=sso,drills=false,withDownloads=false,withSubscriptions=false,withTitle=true,isSaveEnabled=false,theme=default",});codeBlock().should("contain", 'drills="false"');@@ -212,8 +150,8 @@ describe(suiteTitle, () => {navigateToEmbedOptionsStep({experience: "dashboard",resourceName: DASHBOARD_NAME,+ preselectSso: true,});- cy.findByLabelText("Existing Metabase session").click();getEmbedSidebar().findByLabelText("Allow downloads")@@ -239,7 +177,7 @@ describe(suiteTitle, () => {H.expectUnstructuredSnowplowEvent({event: "embed_wizard_options_completed",event_detail:- "settings=custom,experience=dashboard,auth=user-session,drills=true,withDownloads=true,withSubscriptions=false,withTitle=true,isSaveEnabled=false,theme=default",+ "settings=custom,experience=dashboard,authType=sso,drills=true,withDownloads=true,withSubscriptions=false,withTitle=true,isSaveEnabled=false,theme=default",});codeBlock().should("contain", 'with-subscriptions="false"');@@ -282,7 +220,14 @@ describe(suiteTitle, () => {cy.log("test non-guest embeds");getEmbedSidebar().within(() => {cy.button("Back").click();- cy.findByLabelText("Existing Metabase session").click();+ cy.button("Back").click();+ cy.button("Back").click();++ cy.findByLabelText("Metabase account (SSO)").click();++ cy.button("Next").click();+ cy.button("Next").click();+cy.findByLabelText("Allow subscriptions").closest("[data-testid=tooltip-warning]").icon("info")@@ -300,8 +245,8 @@ describe(suiteTitle, () => {navigateToEmbedOptionsStep({experience: "dashboard",resourceName: DASHBOARD_NAME,+ preselectSso: true,});- cy.findByLabelText("Existing Metabase session").click();getEmbedSidebar().findByLabelText("Allow subscriptions")@@ -350,7 +295,7 @@ describe(suiteTitle, () => {H.expectUnstructuredSnowplowEvent({event: "embed_wizard_options_completed",event_detail:- "settings=custom,experience=dashboard,auth=user-session,drills=true,withDownloads=false,withSubscriptions=true,withTitle=true,isSaveEnabled=false,theme=default",+ "settings=custom,experience=dashboard,authType=sso,drills=true,withDownloads=false,withSubscriptions=true,withTitle=true,isSaveEnabled=false,theme=default",});codeBlock().should("contain", 'with-subscriptions="true"');@@ -386,18 +331,18 @@ describe(suiteTitle, () => {H.expectUnstructuredSnowplowEvent({event: "embed_wizard_options_completed",event_detail:- 'settings=custom,experience=dashboard,guestEmbedEnabled=false,auth=guest-embed,drills=false,withDownloads=false,withSubscriptions=false,withTitle=false,params={"disabled":0,"locked":0,"enabled":0},theme=default',+ 'settings=custom,experience=dashboard,guestEmbedEnabled=false,authType=guest-embed,drills=false,withDownloads=false,withSubscriptions=false,withTitle=false,params={"disabled":0,"locked":0,"enabled":0},theme=default',});codeBlock().should("contain", 'with-title="false"');});- it("toggles drill-through for charts for non-authorized auth mode", () => {+ it("toggles drill-through for charts for SSO auth mode", () => {navigateToEmbedOptionsStep({experience: "chart",resourceName: QUESTION_NAME,+ preselectSso: true,});- cy.findByLabelText("Existing Metabase session").click();getEmbedSidebar().findByLabelText("Allow people to drill through on data points")@@ -459,7 +404,7 @@ describe(suiteTitle, () => {H.expectUnstructuredSnowplowEvent({event: "embed_wizard_options_completed",event_detail:- 'settings=custom,experience=chart,guestEmbedEnabled=false,auth=guest-embed,drills=false,withDownloads=true,withTitle=true,isSaveEnabled=false,params={"disabled":0,"locked":0,"enabled":0},theme=default',+ 'settings=custom,experience=chart,guestEmbedEnabled=false,authType=guest-embed,drills=false,withDownloads=true,withTitle=true,isSaveEnabled=false,params={"disabled":0,"locked":0,"enabled":0},theme=default',});codeBlock().should("contain", 'with-downloads="true"');@@ -469,8 +414,8 @@ describe(suiteTitle, () => {navigateToEmbedOptionsStep({experience: "chart",resourceName: QUESTION_NAME,+ preselectSso: true,});- cy.findByLabelText("Existing Metabase session").click();cy.log("chart title should be visible by default");getEmbedSidebar().findByLabelText("Show chart title").should("be.checked");@@ -530,12 +475,14 @@ describe(suiteTitle, () => {it(`toggles save button for ${experience}`, () => {navigateToEmbedOptionsStep(experience === "chart"- ? { experience: "chart", resourceName: QUESTION_NAME }- : { experience: "exploration" },+ ? {+ experience: "chart",+ resourceName: QUESTION_NAME,+ preselectSso: true,+ }+ : { experience: "exploration", preselectSso: true },);- cy.findByLabelText("Existing Metabase session").click();-if (experience === "exploration") {cy.log("visualize a question to enable the save button");H.getSimpleEmbedIframeContent().within(() => {@@ -576,8 +523,8 @@ describe(suiteTitle, () => {event: "embed_wizard_options_completed",event_detail:experience === "chart"- ? "settings=custom,experience=chart,auth=user-session,drills=true,withDownloads=false,withTitle=true,isSaveEnabled=true,theme=default"- : "settings=custom,experience=exploration,auth=user-session,isSaveEnabled=true,theme=default",+ ? "settings=custom,experience=chart,authType=sso,drills=true,withDownloads=false,withTitle=true,isSaveEnabled=true,theme=default"+ : "settings=custom,experience=exploration,authType=sso,isSaveEnabled=true,theme=default",});codeBlock().should("contain", 'is-save-enabled="true"');@@ -614,7 +561,7 @@ describe(suiteTitle, () => {H.expectUnstructuredSnowplowEvent({event: "embed_wizard_options_completed",event_detail:- "settings=custom,experience=browser,auth=user-session,readOnly=false,theme=default",+ "settings=custom,experience=browser,authType=sso,readOnly=false,theme=default",});codeBlock().should("contain", 'read-only="false"');@@ -660,7 +607,7 @@ describe(suiteTitle, () => {H.expectUnstructuredSnowplowEvent({event: "embed_wizard_options_completed",event_detail:- 'settings=custom,experience=dashboard,guestEmbedEnabled=false,auth=guest-embed,drills=false,withDownloads=false,withSubscriptions=false,withTitle=true,params={"disabled":0,"locked":0,"enabled":0},theme=custom',+ 'settings=custom,experience=dashboard,guestEmbedEnabled=false,authType=guest-embed,drills=false,withDownloads=false,withSubscriptions=false,withTitle=true,params={"disabled":0,"locked":0,"enabled":0},theme=custom',});codeBlock().should("contain", '"theme": {');@@ -704,8 +651,8 @@ describe(suiteTitle, () => {navigateToEmbedOptionsStep({experience: "dashboard",resourceName: DASHBOARD_NAME,+ preselectSso: true,});- cy.findByLabelText("Existing Metabase session").click();cy.log("click on brand color picker");cy.findByTestId("brand-color-picker").findByRole("button").click();@@ -739,7 +686,7 @@ describe(suiteTitle, () => {H.expectUnstructuredSnowplowEvent({event: "embed_wizard_options_completed",event_detail:- "settings=custom,experience=dashboard,auth=user-session,drills=true,withDownloads=false,withSubscriptions=false,withTitle=true,isSaveEnabled=false,theme=custom",+ "settings=custom,experience=dashboard,authType=sso,drills=true,withDownloads=false,withSubscriptions=false,withTitle=true,isSaveEnabled=false,theme=custom",});// derived-colors-for-embed-flow.unit.spec.ts contains the tests for other derived colors.@@ -765,7 +712,7 @@ describe(suiteTitle, () => {H.expectUnstructuredSnowplowEvent({event: "embed_wizard_options_completed",event_detail:- "settings=custom,experience=metabot,auth=user-session,layout=stacked,theme=default",+ "settings=custom,experience=metabot,authType=sso,layout=stacked,theme=default",});getEmbedSidebar().findByText("Back").click();@@ -781,7 +728,7 @@ describe(suiteTitle, () => {H.expectUnstructuredSnowplowEvent({event: "embed_wizard_options_completed",event_detail:- "settings=custom,experience=metabot,auth=user-session,layout=sidebar,theme=default",+ "settings=custom,experience=metabot,authType=sso,layout=sidebar,theme=default",});});});diff --git a/e2e/test/scenarios/sharing/public-sharing-embed-flow.cy.spec.ts b/e2e/test/scenarios/sharing/public-sharing-embed-flow.cy.spec.tsindex 01d9cb37a90..814c4d68bc8 100644--- a/e2e/test/scenarios/sharing/public-sharing-embed-flow.cy.spec.ts+++ b/e2e/test/scenarios/sharing/public-sharing-embed-flow.cy.spec.ts@@ -41,6 +41,7 @@ describe(suiteTitle, () => {.findByText("Orders in a dashboard", { timeout: 10_000 }).should("be.visible");+ getEmbedSidebar().findByText("Back").should("not.exist");getEmbedSidebar().findByText("Get code").click();H.expectUnstructuredSnowplowEvent({@@ -67,6 +68,7 @@ describe(suiteTitle, () => {.findByText("Orders", { timeout: 10_000 }).should("be.visible");+ getEmbedSidebar().findByText("Back").should("not.exist");getEmbedSidebar().findByText("Get code").click();H.expectUnstructuredSnowplowEvent({@@ -74,44 +76,4 @@ describe(suiteTitle, () => {event_detail: "settings=default",});});-- it("tracks default resources for pre-selected dashboard", () => {- H.visitDashboard(ORDERS_DASHBOARD_ID);- H.openSharingMenu("Embed");- H.embedModalEnableEmbedding();-- H.expectUnstructuredSnowplowEvent({ event: "embed_wizard_opened" });-- cy.log("go back to resource selection step");- getEmbedSidebar().within(() => {- cy.findByText("Back").click();- cy.findByText("Select a dashboard to embed").should("be.visible");- cy.findByText("Next").click();- });-- H.expectUnstructuredSnowplowEvent({- event: "embed_wizard_resource_selection_completed",- event_detail: "isDefaultResource=true,experience=dashboard",- });- });-- it("tracks default resources for pre-selected question", () => {- H.visitQuestion(ORDERS_QUESTION_ID);- H.openSharingMenu("Embed");- H.embedModalEnableEmbedding();-- H.expectUnstructuredSnowplowEvent({ event: "embed_wizard_opened" });-- cy.log("go back to resource selection step");- getEmbedSidebar().within(() => {- cy.findByText("Back").click();- cy.findByText("Select a chart to embed").should("be.visible");- cy.findByText("Next").click();- });-- H.expectUnstructuredSnowplowEvent({- event: "embed_wizard_resource_selection_completed",- event_detail: "isDefaultResource=true,experience=chart",- });- });});diff --git a/frontend/src/metabase-types/analytics/event.ts b/frontend/src/metabase-types/analytics/event.tsindex 31924482bc6..7bb3a2c424e 100644--- a/frontend/src/metabase-types/analytics/event.ts+++ b/frontend/src/metabase-types/analytics/event.ts@@ -210,7 +210,7 @@ export type EmbedWizardOpenedEvent = ValidateEvent<{export type EmbedWizardExperienceCompletedEvent = ValidateEvent<{event: "embed_wizard_experience_completed";- event_detail: "default" | `custom=${SdkIframeEmbedSetupExperience}`;+ event_detail: string;}>;export type EmbedWizardResourceSelectionCompletedEvent = ValidateEvent<{diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/analytics.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/analytics.tsindex 87a2895defe..b377f582b6f 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/analytics.ts+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/analytics.ts@@ -4,6 +4,7 @@ import type {SdkIframeEmbedSettingKey,SdkIframeEmbedSettings,} from "metabase/embedding/embedding-iframe-sdk/types/embed";+import { getAuthSubTypeForSettings } from "metabase/embedding/embedding-iframe-sdk-setup/utils/get-auth-sub-type-for-settings";import { getAuthTypeForSettings } from "metabase/embedding/embedding-iframe-sdk-setup/utils/get-auth-type-for-settings";import { countEmbeddingParameterOptions } from "metabase/embedding/lib/count-embedding-parameter-options";import { trackSimpleEvent } from "metabase/lib/analytics";@@ -20,10 +21,14 @@ import {getResourceIdFromSettings,} from "./utils/get-default-sdk-iframe-embed-setting";+export const UTM_LOCATION = "embedded_analytics_js_wizard";+export const UPSELL_CAMPAIGN_EXPERIENCE = "embedding_experience";export const UPSELL_CAMPAIGN_AUTH = "embedding_auth";export const UPSELL_CAMPAIGN_BEHAVIOR = "embedding_behavior";+export const SETUP_SSO_CAMPAIGN = "embedding_get_code";+/*** Tracking every embed settings would bloat Snowplow, so we only track* the most relevant options that reveal usage patterns.@@ -53,15 +58,29 @@ const EMBED_SETTINGS_TO_IGNORE: SdkIframeEmbedSettingKey[] = [export const trackEmbedWizardOpened = () =>trackSimpleEvent({ event: "embed_wizard_opened" });-export const trackEmbedWizardExperienceCompleted = (- experience: SdkIframeEmbedSetupExperience,- defaultExperience: SdkIframeEmbedSetupExperience,-) =>+export const trackEmbedWizardExperienceCompleted = ({+ experience,+ defaultExperience,+ settings,+}: {+ experience: SdkIframeEmbedSetupExperience;+ defaultExperience: SdkIframeEmbedSetupExperience;+ settings: Partial<SdkIframeEmbedSetupSettings>;+}) => {+ const authType = getAuthTypeForSettings(settings);+ const isDefaultExperience = experience === defaultExperience;++ const eventDetailsParts: string[] = [+ `authType=${authType}`,+ `experience=${experience}`,+ `isDefaultExperience=${isDefaultExperience}`,+ ];+trackSimpleEvent({event: "embed_wizard_experience_completed",- event_detail:- experience === defaultExperience ? "default" : `custom=${experience}`,+ event_detail: buildEventDetails(eventDetailsParts),});+};export const trackEmbedWizardResourceSelectionCompleted = ({experience,@@ -90,12 +109,12 @@ const getEmbedSettingsToCompare = (settings: Partial<SdkIframeEmbedSettings>) =>_.omit(_.omit(settings, ...EMBED_SETTINGS_TO_IGNORE), _.isUndefined);export const trackEmbedWizardOptionsCompleted = ({- initialState,experience,resource,settings,isSimpleEmbedFeatureAvailable,isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,embeddingParameters,}: {initialState: SdkIframeEmbedSetupModalInitialState | undefined;@@ -104,15 +123,18 @@ export const trackEmbedWizardOptionsCompleted = ({settings: Partial<SdkIframeEmbedSetupSettings>;isSimpleEmbedFeatureAvailable: boolean;isGuestEmbedsEnabled: boolean;+ isSsoEnabledAndConfigured: boolean;embeddingParameters: EmbeddingParameters;}) => {// Get defaults for this experience type (with a dummy resource ID)const defaultSettings = getDefaultSdkIframeEmbedSettings({- initialState,experience,resourceId: 0,isSimpleEmbedFeatureAvailable,isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,+ isGuest: !!settings.isGuest,+ useExistingUserSession: !!settings.useExistingUserSession,});// Does the embed settings diverge from the experience defaults?@@ -134,7 +156,7 @@ export const trackEmbedWizardOptionsCompleted = ({...[`experience=${experience}`,...buldEventDetailsPartsForGuestEmbedResource({ resource, settings }),- `auth=${authType}`,+ `authType=${authType}`,...buildEventDetailsPartsForSettings(settings),...(settings.isGuest ? [`params=${JSON.stringify(params)}`] : []),`theme=${hasCustomTheme ? "custom" : "default"}`,@@ -159,13 +181,13 @@ export const trackEmbedWizardCodeCopied = ({snippetType: "frontend" | "server";settings: SdkIframeEmbedSetupSettings;}) => {- const authType = getAuthTypeForSettings(settings);+ const authSubType = getAuthSubTypeForSettings(settings);const eventDetailsParts: (string | null)[] = [`experience=${experience}`,`snippetType=${snippetType}`,...buldEventDetailsPartsForGuestEmbedResource({ resource, settings }),- `auth=${authType}`,+ `authSubType=${authSubType}`,];trackSimpleEvent({diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/Authentication/AuthenticationSection.tsx b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/Authentication/AuthenticationSection.tsxnew file mode 100644index 00000000000..3ae5edfd6fb--- /dev/null+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/Authentication/AuthenticationSection.tsx@@ -0,0 +1,103 @@+import type { ReactNode } from "react";+import { t } from "ttag";++import { UPSELL_CAMPAIGN_AUTH } from "metabase/embedding/embedding-iframe-sdk-setup/analytics";+import { TooltipWarning } from "metabase/embedding/embedding-iframe-sdk-setup/components/warnings/TooltipWarning";+import { WithSimpleEmbeddingFeatureUpsellTooltip } from "metabase/embedding/embedding-iframe-sdk-setup/components/warnings/WithSimpleEmbeddingFeatureUpsellTooltip";+import { useSdkIframeEmbedSetupContext } from "metabase/embedding/embedding-iframe-sdk-setup/context";+import {+ DEFAULT_EXPERIENCE,+ useHandleExperienceChange,+} from "metabase/embedding/embedding-iframe-sdk-setup/hooks/use-handle-experience-change";+import { getAuthTypeForSettings } from "metabase/embedding/embedding-iframe-sdk-setup/utils/get-auth-type-for-settings";+import { Card, Radio, Stack, Text } from "metabase/ui";++export const AuthenticationSection = () => {+ const {+ isSimpleEmbedFeatureAvailable,+ isFirstStep,+ settings,+ updateSettings,+ } = useSdkIframeEmbedSetupContext();+ const handleEmbedExperienceChange = useHandleExperienceChange();++ if (!isFirstStep) {+ return null;+ }++ const authType = getAuthTypeForSettings(settings);++ const handleAuthTypeChange = (value: string) => {+ const isGuest = value === "guest-embed";+ const isSso = value === "sso";++ if (isGuest) {+ // Reset experience to default when switching to guest embeds+ handleEmbedExperienceChange(DEFAULT_EXPERIENCE);+ }++ updateSettings({+ isGuest,+ isSso,+ });+ };++ return (+ <Card p="md">+ <Stack gap="md" p="xs">+ <Text size="lg" fw="bold">+ {t`Authentication`}+ </Text>++ <Radio.Group value={authType} onChange={handleAuthTypeChange}>+ <Stack gap="sm">+ <WithGuestEmbedsDisabledWarning>+ {({ disabled }) => (+ <Radio+ disabled={disabled}+ value="guest-embed"+ label={t`Guest`}+ />+ )}+ </WithGuestEmbedsDisabledWarning>++ <WithSimpleEmbeddingFeatureUpsellTooltip+ enableTooltip={!isSimpleEmbedFeatureAvailable}+ campaign={UPSELL_CAMPAIGN_AUTH}+ >+ {({ disabled }) => (+ <Radio+ value="sso"+ label={+ // eslint-disable-next-line no-literal-metabase-strings -- Public Facing string+ t`Metabase account (SSO)`+ }+ disabled={disabled}+ />+ )}+ </WithSimpleEmbeddingFeatureUpsellTooltip>+ </Stack>+ </Radio.Group>+ </Stack>+ </Card>+ );+};++const WithGuestEmbedsDisabledWarning = ({+ children,+}: {+ children: (data: { disabled: boolean }) => ReactNode;+}) => {+ const { isGuestEmbedsEnabled } = useSdkIframeEmbedSetupContext();++ const disabled = !isGuestEmbedsEnabled;++ return (+ <TooltipWarning+ tooltip={t`Disabled in the admin settings`}+ disabled={disabled}+ >+ {children}+ </TooltipWarning>+ );+};diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/Authentication/MetabaseAccountSection.tsx b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/Authentication/MetabaseAccountSection.tsxnew file mode 100644index 00000000000..8a4c0a7708a--- /dev/null+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/Authentication/MetabaseAccountSection.tsx@@ -0,0 +1,89 @@+import { jt, t } from "ttag";++import { useDocsUrl } from "metabase/common/hooks";+import {+ SETUP_SSO_CAMPAIGN,+ UTM_LOCATION,+} from "metabase/embedding/embedding-iframe-sdk-setup/analytics";+import { useSdkIframeEmbedSetupContext } from "metabase/embedding/embedding-iframe-sdk-setup/context";+import { getAuthSubTypeForSettings } from "metabase/embedding/embedding-iframe-sdk-setup/utils/get-auth-sub-type-for-settings";+import { Alert, Anchor, Card, Icon, Radio, Stack, Text } from "metabase/ui";++const utmTags = {+ utm_source: "product",+ utm_medium: "docs",+ utm_campaign: SETUP_SSO_CAMPAIGN,+ utm_content: UTM_LOCATION,+};++export const MetabaseAccountSection = () => {+ const { isSsoEnabledAndConfigured, settings, updateSettings } =+ useSdkIframeEmbedSetupContext();++ const isGuestEmbed = !!settings.isGuest;++ // eslint-disable-next-line no-unconditional-metabase-links-render -- Only for admins+ const { url: setupSsoUrl } = useDocsUrl("embedding/sdk/authentication", {+ utm: utmTags,+ });++ if (isGuestEmbed) {+ return null;+ }++ const authSubType = getAuthSubTypeForSettings(settings);++ const handleAuthSubTypeChange = (value: string) => {+ const useExistingUserSession = value === "user-session";++ updateSettings({ useExistingUserSession });+ };++ return (+ <>+ <Card p="md">+ <Stack gap="md" p="xs">+ <Text size="lg" fw="bold">+ {+ // eslint-disable-next-line no-literal-metabase-strings -- Public Facing string+ t`Metabase account`+ }+ </Text>++ <Radio.Group value={authSubType} onChange={handleAuthSubTypeChange}>+ <Stack gap="sm">+ <Radio+ disabled={!isSsoEnabledAndConfigured}+ value="sso"+ label={t`Single sign-on`}+ />++ <Radio+ value="user-session"+ label={t`Existing session (local testing only)`}+ />+ </Stack>+ </Radio.Group>+ </Stack>+ </Card>++ {!isSsoEnabledAndConfigured && !!settings.useExistingUserSession && (+ <Alert icon={<Icon name="warning" size={16} />} color="warning">+ <Text size="md" lh="lg">+ {jt`The code below will only work for local testing. To get production ready code, configure ${(+ <Anchor+ key="configure-sso"+ href={setupSsoUrl}+ target="_blank"+ size="md"+ lh="lg"+ >+ {t`JWT SSO or SAML`}+ </Anchor>+ )}.`}+ </Text>+ </Alert>+ )}+ </>+ );+};diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/Common/WithNotAvailableForGuestEmbedsWarning.tsx b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/Common/WithNotAvailableForGuestEmbedsWarning.tsxnew file mode 100644index 00000000000..32483b1c514--- /dev/null+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/Common/WithNotAvailableForGuestEmbedsWarning.tsx@@ -0,0 +1,48 @@+import type { ReactNode } from "react";+import { t } from "ttag";++import {+ TooltipWarning,+ type TooltipWarningMode,+} from "metabase/embedding/embedding-iframe-sdk-setup/components/warnings/TooltipWarning";+import { useSdkIframeEmbedSetupContext } from "metabase/embedding/embedding-iframe-sdk-setup/context";++import { WithNotAvailableWithoutSimpleEmbeddingFeatureWarning } from "./WithNotAvailableWithoutSimpleEmbeddingFeatureWarning";++export const WithNotAvailableForGuestEmbedsWarning = ({+ mode,+ children,+ campaign,+}: {+ mode?: TooltipWarningMode;+ children: (data: { disabled: boolean; hoverCard: ReactNode }) => ReactNode;+ campaign: string;+}) => {+ const { settings } = useSdkIframeEmbedSetupContext();++ return (+ <WithNotAvailableWithoutSimpleEmbeddingFeatureWarning+ mode={mode}+ campaign={campaign}+ >+ {({ disabled: disabledForOss, hoverCard: disabledForOssHoverCard }) => (+ <TooltipWarning+ enableTooltip={!disabledForOss}+ tooltip={t`Not available if Guest Mode is selected`}+ disabled={!!settings.isGuest}+ >+ {({+ disabled: disabledForGuestEmbeds,+ hoverCard: disabledForGuestEmbedsHoverCard,+ }) =>+ children({+ disabled: disabledForOss || disabledForGuestEmbeds,+ hoverCard:+ disabledForOssHoverCard || disabledForGuestEmbedsHoverCard,+ })+ }+ </TooltipWarning>+ )}+ </WithNotAvailableWithoutSimpleEmbeddingFeatureWarning>+ );+};diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/Common/WithNotAvailableWithoutSimpleEmbeddingFeatureWarning.tsx b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/Common/WithNotAvailableWithoutSimpleEmbeddingFeatureWarning.tsxnew file mode 100644index 00000000000..f900a47bf42--- /dev/null+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/Common/WithNotAvailableWithoutSimpleEmbeddingFeatureWarning.tsx@@ -0,0 +1,28 @@+import type { ReactNode } from "react";++import { useSdkIframeEmbedSetupContext } from "metabase/embedding/embedding-iframe-sdk-setup/context";++import type { TooltipWarningMode } from "../warnings/TooltipWarning";+import { WithSimpleEmbeddingFeatureUpsellTooltip } from "../warnings/WithSimpleEmbeddingFeatureUpsellTooltip";++export const WithNotAvailableWithoutSimpleEmbeddingFeatureWarning = ({+ mode,+ children,+ campaign,+}: {+ mode?: TooltipWarningMode;+ children: (data: { disabled: boolean; hoverCard: ReactNode }) => ReactNode;+ campaign: string;+}) => {+ const { isSimpleEmbedFeatureAvailable } = useSdkIframeEmbedSetupContext();++ return (+ <WithSimpleEmbeddingFeatureUpsellTooltip+ mode={mode}+ enableTooltip={!isSimpleEmbedFeatureAvailable}+ campaign={campaign}+ >+ {({ disabled, hoverCard }) => children({ disabled, hoverCard })}+ </WithSimpleEmbeddingFeatureUpsellTooltip>+ );+};diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/GetCodeStep.tsx b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/GetCodeStep.tsxindex 5600179d6e5..1c91af62673 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/GetCodeStep.tsx+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/GetCodeStep.tsx@@ -3,6 +3,7 @@ import { t } from "ttag";import { useUpdateSettingsMutation } from "metabase/api";import { CodeEditor } from "metabase/common/components/CodeEditor";import { MoreServerSnippetExamplesLink } from "metabase/embedding/components/MoreServerSnippetExamplesLink/MoreServerSnippetExamplesLink";+import { MetabaseAccountSection } from "metabase/embedding/embedding-iframe-sdk-setup/components/Authentication/MetabaseAccountSection";import { CopyCodeSnippetButton } from "metabase/embedding/embedding-iframe-sdk-setup/components/CodeSnippet/CopyCodeSnippetButton";import { useSdkIframeEmbedServerSnippet } from "metabase/embedding/embedding-iframe-sdk-setup/hooks/use-sdk-iframe-embed-server-snippet";import { EmbedServerSnippetLanguageSelect } from "metabase/public/components/EmbedServerSnippetLanguageSelect/EmbedServerSnippetLanguageSelect";@@ -17,6 +18,8 @@ export const GetCodeStep = () => {const { experience, resource, settings } = useSdkIframeEmbedSetupContext();const [updateInstanceSettings] = useUpdateSettingsMutation();+ const isGuestEmbed = !!settings.isGuest;+const serverSnippetData = useSdkIframeEmbedServerSnippet();const snippet = useSdkIframeEmbedSnippet();@@ -44,6 +47,8 @@ export const GetCodeStep = () => {return (<Stack gap="md">+ {!isGuestEmbed && <MetabaseAccountSection />}+<Card p="md"><Text size="lg" fw="bold" mb="md">{t`Embed code`}diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/SdkIframeEmbedSetupModal.tsx b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/SdkIframeEmbedSetupModal.tsxindex 8cfe1334c06..0fe56e41e90 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/SdkIframeEmbedSetupModal.tsx+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/SdkIframeEmbedSetupModal.tsx@@ -1,5 +1,5 @@import cx from "classnames";-import { useState } from "react";+import { useMemo, useState } from "react";import { ResizableBox } from "react-resizable";import { match } from "ts-pattern";import { t } from "ttag";@@ -11,6 +11,7 @@ import { useUpdateSettingsMutation } from "metabase/api";import CS from "metabase/css/core/index.css";import { SdkIframeGuestEmbedStatusBar } from "metabase/embedding/embedding-iframe-sdk-setup/components/SdkIframeGuestEmbedStatusBar";import { SdkIframeStepHeader } from "metabase/embedding/embedding-iframe-sdk-setup/components/SdkIframeStepHeader";+import { EMBED_STEPS } from "metabase/embedding/embedding-iframe-sdk-setup/constants";import { useDispatch } from "metabase/lib/redux";import type { SdkIframeEmbedSetupModalProps } from "metabase/plugins";import { closeModal } from "metabase/redux/ui";@@ -28,7 +29,6 @@ import {import type { SettingKey } from "metabase-types/api";import { useSdkIframeEmbedSetupContext } from "../context";-import { useSdkIframeEmbedNavigation } from "../hooks";import { SdkIframeEmbedPreview } from "./SdkIframeEmbedPreview";import S from "./SdkIframeEmbedSetup.module.css";@@ -44,11 +44,17 @@ export const SdkIframeEmbedSetupContent = () => {isGuestEmbedsEnabled,isGuestEmbedsTermsAccepted,currentStep,+ handleNext,+ handleBack,+ canGoBack,settings,} = useSdkIframeEmbedSetupContext();- const { handleNext, handleBack, canGoBack, StepContent } =- useSdkIframeEmbedNavigation();+ const StepContent = useMemo(+ () =>+ EMBED_STEPS.find((step) => step.id === currentStep)?.component ?? noop,+ [currentStep],+ );function handleEmbedDone() {// Embedding Hub: track step completion@@ -118,15 +124,17 @@ export const SdkIframeEmbedSetupContent = () => {</Stack><Group className={S.Navigation} justify="space-between">- <Button- variant="default"- onClick={handleBack}- disabled={!canGoBack || !allowPreviewAndNavigation}- >- {t`Back`}- </Button>-- {nextStepButton}+ {canGoBack && (+ <Button+ variant="default"+ onClick={handleBack}+ disabled={!allowPreviewAndNavigation}+ >+ {t`Back`}+ </Button>+ )}++ <Box ml="auto">{nextStepButton}</Box></Group></Box></SidebarResizer>@@ -192,3 +200,5 @@ export const SdkIframeEmbedSetupModal = ({</Modal.Content></Modal>);++const noop = () => null;diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/SdkIframeEmbedSetupProvider.tsx b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/SdkIframeEmbedSetupProvider.tsxindex d9bc8d2042d..503af4178e4 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/SdkIframeEmbedSetupProvider.tsx+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/SdkIframeEmbedSetupProvider.tsx@@ -6,6 +6,7 @@ import { useSetting } from "metabase/common/hooks";import { trackEmbedWizardOpened } from "metabase/embedding/embedding-iframe-sdk-setup/analytics";import { useEmbeddingParameters } from "metabase/embedding/embedding-iframe-sdk-setup/hooks/use-embedding-parameters";import { useGetGuestEmbedSignedToken } from "metabase/embedding/embedding-iframe-sdk-setup/hooks/use-get-guest-embed-signed-token";+import { useIsSsoEnabledAndConfigured } from "metabase/embedding/embedding-iframe-sdk-setup/hooks/use-is-sso-enabled-and-configured";import {PLUGIN_EMBEDDING_IFRAME_SDK_SETUP,type SdkIframeEmbedSetupModalInitialState,@@ -20,6 +21,7 @@ import {useGetCurrentResource,useParametersValues,useRecentItems,+ useSdkIframeEmbedNavigation,} from "../hooks";import { useSdkIframeEmbedSettings } from "../hooks/use-sdk-iframe-embed-settings";import type { SdkIframeEmbedSetupStep } from "../types";@@ -45,6 +47,8 @@ export const SdkIframeEmbedSetupProvider = ({const isGuestEmbedsEnabled = useSetting("enable-embedding-static");const isGuestEmbedsTermsAccepted = !useSetting("show-static-embed-terms");+ const isSsoEnabledAndConfigured = useIsSsoEnabledAndConfigured();+useMount(() => {trackEmbedWizardOpened();});@@ -92,6 +96,7 @@ export const SdkIframeEmbedSetupProvider = ({modelCount,isSimpleEmbedFeatureAvailable,isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,});// Which embed experience are we setting up?@@ -141,14 +146,36 @@ export const SdkIframeEmbedSetupProvider = ({embeddingParameters,});+ const { handleNext, handleBack, canGoBack, isFirstStep, isLastStep } =+ useSdkIframeEmbedNavigation({+ isSimpleEmbedFeatureAvailable,+ isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,+ initialState,+ experience,+ resource,+ currentStep,+ defaultStep,+ setCurrentStep,+ settings,+ defaultSettings,+ embeddingParameters,+ });+const value: SdkIframeEmbedSetupContextType = {isSimpleEmbedFeatureAvailable,isSimpleEmbeddingEnabled,isSimpleEmbeddingTermsAccepted,isGuestEmbedsEnabled,isGuestEmbedsTermsAccepted,+ isSsoEnabledAndConfigured,currentStep,setCurrentStep,+ handleNext,+ handleBack,+ canGoBack,+ isFirstStep,+ isLastStep,initialState,experience,resource,diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/SelectEmbedExperienceStep.tsx b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/SelectEmbedExperienceStep.tsxindex 3a46c9e4e38..6bf74cf0e8f 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/SelectEmbedExperienceStep.tsx+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/SelectEmbedExperienceStep.tsx@@ -1,69 +1,24 @@-import { P, match } from "ts-pattern";import { t } from "ttag";-import _ from "underscore";-import { ALLOWED_EMBED_SETTING_KEYS_MAP } from "metabase/embedding/embedding-iframe-sdk/constants";import { UPSELL_CAMPAIGN_EXPERIENCE } from "metabase/embedding/embedding-iframe-sdk-setup/analytics";+import { AuthenticationSection } from "metabase/embedding/embedding-iframe-sdk-setup/components/Authentication/AuthenticationSection";import { WithSimpleEmbeddingFeatureUpsellTooltip } from "metabase/embedding/embedding-iframe-sdk-setup/components/warnings/WithSimpleEmbeddingFeatureUpsellTooltip";+import { useHandleExperienceChange } from "metabase/embedding/embedding-iframe-sdk-setup/hooks/use-handle-experience-change";import { PLUGIN_METABOT } from "metabase/plugins";import { Card, Flex, Radio, Stack, Text } from "metabase/ui";-import {- EMBED_FALLBACK_DASHBOARD_ID,- EMBED_FALLBACK_QUESTION_ID,- getEmbedExperiences,-} from "../constants";+import { getEmbedExperiences } from "../constants";import { useSdkIframeEmbedSetupContext } from "../context";import type { SdkIframeEmbedSetupExperience } from "../types";-import { getDefaultSdkIframeEmbedSettings } from "../utils/get-default-sdk-iframe-embed-setting";export const SelectEmbedExperienceStep = () => {- const {- isSimpleEmbedFeatureAvailable,- isGuestEmbedsEnabled,- initialState,- experience,- settings,- replaceSettings,- recentDashboards,- recentQuestions,- } = useSdkIframeEmbedSetupContext();+ const { isSimpleEmbedFeatureAvailable, experience, settings } =+ useSdkIframeEmbedSetupContext();+ const isGuestEmbed = !!settings.isGuest;const isMetabotAvailable = PLUGIN_METABOT.isEnabled();- const handleEmbedExperienceChange = (- experience: SdkIframeEmbedSetupExperience,- ) => {- const persistedSettings = _.pick(- settings,- ALLOWED_EMBED_SETTING_KEYS_MAP.base,- );-- // Use the most recent item for the selected type.- // If the activity log is completely empty, use the fallback.- const defaultResourceId = match(experience)- .with("chart", () => recentQuestions[0]?.id ?? EMBED_FALLBACK_QUESTION_ID)- .with(- "dashboard",- () => recentDashboards[0]?.id ?? EMBED_FALLBACK_DASHBOARD_ID,- )- .with(P.union("exploration", "browser", "metabot"), () => 0) // resource id does not apply- .exhaustive();-- replaceSettings({- // these settings do not change when the embed type changes- ...persistedSettings,-- // these settings are overridden when the embed type changes- ...getDefaultSdkIframeEmbedSettings({- initialState,- experience,- resourceId: defaultResourceId,- isSimpleEmbedFeatureAvailable,- isGuestEmbedsEnabled,- }),- });- };+ const handleEmbedExperienceChange = useHandleExperienceChange();const experiences = getEmbedExperiences({isSimpleEmbedFeatureAvailable,@@ -71,44 +26,51 @@ export const SelectEmbedExperienceStep = () => {});return (- <Card p="md" mb="md">- <Text size="lg" fw="bold" mb="md">- {t`Select your embed experience`}- </Text>+ <>+ <AuthenticationSection />++ <Card p="md" mb="md">+ <Text size="lg" fw="bold" mb="md">+ {t`Select your embed experience`}+ </Text>- <Radio.Group- value={experience}- onChange={(experience) =>- handleEmbedExperienceChange(- experience as SdkIframeEmbedSetupExperience,- )- }- >- <Stack gap="md">- {experiences.map((experience) => (- <WithSimpleEmbeddingFeatureUpsellTooltip- key={experience.value}- mode="custom"- enableTooltip={experience.showUpsell === true}- campaign={UPSELL_CAMPAIGN_EXPERIENCE}- >- {({ disabled, hoverCard }) => (- <Radio- value={experience.value}- label={- <Flex gap="xs" align="center">- {experience.title}- {hoverCard}- </Flex>- }- description={experience.description}- disabled={disabled}- />- )}- </WithSimpleEmbeddingFeatureUpsellTooltip>- ))}- </Stack>- </Radio.Group>- </Card>+ <Radio.Group+ value={experience}+ onChange={(experience) =>+ handleEmbedExperienceChange(+ experience as SdkIframeEmbedSetupExperience,+ )+ }+ >+ <Stack gap="md">+ {experiences.map((experience) => (+ <WithSimpleEmbeddingFeatureUpsellTooltip+ key={experience.value}+ mode="custom"+ enableTooltip={experience.showUpsell === true}+ campaign={UPSELL_CAMPAIGN_EXPERIENCE}+ >+ {({ disabled, hoverCard }) => (+ <Radio+ value={experience.value}+ label={+ <Flex gap="xs" align="center">+ {experience.title}+ {hoverCard}+ </Flex>+ }+ description={experience.description}+ disabled={+ disabled ||+ (isGuestEmbed && !experience.supportsGuestEmbed)+ }+ />+ )}+ </WithSimpleEmbeddingFeatureUpsellTooltip>+ ))}+ </Stack>+ </Radio.Group>+ </Card>+ </>);};diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/SelectEmbedOptionsStep.tsx b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/SelectEmbedOptionsStep.tsxindex 3a4f53bc779..ebb1cb7196a 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/SelectEmbedOptionsStep.tsx+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/SelectEmbedOptionsStep.tsx@@ -1,16 +1,11 @@-import { type ReactNode, useCallback, useMemo } from "react";+import { useCallback, useMemo } from "react";import { Link } from "react-router";import { P, match } from "ts-pattern";import { c, t } from "ttag";-import { useHasEmailSetup, useSetting } from "metabase/common/hooks";-import {- UPSELL_CAMPAIGN_AUTH,- UPSELL_CAMPAIGN_BEHAVIOR,-} from "metabase/embedding/embedding-iframe-sdk-setup/analytics";-import { SimpleThemeSwitcherSection } from "metabase/embedding/embedding-iframe-sdk-setup/components/Appearance/SimpleThemeSwitcherSection";-import { getAuthTypeForSettings } from "metabase/embedding/embedding-iframe-sdk-setup/utils/get-auth-type-for-settings";-import { isQuestionOrDashboardSettings } from "metabase/embedding/embedding-iframe-sdk-setup/utils/is-question-or-dashboard-settings";+import { useHasEmailSetup } from "metabase/common/hooks";+import { UPSELL_CAMPAIGN_BEHAVIOR } from "metabase/embedding/embedding-iframe-sdk-setup/analytics";+import { WithNotAvailableWithoutSimpleEmbeddingFeatureWarning } from "metabase/embedding/embedding-iframe-sdk-setup/components/Common/WithNotAvailableWithoutSimpleEmbeddingFeatureWarning";import type {MetabaseColors,MetabaseThemePreset,@@ -22,7 +17,6 @@ import {Flex,HoverCard,Icon,- Radio,Stack,Text,} from "metabase/ui";@@ -30,14 +24,12 @@ import {import { useSdkIframeEmbedSetupContext } from "../context";import { ColorCustomizationSection } from "./Appearance/ColorCustomizationSection";+import { SimpleThemeSwitcherSection } from "./Appearance/SimpleThemeSwitcherSection";+import { AuthenticationSection } from "./Authentication/AuthenticationSection";+import { WithNotAvailableForGuestEmbedsWarning } from "./Common/WithNotAvailableForGuestEmbedsWarning";import { LegacyStaticEmbeddingAlert } from "./LegacyStaticEmbeddingAlert";import { MetabotLayoutSetting } from "./MetabotLayoutSetting";import { ParameterSettings } from "./ParameterSettings";-import {- TooltipWarning,- type TooltipWarningMode,-} from "./warnings/TooltipWarning";-import { WithSimpleEmbeddingFeatureUpsellTooltip } from "./warnings/WithSimpleEmbeddingFeatureUpsellTooltip";export const SelectEmbedOptionsStep = () => (<Stack gap="md">@@ -49,126 +41,6 @@ export const SelectEmbedOptionsStep = () => (</Stack>);-const AuthenticationSection = () => {- const {- isSimpleEmbedFeatureAvailable,- experience,- settings,- updateSettings,- } = useSdkIframeEmbedSetupContext();-- const isQuestionOrDashboardEmbed = isQuestionOrDashboardSettings(- experience,- settings,- );-- const isJwtEnabled = useSetting("jwt-enabled");- const isSamlEnabled = useSetting("saml-enabled");- const isJwtConfigured = useSetting("jwt-configured");- const isSamlConfigured = useSetting("saml-configured");-- const isSsoEnabledAndConfigured =- (isJwtEnabled && isJwtConfigured) || (isSamlEnabled && isSamlConfigured);-- const authType = getAuthTypeForSettings(settings);-- const handleAuthTypeChange = (value: string) => {- const isGuest = value === "guest-embed";- const useExistingUserSession = value === "user-session";-- updateSettings({- isGuest,- useExistingUserSession,- });- };-- /* eslint-disable-next-line no-literal-metabase-strings -- this string is only shown for admins. */- const existingMetabaseSessionLabel = t`Existing Metabase session`;-- return (- <Card p="md">- <Stack gap="md" p="xs">- <Text size="lg" fw="bold">- {t`Authentication`}- </Text>-- <Radio.Group value={authType} onChange={handleAuthTypeChange}>- <Stack gap="sm">- {isQuestionOrDashboardEmbed && (- <WithGuestEmbedsDisabledWarning>- {({ disabled }) => (- <Radio- disabled={disabled}- value="guest-embed"- label={t`Guest`}- />- )}- </WithGuestEmbedsDisabledWarning>- )}-- <WithSimpleEmbeddingFeatureUpsellTooltip- enableTooltip={!isSimpleEmbedFeatureAvailable}- campaign={UPSELL_CAMPAIGN_AUTH}- >- {({ disabled }) => (- <Radio- value="user-session"- label={- disabled ? (- existingMetabaseSessionLabel- ) : (- <Flex align="center" gap="xs">- <Text>{existingMetabaseSessionLabel}</Text>- <HoverCard position="bottom">- <HoverCard.Target>- <Icon- name="info"- size={14}- c="text-medium"- cursor="pointer"- style={{ flexShrink: 0 }}- />- </HoverCard.Target>- <HoverCard.Dropdown>- <Text lh="md" p="md" style={{ width: 300 }}>- {/* eslint-disable-next-line no-literal-metabase-strings -- this string is only shown for admins. */}- {t`This option lets you test Embedded Analytics JS locally using your existing Metabase session cookie. This only works for testing locally, using your admin account and on this browser. This may not work on Safari and Firefox. We recommend testing this in Chrome.`}- </Text>- </HoverCard.Dropdown>- </HoverCard>- </Flex>- )- }- disabled={disabled}- />- )}- </WithSimpleEmbeddingFeatureUpsellTooltip>-- <WithSimpleEmbeddingFeatureUpsellTooltip- enableTooltip={!isSimpleEmbedFeatureAvailable}- campaign={UPSELL_CAMPAIGN_AUTH}- >- {({ disabled }) => (- <Radio- value="sso"- label={t`Single sign-on (SSO)`}- disabled={disabled || !isSsoEnabledAndConfigured}- />- )}- </WithSimpleEmbeddingFeatureUpsellTooltip>- </Stack>- </Radio.Group>-- {authType === "sso" && (- <Text size="sm" c="text-medium">- {t`Select this option if you have already set up SSO. This option relies on SSO to sign in your application users into the embedded iframe, and groups and permissions to enforce limits on what users can access. `}- </Text>- )}- </Stack>- </Card>- );-};-const BehaviorSection = () => {const { settings, updateSettings } = useSdkIframeEmbedSetupContext();const hasEmailSetup = useHasEmailSetup();@@ -445,82 +317,3 @@ const AppearanceSection = () => {</Card>);};--const WithGuestEmbedsDisabledWarning = ({- children,-}: {- children: (data: { disabled: boolean }) => ReactNode;-}) => {- const { isGuestEmbedsEnabled } = useSdkIframeEmbedSetupContext();-- const disabled = !isGuestEmbedsEnabled;-- return (- <TooltipWarning- tooltip={t`Disabled in the admin settings`}- disabled={disabled}- >- {children}- </TooltipWarning>- );-};--const WithNotAvailableWithoutSimpleEmbeddingFeatureWarning = ({- mode,- children,- campaign,-}: {- mode?: TooltipWarningMode;- children: (data: { disabled: boolean; hoverCard: ReactNode }) => ReactNode;- campaign: string;-}) => {- const { isSimpleEmbedFeatureAvailable } = useSdkIframeEmbedSetupContext();-- return (- <WithSimpleEmbeddingFeatureUpsellTooltip- mode={mode}- enableTooltip={!isSimpleEmbedFeatureAvailable}- campaign={campaign}- >- {({ disabled, hoverCard }) => children({ disabled, hoverCard })}- </WithSimpleEmbeddingFeatureUpsellTooltip>- );-};--const WithNotAvailableForGuestEmbedsWarning = ({- mode,- children,- campaign,-}: {- mode?: TooltipWarningMode;- children: (data: { disabled: boolean; hoverCard: ReactNode }) => ReactNode;- campaign: string;-}) => {- const { settings } = useSdkIframeEmbedSetupContext();-- return (- <WithNotAvailableWithoutSimpleEmbeddingFeatureWarning- mode={mode}- campaign={campaign}- >- {({ disabled: disabledForOss, hoverCard: disabledForOssHoverCard }) => (- <TooltipWarning- enableTooltip={!disabledForOss}- tooltip={t`Not available if Guest Mode is selected`}- disabled={!!settings.isGuest}- >- {({- disabled: disabledForGuestEmbeds,- hoverCard: disabledForGuestEmbedsHoverCard,- }) =>- children({- disabled: disabledForOss || disabledForGuestEmbeds,- hoverCard:- disabledForOssHoverCard || disabledForGuestEmbedsHoverCard,- })- }- </TooltipWarning>- )}- </WithNotAvailableWithoutSimpleEmbeddingFeatureWarning>- );-};diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/tests/SdkIframeEmbedSetup-embedding-hub.unit.spec.tsx b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/tests/SdkIframeEmbedSetup-embedding-hub.unit.spec.tsxindex 9ede2a12453..05151015ae8 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/tests/SdkIframeEmbedSetup-embedding-hub.unit.spec.tsx+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/tests/SdkIframeEmbedSetup-embedding-hub.unit.spec.tsx@@ -35,17 +35,19 @@ describe("Embed flow > embedding hub step completion tracking", () => {},});+ const authRadio = screen.getByDisplayValue("sso");+ await userEvent.click(authRadio);+ expect(authRadio).toBeChecked();+await userEvent.click(screen.getByRole("button", { name: "Next" }));await userEvent.click(screen.getByRole("button", { name: "Next" }));+ await userEvent.click(screen.getByRole("button", { name: "Get code" }));- const authRadio = screen.getByDisplayValue(+ const ssoTypeRadio = screen.getByDisplayValue(useExistingUserSession ? "user-session" : "sso",);-- await userEvent.click(authRadio);- expect(authRadio).toBeChecked();-- await userEvent.click(screen.getByRole("button", { name: "Get code" }));+ await userEvent.click(ssoTypeRadio);+ expect(ssoTypeRadio).toBeChecked();const actionButton = screen.getByRole("button", {name: trigger === "copy" ? /Copy code/ : /Done/,diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/tests/SdkIframeEmbedSetup.unit.spec.tsx b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/tests/SdkIframeEmbedSetup.unit.spec.tsxindex d8981bd6c2e..7285cdb4888 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/tests/SdkIframeEmbedSetup.unit.spec.tsx+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/tests/SdkIframeEmbedSetup.unit.spec.tsx@@ -43,6 +43,8 @@ describe("Embed flow > forward and backward navigation", () => {it("navigates forward through the embed flow", async () => {setup({ simpleEmbeddingEnabled: true });+ expect(screen.getByText("Authentication")).toBeInTheDocument();+expect(screen.getByText("Select your embed experience"),).toBeInTheDocument();@@ -53,7 +55,6 @@ describe("Embed flow > forward and backward navigation", () => {await userEvent.click(screen.getByRole("button", { name: "Next" }));- expect(screen.getByText("Authentication")).toBeInTheDocument();expect(screen.getByText("Behavior")).toBeInTheDocument();expect(screen.getByText("Appearance")).toBeInTheDocument();expect(@@ -88,7 +89,9 @@ describe("Embed flow > forward and backward navigation", () => {expect(screen.getByText("Select your embed experience"),).toBeInTheDocument();- expect(screen.getByRole("button", { name: "Back" })).toBeDisabled();+ expect(+ screen.queryByRole("button", { name: "Back" }),+ ).not.toBeInTheDocument();});it("skips the 'select resource' step for exploration", async () => {@@ -110,10 +113,12 @@ describe("Embed flow > forward and backward navigation", () => {setup({ simpleEmbeddingEnabled: false });expect(screen.getByRole("button", { name: "Next" })).toBeDisabled();- expect(screen.getByRole("button", { name: "Back" })).toBeDisabled();+ expect(+ screen.queryByRole("button", { name: "Back" }),+ ).not.toBeInTheDocument();});- it("pre-selects question when resourceType: question is the initial state", async () => {+ it("does not allow to go back when resourceType: question is the initial state", async () => {const mockDatabase = createMockDatabase();const mockCard = createMockCard({ id: 456 });@@ -137,12 +142,8 @@ describe("Embed flow > forward and backward navigation", () => {expect(screen.getByText("Behavior")).toBeInTheDocument();expect(screen.getByText("Appearance")).toBeInTheDocument();- // Going back to the "select resource" step shows that it is expecting a chart.- await userEvent.click(screen.getByRole("button", { name: "Back" }));- expect(screen.getByText("Select a chart to embed")).toBeInTheDocument();-- // Going back to the "select experience" step shows that it is expecting a chart.- await userEvent.click(screen.getByRole("button", { name: "Back" }));- expect(screen.getByRole("radio", { name: /Chart/ })).toBeChecked();+ expect(+ screen.queryByRole("button", { name: "Back" }),+ ).not.toBeInTheDocument();});});diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/warnings/WithSimpleEmbeddingFeatureUpsellTooltip.tsx b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/warnings/WithSimpleEmbeddingFeatureUpsellTooltip.tsxindex 846a1d493cb..cd4b49350e7 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/warnings/WithSimpleEmbeddingFeatureUpsellTooltip.tsx+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/components/warnings/WithSimpleEmbeddingFeatureUpsellTooltip.tsx@@ -3,6 +3,7 @@ import { t } from "ttag";import { UpsellGem } from "metabase/admin/upsells/components";import { UpsellCard } from "metabase/common/components/UpsellCard";+import { UTM_LOCATION } from "metabase/embedding/embedding-iframe-sdk-setup/analytics";import { useSdkIframeEmbedSetupContext } from "metabase/embedding/embedding-iframe-sdk-setup/context";import { useSelector } from "metabase/lib/redux";import { getUpgradeUrl } from "metabase/selectors/settings";@@ -40,7 +41,7 @@ export const WithSimpleEmbeddingFeatureUpsellTooltip = ({title={t`Get more powerful embedding`}buttonLink={upgradeUrl}campaign={campaign}- location="embedded_analytics_js_wizard"+ location={UTM_LOCATION}/* eslint-disable-next-line no-literal-metabase-strings -- Button text */buttonText={t`Upgrade to Metabase Pro`}maxWidth={UPSELL_CARD_WIDTH}diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/constants.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/constants.tsindex 10f1845166a..e8a46f94b5e 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/constants.ts+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/constants.ts@@ -24,23 +24,27 @@ export const getEmbedExperiences = ({value: "dashboard",title: t`Dashboard`,description: t`Embed an entire dashboard with multiple charts and filters`,+ supportsGuestEmbed: true,},{value: "chart",title: t`Chart`,description: t`Embed a single chart`,+ supportsGuestEmbed: true,},{value: "exploration",title: t`Exploration`,description: t`Embed an interactive data exploration experience`,showUpsell: !isSimpleEmbedFeatureAvailable,+ supportsGuestEmbed: false,},{value: "browser",title: t`Browser`,description: t`Embed a browser to manage dashboards and charts`,showUpsell: !isSimpleEmbedFeatureAvailable,+ supportsGuestEmbed: false,},...(isMetabotAvailable? [@@ -49,6 +53,7 @@ export const getEmbedExperiences = ({title: t`Metabot`,description: t`Embed a Metabot chat interface`,showUpsell: !isSimpleEmbedFeatureAvailable,+ supportsGuestEmbed: false,},]: []),@@ -57,6 +62,7 @@ export const getEmbedExperiences = ({description: string;value: SdkIframeEmbedSetupExperience;showUpsell?: boolean;+ supportsGuestEmbed: boolean;}[];type EmbedStepConfig = {diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/context.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/context.tsindex db2241e3eb0..3930435149b 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/context.ts+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/context.ts@@ -26,9 +26,16 @@ export interface SdkIframeEmbedSetupContextType {isGuestEmbedsEnabled: boolean;isGuestEmbedsTermsAccepted: boolean;+ isSsoEnabledAndConfigured: boolean;+// NavigationcurrentStep: SdkIframeEmbedSetupStep;setCurrentStep: (step: SdkIframeEmbedSetupStep) => void;+ handleNext: () => void;+ handleBack: () => void;+ canGoBack: boolean;+ isFirstStep: boolean;+ isLastStep: boolean;// Initial stateinitialState: SdkIframeEmbedSetupModalInitialState | undefined;diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-handle-experience-change.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-handle-experience-change.tsnew file mode 100644index 00000000000..73a5578b3c0--- /dev/null+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-handle-experience-change.ts@@ -0,0 +1,76 @@+import { useCallback } from "react";+import { P, match } from "ts-pattern";+import _ from "underscore";++import { ALLOWED_EMBED_SETTING_KEYS_MAP } from "metabase/embedding/embedding-iframe-sdk/constants";+import {+ EMBED_FALLBACK_DASHBOARD_ID,+ EMBED_FALLBACK_QUESTION_ID,+} from "metabase/embedding/embedding-iframe-sdk-setup/constants";+import { useSdkIframeEmbedSetupContext } from "metabase/embedding/embedding-iframe-sdk-setup/context";+import type { SdkIframeEmbedSetupExperience } from "metabase/embedding/embedding-iframe-sdk-setup/types";+import { getDefaultSdkIframeEmbedSettings } from "metabase/embedding/embedding-iframe-sdk-setup/utils/get-default-sdk-iframe-embed-setting";++export const DEFAULT_EXPERIENCE = "dashboard";++export const useHandleExperienceChange = () => {+ const {+ isSimpleEmbedFeatureAvailable,+ isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,+ settings,+ replaceSettings,+ recentDashboards,+ recentQuestions,+ } = useSdkIframeEmbedSetupContext();++ const handleEmbedExperienceChange = useCallback(+ (experience: SdkIframeEmbedSetupExperience) => {+ const persistedSettings = _.pick(+ settings,+ ALLOWED_EMBED_SETTING_KEYS_MAP.base,+ );++ // Use the most recent item for the selected type.+ // If the activity log is completely empty, use the fallback.+ const defaultResourceId = match(experience)+ .with(+ "chart",+ () => recentQuestions[0]?.id ?? EMBED_FALLBACK_QUESTION_ID,+ )+ .with(+ "dashboard",+ () => recentDashboards[0]?.id ?? EMBED_FALLBACK_DASHBOARD_ID,+ )+ .with(P.union("exploration", "browser", "metabot"), () => 0) // resource id does not apply+ .exhaustive();++ replaceSettings({+ // these settings do not change when the embed type changes+ ...persistedSettings,++ // these settings are overridden when the embed type changes+ ...getDefaultSdkIframeEmbedSettings({+ experience,+ resourceId: defaultResourceId,+ isSimpleEmbedFeatureAvailable,+ isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,+ isGuest: !!settings.isGuest,+ useExistingUserSession: !!settings.useExistingUserSession,+ }),+ });+ },+ [+ isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,+ isSimpleEmbedFeatureAvailable,+ recentDashboards,+ recentQuestions,+ replaceSettings,+ settings,+ ],+ );++ return handleEmbedExperienceChange;+};diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-is-sso-enabled-and-configured.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-is-sso-enabled-and-configured.tsnew file mode 100644index 00000000000..57cf21b5d78--- /dev/null+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-is-sso-enabled-and-configured.ts@@ -0,0 +1,12 @@+import { useSetting } from "metabase/common/hooks";++export const useIsSsoEnabledAndConfigured = () => {+ const isJwtEnabled = useSetting("jwt-enabled");+ const isSamlEnabled = useSetting("saml-enabled");+ const isJwtConfigured = useSetting("jwt-configured");+ const isSamlConfigured = useSetting("saml-configured");++ return (+ (isJwtEnabled && isJwtConfigured) || (isSamlEnabled && isSamlConfigured)+ );+};diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-sdk-iframe-embed-navigation.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-sdk-iframe-embed-navigation.tsindex 09c48252c9b..6c9f77d9ca6 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-sdk-iframe-embed-navigation.ts+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-sdk-iframe-embed-navigation.ts@@ -1,28 +1,45 @@import { useMemo } from "react";import { match } from "ts-pattern";+import type { SdkIframeEmbedSetupStep } from "metabase/embedding/embedding-iframe-sdk-setup/types";+import {trackEmbedWizardExperienceCompleted,trackEmbedWizardOptionsCompleted,trackEmbedWizardResourceSelectionCompleted,} from "../analytics";import { EMBED_STEPS } from "../constants";-import { useSdkIframeEmbedSetupContext } from "../context";--export function useSdkIframeEmbedNavigation() {- const {- isSimpleEmbedFeatureAvailable,- isGuestEmbedsEnabled,- initialState,- experience,- resource,- currentStep,- setCurrentStep,- settings,- defaultSettings,- embeddingParameters,- } = useSdkIframeEmbedSetupContext();-+import type { SdkIframeEmbedSetupContextType } from "../context";++export function useSdkIframeEmbedNavigation({+ isSimpleEmbedFeatureAvailable,+ isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,+ initialState,+ experience,+ resource,+ defaultStep,+ currentStep,+ setCurrentStep,+ settings,+ defaultSettings,+ embeddingParameters,+}: Pick<+ SdkIframeEmbedSetupContextType,+ | "isSimpleEmbedFeatureAvailable"+ | "isGuestEmbedsEnabled"+ | "isSsoEnabledAndConfigured"+ | "initialState"+ | "experience"+ | "resource"+ | "currentStep"+ | "setCurrentStep"+ | "settings"+ | "defaultSettings"+ | "embeddingParameters"+> & {+ defaultStep: SdkIframeEmbedSetupStep;+}) {const availableSteps = useMemo(() => {// Exclude non-applicable steps for the current embed typereturn EMBED_STEPS.filter((step) => !step.skipFor?.includes(experience));@@ -37,10 +54,11 @@ export function useSdkIframeEmbedNavigation() {match(currentStep).with("select-embed-experience", () => {- trackEmbedWizardExperienceCompleted(+ trackEmbedWizardExperienceCompleted({experience,- defaultSettings.experience,- );+ defaultExperience: defaultSettings.experience,+ settings,+ });}).with("select-embed-resource", () => {trackEmbedWizardResourceSelectionCompleted({@@ -57,6 +75,7 @@ export function useSdkIframeEmbedNavigation() {settings,isSimpleEmbedFeatureAvailable,isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,embeddingParameters,});});@@ -82,17 +101,16 @@ export function useSdkIframeEmbedNavigation() {(step) => step.id === currentStep,);- const canGoNext = currentIndex < availableSteps.length - 1;- const canGoBack = currentIndex > 0;-+ const isFirstStep = currentStep === defaultStep;const isLastStep = currentIndex === availableSteps.length - 1;- const StepContent = useMemo(- () =>- EMBED_STEPS.find((step) => step.id === currentStep)?.component ?? noop,- [currentStep],+ const defaultStepIndex = EMBED_STEPS.findIndex(+ ({ id }) => id === defaultStep,);+ const canGoNext = currentIndex < availableSteps.length - 1;+ const canGoBack = currentIndex > defaultStepIndex;+return {handleNext,handleBack,@@ -100,9 +118,7 @@ export function useSdkIframeEmbedNavigation() {canGoNext,canGoBack,+ isFirstStep,isLastStep,- StepContent,};}--const noop = () => null;diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-sdk-iframe-embed-settings.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-sdk-iframe-embed-settings.tsindex 3d3d0f495e5..51c92181a35 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-sdk-iframe-embed-settings.ts+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/hooks/use-sdk-iframe-embed-settings.ts@@ -75,6 +75,7 @@ export const useSdkIframeEmbedSettings = ({modelCount,isSimpleEmbedFeatureAvailable,isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,}: {initialState: SdkIframeEmbedSetupModalInitialState | undefined;recentDashboards: SdkIframeEmbedSetupRecentItem[];@@ -82,6 +83,7 @@ export const useSdkIframeEmbedSettings = ({modelCount: number;isSimpleEmbedFeatureAvailable: boolean;isGuestEmbedsEnabled: boolean;+ isSsoEnabledAndConfigured: boolean;}) => {const [isEmbedSettingsLoaded, setEmbedSettingsLoaded] = useState(false);const [persistedSettings, persistSettings] = usePersistedSettings({@@ -94,38 +96,45 @@ export const useSdkIframeEmbedSettings = ({{ resourceType: "dashboard", resourceId: P.nonNullable },(initialState) =>getDefaultSdkIframeEmbedSettings({- initialState,experience: "dashboard",resourceId: initialState.resourceId,isSimpleEmbedFeatureAvailable,isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,+ isGuest: !!initialState.isGuest,+ useExistingUserSession: !!initialState.useExistingUserSession,}),).with({ resourceType: "question", resourceId: P.nonNullable },(initialState) =>getDefaultSdkIframeEmbedSettings({- initialState,experience: "chart",resourceId: initialState.resourceId,isSimpleEmbedFeatureAvailable,isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,+ isGuest: !!initialState.isGuest,+ useExistingUserSession: !!initialState.useExistingUserSession,}),).otherwise((initialState) =>getDefaultSdkIframeEmbedSettings({- initialState,experience: "dashboard",resourceId: recentDashboards[0]?.id ?? EMBED_FALLBACK_DASHBOARD_ID,isSimpleEmbedFeatureAvailable,isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,+ isGuest: !!initialState?.isGuest,+ useExistingUserSession: !!initialState?.useExistingUserSession,}),);}, [- recentDashboards,initialState,isSimpleEmbedFeatureAvailable,isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,+ recentDashboards,]);const [rawSettings, setRawSettings] = useState<SdkIframeEmbedSetupSettings>();@@ -164,13 +173,19 @@ export const useSdkIframeEmbedSettings = ({prevSettings: prevSettings ?? defaultSettings,settings: mergedSettings,isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,});persistSettings(adjustedSettings);return adjustedSettings;}),- [defaultSettings, persistSettings, isGuestEmbedsEnabled],+ [+ defaultSettings,+ isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,+ persistSettings,+ ],);const replaceSettings = useCallback(@@ -196,6 +211,7 @@ export const useSdkIframeEmbedSettings = ({prevSettings: prevSettings ?? defaultSettings,settings: mergedSettings,isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,});return adjustedSettings;@@ -211,6 +227,7 @@ export const useSdkIframeEmbedSettings = ({initialState,defaultSettings,isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,]);return {diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/types.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/types.tsindex 08c53440fe8..20186895748 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/types.ts+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/types.ts@@ -4,8 +4,8 @@ import type {ExplorationEmbedOptions,MetabotEmbedOptions,QuestionEmbedOptions,+ SdkIframeEmbedAuthTypeSettings,SdkIframeEmbedBaseSettings,- SdkIframeEmbedGuestEmbedSettings,} from "metabase/embedding/embedding-iframe-sdk/types/embed";import type { BaseRecentItem } from "metabase-types/api";@@ -33,7 +33,7 @@ export type SdkIframeEmbedSetupRecentItem = Pick<> & { id: string | number };export type SdkIframeEmbedSetupGuestEmbedSettings =- SdkIframeEmbedGuestEmbedSettings;+ SdkIframeEmbedAuthTypeSettings;export type SdkIframeDashboardEmbedSettings = DashboardEmbedOptions & {lockedParameters?: string[];diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-adjusted-sdk-iframe-embed-setting.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-adjusted-sdk-iframe-embed-setting.tsindex 10376140007..27f5b755b5b 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-adjusted-sdk-iframe-embed-setting.ts+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-adjusted-sdk-iframe-embed-setting.ts@@ -11,11 +11,13 @@ export const getAdjustedSdkIframeEmbedSetting = ({prevSettings,settings,isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,}: {defaultSettings: SdkIframeEmbedSetupSettings;prevSettings: SdkIframeEmbedSetupSettings;settings: SdkIframeEmbedSetupSettings;isGuestEmbedsEnabled: boolean;+ isSsoEnabledAndConfigured: boolean;}): SdkIframeEmbedSetupSettings => {const experience = getExperienceFromSettings(settings);@@ -28,12 +30,11 @@ export const getAdjustedSdkIframeEmbedSetting = ({({ settings }) => ({...settings,...getCommonEmbedSettings({- state: {- isGuest: settings.isGuest,- useExistingUserSession: settings.useExistingUserSession,- },experience,isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,+ isGuest: settings.isGuest,+ useExistingUserSession: !!settings.useExistingUserSession,}),}),)@@ -48,14 +49,12 @@ export const getAdjustedSdkIframeEmbedSetting = ({isSaveEnabled:"isSaveEnabled" in defaultSettings && defaultSettings.isSaveEnabled,...getCommonEmbedSettings({- state: {- isGuest: settings.isGuest,- useExistingUserSession: settings.useExistingUserSession,- },experience,isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,+ isGuest: settings.isGuest,+ useExistingUserSession: !!settings.useExistingUserSession,}),- useExistingUserSession: settings.useExistingUserSession,}),).otherwise(({ settings }) => settings);diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-auth-sub-type-for-settings.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-auth-sub-type-for-settings.tsnew file mode 100644index 00000000000..fc653a1c527--- /dev/null+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-auth-sub-type-for-settings.ts@@ -0,0 +1,10 @@+import type { SdkIframeEmbedSetupSettings } from "metabase/embedding/embedding-iframe-sdk-setup/types";++export const getAuthSubTypeForSettings = (+ settings: Partial<SdkIframeEmbedSetupSettings>,+) =>+ settings.isGuest+ ? "none"+ : settings.useExistingUserSession+ ? "user-session"+ : "sso";diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-auth-type-for-settings.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-auth-type-for-settings.tsindex fc3a18c1213..567db7afb06 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-auth-type-for-settings.ts+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-auth-type-for-settings.ts@@ -2,9 +2,4 @@ import type { SdkIframeEmbedSetupSettings } from "metabase/embedding/embedding-iexport const getAuthTypeForSettings = (settings: Partial<SdkIframeEmbedSetupSettings>,-) =>- settings.isGuest- ? "guest-embed"- : settings.useExistingUserSession- ? "user-session"- : "sso";+) => (settings.isGuest ? "guest-embed" : "sso");diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-common-embed-settings.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-common-embed-settings.tsindex 395b3e75594..9a988f2504d 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-common-embed-settings.ts+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-common-embed-settings.ts@@ -24,6 +24,7 @@ const GET_ENABLE_GUEST_EMBED_SETTINGS: (data: {...(isQuestionOrDashboardEmbed? {isGuest: true,+ isSso: false,useExistingUserSession: false,...(isQuestionOrDashboardEmbed && {drills: false,@@ -35,6 +36,7 @@ const GET_ENABLE_GUEST_EMBED_SETTINGS: (data: {}: {isGuest: false,+ isSso: true,useExistingUserSession: true,}),hiddenParameters: [],@@ -42,16 +44,15 @@ const GET_ENABLE_GUEST_EMBED_SETTINGS: (data: {};const GET_DISABLE_GUEST_EMBED_SETTINGS: (data: {- state:- | Pick<SdkIframeEmbedSetupSettings, "isGuest" | "useExistingUserSession">- | undefined;experience: SdkIframeEmbedSetupExperience;+ isSsoEnabledAndConfigured: boolean;+ useExistingUserSession: boolean;}) => SdkIframeEmbedSetupGuestEmbedSettings &Pick<SdkIframeEmbedSetupSettings, "useExistingUserSession"> &Pick<SdkIframeDashboardEmbedSettings | SdkIframeQuestionEmbedSettings,"lockedParameters"- > = ({ state, experience }) => {+ > = ({ experience, isSsoEnabledAndConfigured, useExistingUserSession }) => {const isQuestionOrDashboardEmbed =isQuestionOrDashboardExperience(experience);const isQuestionEmbed = experience === "chart";@@ -60,12 +61,16 @@ const GET_DISABLE_GUEST_EMBED_SETTINGS: (data: {...(isQuestionOrDashboardEmbed? {isGuest: false,- useExistingUserSession: state?.useExistingUserSession,+ isSso: true,+ useExistingUserSession:+ !isSsoEnabledAndConfigured || useExistingUserSession,drills: true,}: {isGuest: false,- useExistingUserSession: state?.useExistingUserSession,+ isSso: true,+ useExistingUserSession:+ !isSsoEnabledAndConfigured || useExistingUserSession,}),...(isQuestionEmbed && {// Currently, a chart should not have hidden parameters in non-guest embed mode@@ -75,26 +80,32 @@ const GET_DISABLE_GUEST_EMBED_SETTINGS: (data: {};export const getCommonEmbedSettings = ({- state,experience,isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,+ isGuest,+ useExistingUserSession,}: {- state:- | Pick<SdkIframeEmbedSetupSettings, "isGuest" | "useExistingUserSession">- | undefined;experience: SdkIframeEmbedSetupExperience;isGuestEmbedsEnabled: boolean;+ isSsoEnabledAndConfigured: boolean;+ isGuest: boolean;+ useExistingUserSession: boolean;}) => {const isSimpleEmbedFeatureAvailable =PLUGIN_EMBEDDING_IFRAME_SDK_SETUP.isEnabled();if (isSimpleEmbedFeatureAvailable) {- return isGuestEmbedsEnabled && state?.isGuest+ return isGuestEmbedsEnabled && isGuest? GET_ENABLE_GUEST_EMBED_SETTINGS({experience,isSimpleEmbedFeatureAvailable,})- : GET_DISABLE_GUEST_EMBED_SETTINGS({ state, experience });+ : GET_DISABLE_GUEST_EMBED_SETTINGS({+ experience,+ isSsoEnabledAndConfigured,+ useExistingUserSession,+ });} else {return GET_ENABLE_GUEST_EMBED_SETTINGS({experience,diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-common-embed-settings.unit.spec.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-common-embed-settings.unit.spec.tsindex 93177f36939..8ce894ead51 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-common-embed-settings.unit.spec.ts+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-common-embed-settings.unit.spec.ts@@ -36,6 +36,7 @@ describe("getCommonEmbedSettings", () => {useExistingUserSession: false,expected: {isGuest: true,+ isSso: false,useExistingUserSession: false,drills: false,hiddenParameters: [],@@ -46,6 +47,7 @@ describe("getCommonEmbedSettings", () => {useExistingUserSession: false,expected: {isGuest: true,+ isSso: false,useExistingUserSession: false,drills: false,hiddenParameters: [],@@ -56,6 +58,7 @@ describe("getCommonEmbedSettings", () => {useExistingUserSession: true,expected: {isGuest: false,+ isSso: true,useExistingUserSession: true,hiddenParameters: [],},@@ -65,6 +68,7 @@ describe("getCommonEmbedSettings", () => {useExistingUserSession: true,expected: {isGuest: false,+ isSso: true,useExistingUserSession: true,hiddenParameters: [],},@@ -74,6 +78,7 @@ describe("getCommonEmbedSettings", () => {useExistingUserSession: true,expected: {isGuest: false,+ isSso: true,useExistingUserSession: true,hiddenParameters: [],},@@ -82,9 +87,11 @@ describe("getCommonEmbedSettings", () => {"should return correct settings for $experience experience",({ experience, useExistingUserSession, expected }) => {const result = getCommonEmbedSettings({- state: { isGuest: true, useExistingUserSession },experience,isGuestEmbedsEnabled: true,+ isSsoEnabledAndConfigured: true,+ isGuest: true,+ useExistingUserSession,});expect(result).toEqual(expected);@@ -96,13 +103,27 @@ describe("getCommonEmbedSettings", () => {it.each<{experience: SdkIframeEmbedSetupExperience;useExistingUserSession: boolean;+ isSsoEnabledAndConfigured: boolean;expected: Record<string, unknown>;}>([{experience: "dashboard",useExistingUserSession: true,+ isSsoEnabledAndConfigured: true,+ expected: {+ isGuest: false,+ isSso: true,+ useExistingUserSession: true,+ drills: true,+ },+ },+ {+ experience: "dashboard",+ useExistingUserSession: false,+ isSsoEnabledAndConfigured: false,expected: {isGuest: false,+ isSso: true,useExistingUserSession: true,drills: true,},@@ -110,8 +131,10 @@ describe("getCommonEmbedSettings", () => {{experience: "chart",useExistingUserSession: false,+ isSsoEnabledAndConfigured: true,expected: {isGuest: false,+ isSso: true,useExistingUserSession: false,drills: true,hiddenParameters: [],@@ -120,18 +143,27 @@ describe("getCommonEmbedSettings", () => {{experience: "exploration",useExistingUserSession: true,+ isSsoEnabledAndConfigured: true,expected: {isGuest: false,+ isSso: true,useExistingUserSession: true,},},])(- "should return non-guest settings for $experience experience",- ({ experience, useExistingUserSession, expected }) => {+ "should return non-guest settings for $experience experience (useExistingUserSession=$useExistingUserSession, isSsoEnabledAndConfigured=$isSsoEnabledAndConfigured)",+ ({+ experience,+ useExistingUserSession,+ isSsoEnabledAndConfigured,+ expected,+ }) => {const result = getCommonEmbedSettings({- state: { isGuest: false, useExistingUserSession },experience,isGuestEmbedsEnabled: false,+ isSsoEnabledAndConfigured,+ isGuest: false,+ useExistingUserSession,});expect(result).toEqual(expected);@@ -140,34 +172,53 @@ describe("getCommonEmbedSettings", () => {it("should reset hiddenParameters for chart but not for dashboard in non-guest mode", () => {const chartResult = getCommonEmbedSettings({- state: { isGuest: false, useExistingUserSession: true },experience: "chart",isGuestEmbedsEnabled: false,+ isSsoEnabledAndConfigured: true,+ isGuest: false,+ useExistingUserSession: true,});const dashboardResult = getCommonEmbedSettings({- state: { isGuest: false, useExistingUserSession: true },experience: "dashboard",isGuestEmbedsEnabled: false,+ isSsoEnabledAndConfigured: true,+ isGuest: false,+ useExistingUserSession: true,});expect(chartResult).toHaveProperty("hiddenParameters", []);expect(dashboardResult).not.toHaveProperty("hiddenParameters");});- it("should handle undefined state", () => {+ it("should handle `false` for isGuest and `useExistingUserSession`", () => {const result = getCommonEmbedSettings({- state: undefined,experience: "dashboard",isGuestEmbedsEnabled: false,+ isSsoEnabledAndConfigured: true,+ isGuest: false,+ useExistingUserSession: false,});expect(result).toEqual({isGuest: false,- useExistingUserSession: undefined,+ isSso: true,+ useExistingUserSession: false,drills: true,});});++ it("should set useExistingUserSession to true when isSsoEnabledAndConfigured is false", () => {+ const result = getCommonEmbedSettings({+ experience: "dashboard",+ isGuestEmbedsEnabled: false,+ isSsoEnabledAndConfigured: false,+ isGuest: false,+ useExistingUserSession: false,+ });++ expect(result).toHaveProperty("useExistingUserSession", true);+ });});describe("with guest embeds enabled but state.isGuest is false", () => {@@ -181,6 +232,7 @@ describe("getCommonEmbedSettings", () => {useExistingUserSession: true,expected: {isGuest: false,+ isSso: true,useExistingUserSession: true,drills: true,},@@ -190,6 +242,7 @@ describe("getCommonEmbedSettings", () => {useExistingUserSession: false,expected: {isGuest: false,+ isSso: true,useExistingUserSession: false,},},@@ -197,9 +250,11 @@ describe("getCommonEmbedSettings", () => {"should return non-guest settings for $experience experience",({ experience, useExistingUserSession, expected }) => {const result = getCommonEmbedSettings({- state: { isGuest: false, useExistingUserSession },experience,isGuestEmbedsEnabled: true,+ isSsoEnabledAndConfigured: true,+ isGuest: false,+ useExistingUserSession,});expect(result).toEqual(expected);@@ -221,6 +276,7 @@ describe("getCommonEmbedSettings", () => {experience: "dashboard",expected: {isGuest: true,+ isSso: false,useExistingUserSession: false,drills: false,withDownloads: true,@@ -231,6 +287,7 @@ describe("getCommonEmbedSettings", () => {experience: "chart",expected: {isGuest: true,+ isSso: false,useExistingUserSession: false,drills: false,withDownloads: true,@@ -241,6 +298,7 @@ describe("getCommonEmbedSettings", () => {experience: "exploration",expected: {isGuest: false,+ isSso: true,useExistingUserSession: true,hiddenParameters: [],},@@ -249,6 +307,7 @@ describe("getCommonEmbedSettings", () => {experience: "browser",expected: {isGuest: false,+ isSso: true,useExistingUserSession: true,hiddenParameters: [],},@@ -257,6 +316,7 @@ describe("getCommonEmbedSettings", () => {experience: "metabot",expected: {isGuest: false,+ isSso: true,useExistingUserSession: true,hiddenParameters: [],},@@ -265,9 +325,11 @@ describe("getCommonEmbedSettings", () => {"should return correct settings for $experience experience",({ experience, expected }) => {const result = getCommonEmbedSettings({- state: { isGuest: false, useExistingUserSession: false },experience,isGuestEmbedsEnabled: false,+ isSsoEnabledAndConfigured: false,+ isGuest: false,+ useExistingUserSession: false,});expect(result).toEqual(expected);@@ -276,20 +338,25 @@ describe("getCommonEmbedSettings", () => {it("should ignore isGuestEmbedsEnabled parameter for dashboard/chart", () => {const resultWithTrue = getCommonEmbedSettings({- state: { isGuest: false, useExistingUserSession: false },experience: "dashboard",isGuestEmbedsEnabled: true,+ isSsoEnabledAndConfigured: false,+ isGuest: false,+ useExistingUserSession: false,});const resultWithFalse = getCommonEmbedSettings({- state: { isGuest: false, useExistingUserSession: false },experience: "dashboard",isGuestEmbedsEnabled: false,+ isSsoEnabledAndConfigured: false,+ isGuest: false,+ useExistingUserSession: false,});expect(resultWithTrue).toEqual(resultWithFalse);expect(resultWithTrue).toEqual({isGuest: true,+ isSso: false,useExistingUserSession: false,drills: false,withDownloads: true,@@ -299,23 +366,28 @@ describe("getCommonEmbedSettings", () => {it("should force withDownloads=true for dashboard/chart", () => {const result = getCommonEmbedSettings({- state: undefined,experience: "dashboard",isGuestEmbedsEnabled: true,+ isSsoEnabledAndConfigured: false,+ isGuest: false,+ useExistingUserSession: false,});expect(result).toHaveProperty("withDownloads", true);});- it("should handle undefined state", () => {+ it("should handle false for isGuest and useExistingUserSession", () => {const result = getCommonEmbedSettings({- state: undefined,experience: "chart",isGuestEmbedsEnabled: false,+ isSsoEnabledAndConfigured: false,+ isGuest: false,+ useExistingUserSession: false,});expect(result).toEqual({isGuest: true,+ isSso: false,useExistingUserSession: false,drills: false,withDownloads: true,diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-default-sdk-iframe-embed-setting.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-default-sdk-iframe-embed-setting.tsindex 2069fdc0819..adcb5b3d828 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-default-sdk-iframe-embed-setting.ts+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-default-sdk-iframe-embed-setting.ts@@ -9,7 +9,6 @@ import type {QuestionEmbedOptions,SdkIframeEmbedBaseSettings,} from "metabase/embedding/embedding-iframe-sdk/types/embed";-import type { SdkIframeEmbedSetupModalInitialState } from "metabase/plugins";import type {SdkIframeEmbedSetupExperience,@@ -19,17 +18,21 @@ import type {import { getCommonEmbedSettings } from "./get-common-embed-settings";export const getDefaultSdkIframeEmbedSettings = ({- initialState,experience,resourceId,isSimpleEmbedFeatureAvailable,isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,+ isGuest,+ useExistingUserSession,}: {- initialState: SdkIframeEmbedSetupModalInitialState | undefined;experience: SdkIframeEmbedSetupExperience;resourceId: SdkDashboardId | SdkQuestionId;isSimpleEmbedFeatureAvailable: boolean;isGuestEmbedsEnabled: boolean;+ isSsoEnabledAndConfigured: boolean;+ isGuest: boolean;+ useExistingUserSession: boolean;}): SdkIframeEmbedSetupSettings => {const baseSettingsDefaults: Partial<SdkIframeEmbedBaseSettings> = {useExistingUserSession: true,@@ -90,9 +93,11 @@ export const getDefaultSdkIframeEmbedSettings = ({...baseSettingsDefaults,...experienceSettingsDefaults,...getCommonEmbedSettings({- state: initialState,experience,isGuestEmbedsEnabled,+ isSsoEnabledAndConfigured,+ isGuest,+ useExistingUserSession,}),};};diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-default-sdk-iframe-embed-setting.unit.spec.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-default-sdk-iframe-embed-setting.unit.spec.tsindex 23720173e8c..35ce62c5d50 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-default-sdk-iframe-embed-setting.unit.spec.ts+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-default-sdk-iframe-embed-setting.unit.spec.ts@@ -15,6 +15,7 @@ const BASE_PARAMS = {resourceId: 123,isSimpleEmbedFeatureAvailable: true,isGuestEmbedsEnabled: false,+ isSsoEnabledAndConfigured: true,} as const;describe("getDefaultSdkIframeEmbedSettings", () => {@@ -66,6 +67,8 @@ describe("getDefaultSdkIframeEmbedSettings", () => {const result = getDefaultSdkIframeEmbedSettings({...BASE_PARAMS,experience,+ isGuest: false,+ useExistingUserSession: false,});expect(result).toMatchObject({@@ -83,6 +86,8 @@ describe("getDefaultSdkIframeEmbedSettings", () => {...BASE_PARAMS,experience: "dashboard",isSimpleEmbedFeatureAvailable: false,+ isGuest: false,+ useExistingUserSession: false,});expect(result.theme).toEqual({ preset: "light" });@@ -95,6 +100,8 @@ describe("getDefaultSdkIframeEmbedSettings", () => {...BASE_PARAMS,experience: "dashboard",isSimpleEmbedFeatureAvailable: true,+ isGuest: false,+ useExistingUserSession: false,});expect(result.theme).toBeUndefined();diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk/types/embed.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk/types/embed.tsindex 33af74f29c8..21174f287c6 100644--- a/frontend/src/metabase/embedding/embedding-iframe-sdk/types/embed.ts+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk/types/embed.ts@@ -189,7 +189,8 @@ export type SdkIframeEmbedBaseSettings = {_isLocalhost?: boolean;};-export type SdkIframeEmbedGuestEmbedSettings = {+export type SdkIframeEmbedAuthTypeSettings = {+ isSso: boolean;isGuest: boolean;};