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
feat(sdk-bundle, embed-js): Remove embedding subscriptions email links (#67511)
Mahatthana (Kelvin) Nomsawadi3f4e0678f5ec
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.ednindex 4901af07327..7d97dc5b3dd 100644--- a/.clj-kondo/config/modules/config.edn+++ b/.clj-kondo/config/modules/config.edn@@ -1010,6 +1010,7 @@collectionsconfigdriver+ embeddingeventslibmodelsdiff --git a/e2e/test-component/scenarios/embedding-sdk/editable-dashboard.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/editable-dashboard.cy.spec.tsxindex a2ce9d9ef1e..99773fcc691 100644--- a/e2e/test-component/scenarios/embedding-sdk/editable-dashboard.cy.spec.tsx+++ b/e2e/test-component/scenarios/embedding-sdk/editable-dashboard.cy.spec.tsx@@ -1,6 +1,7 @@const { H } = cy;import { EditableDashboard } from "@metabase/embedding-sdk-react";+import { WEBMAIL_CONFIG } from "e2e/support/cypress_data";import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";import {ORDERS_BY_YEAR_QUESTION_ID,@@ -22,6 +23,8 @@ import {createMockParameter,} from "metabase-types/api/mocks";+const { WEB_PORT } = WEBMAIL_CONFIG;+const categoryParameter = createMockParameter({id: "1b9cd9f1",name: "Category",@@ -447,4 +450,47 @@ describe("scenarios > embedding-sdk > editable-dashboard", () => {});});});++ describe("subscriptions", () => {+ beforeEach(() => {+ cy.signInAsAdmin();+ H.setupSMTP();+ const questionCard: Partial<DashboardCard> = {+ id: ORDERS_DASHBOARD_DASHCARD_ID,+ card_id: ORDERS_QUESTION_ID,+ row: 0,+ col: 0,+ size_x: 16,+ size_y: 8,+ };+ H.createDashboard({+ name: DASHBOARD_NAME,+ dashcards: [questionCard],+ parameters: [categoryParameter, textParameter, countParameter],+ }).then(({ body: dashboard }) => {+ cy.wrap(dashboard.id).as("dashboardId");+ cy.wrap(dashboard.entity_id).as("dashboardEntityId");+ });+ cy.signOut();+ });++ it("should not include links to Metabase", () => {+ cy.get<string>("@dashboardId").then((dashboardId) => {+ mountSdkContent(+ <EditableDashboard dashboardId={dashboardId} withSubscriptions />,+ );++ cy.button("Subscriptions").click();+ H.clickSend();+ const emailUrl = `http://localhost:${WEB_PORT}/email`;+ cy.request("GET", emailUrl).then(({ body }) => {+ const latest = body.slice(-1)[0];+ cy.request(`${emailUrl}/${latest.id}/html`).then(({ body }) => {+ expect(body).to.include("Embedding SDK Test Dashboard");+ expect(body).not.to.include("href=");+ });+ });+ });+ });+ });});diff --git a/e2e/test-component/scenarios/embedding-sdk/interactive-dashboard.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/interactive-dashboard.cy.spec.tsxindex 106b65b923b..39f2142e1ff 100644--- a/e2e/test-component/scenarios/embedding-sdk/interactive-dashboard.cy.spec.tsx+++ b/e2e/test-component/scenarios/embedding-sdk/interactive-dashboard.cy.spec.tsx@@ -5,6 +5,7 @@ import {} from "@metabase/embedding-sdk-react";import { useState } from "react";+import { WEBMAIL_CONFIG } from "e2e/support/cypress_data";import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";import {ORDERS_DASHBOARD_DASHCARD_ID,@@ -22,6 +23,8 @@ import type {Parameter,} from "metabase-types/api";+const { WEB_PORT } = WEBMAIL_CONFIG;+const { ORDERS } = SAMPLE_DATABASE;const DATE_FILTER: Parameter = {@@ -354,6 +357,33 @@ describe("scenarios > embedding-sdk > interactive-dashboard", () => {});});});++ describe("subscriptions", () => {+ beforeEach(() => {+ cy.signInAsAdmin();+ H.setupSMTP();+ cy.signOut();+ });++ it("should not include links to Metabase", () => {+ cy.get<string>("@dashboardId").then((dashboardId) => {+ mountSdkContent(+ <InteractiveDashboard dashboardId={dashboardId} withSubscriptions />,+ );++ cy.button("Subscriptions").click();+ H.clickSend();+ const emailUrl = `http://localhost:${WEB_PORT}/email`;+ cy.request("GET", emailUrl).then(({ body }) => {+ const latest = body.slice(-1)[0];+ cy.request(`${emailUrl}/${latest.id}/html`).then(({ body }) => {+ expect(body).to.include("Orders in a dashboard");+ expect(body).not.to.include("href=");+ });+ });+ });+ });+ });});describe("scenarios > embedding-sdk > interactive-dashboard > tabs", () => {diff --git a/e2e/test-component/scenarios/embedding-sdk/static-dashboard.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/static-dashboard.cy.spec.tsxindex 9cb1b8c912c..da28f338fee 100644--- a/e2e/test-component/scenarios/embedding-sdk/static-dashboard.cy.spec.tsx+++ b/e2e/test-component/scenarios/embedding-sdk/static-dashboard.cy.spec.tsx@@ -1,6 +1,7 @@const { H } = cy;import { StaticDashboard } from "@metabase/embedding-sdk-react";+import { WEBMAIL_CONFIG } from "e2e/support/cypress_data";import {ORDERS_DASHBOARD_DASHCARD_ID,ORDERS_QUESTION_ID,@@ -11,6 +12,8 @@ import { mountSdkContent } from "e2e/support/helpers/embedding-sdk-component-tesimport { signInAsAdminAndEnableEmbeddingSdk } from "e2e/support/helpers/embedding-sdk-testing";import { mockAuthProviderAndJwtSignIn } from "e2e/support/helpers/embedding-sdk-testing/embedding-sdk-helpers";+const { WEB_PORT } = WEBMAIL_CONFIG;+describe("scenarios > embedding-sdk > static-dashboard", () => {beforeEach(() => {signInAsAdminAndEnableEmbeddingSdk();@@ -138,4 +141,31 @@ describe("scenarios > embedding-sdk > static-dashboard", () => {});});});++ describe("subscriptions", () => {+ beforeEach(() => {+ cy.signInAsAdmin();+ H.setupSMTP();+ cy.signOut();+ });++ it("should not include links to Metabase", () => {+ cy.get<string>("@dashboardId").then((dashboardId) => {+ mountSdkContent(+ <StaticDashboard dashboardId={dashboardId} withSubscriptions />,+ );++ cy.button("Subscriptions").click();+ H.clickSend();+ const emailUrl = `http://localhost:${WEB_PORT}/email`;+ cy.request("GET", emailUrl).then(({ body }) => {+ const latest = body.slice(-1)[0];+ cy.request(`${emailUrl}/${latest.id}/html`).then(({ body }) => {+ expect(body).to.include("Embedding SDK Test Dashboard");+ expect(body).not.to.include("href=");+ });+ });+ });+ });+ });});diff --git a/e2e/test/scenarios/sharing/subscriptions.cy.spec.js b/e2e/test/scenarios/sharing/subscriptions.cy.spec.jsindex 25ee0c41916..10ca3c838ff 100644--- a/e2e/test/scenarios/sharing/subscriptions.cy.spec.js+++ b/e2e/test/scenarios/sharing/subscriptions.cy.spec.js@@ -796,6 +796,31 @@ describe("scenarios > dashboard > subscriptions", () => {.should("not.exist");});});++ describe("modular embedding", () => {+ it("should not include links to Metabase", () => {+ H.visitDashboard(ORDERS_DASHBOARD_ID);++ H.openSharingMenu();+ H.sharingMenu().findByRole("menuitem", { name: "Embed" }).click();+ cy.findByRole("button", { name: "Agree and enable" }).click();+ cy.findByLabelText("Metabase account (SSO)").click();+ cy.findByLabelText("Allow subscriptions").check().should("be.checked");+ H.getIframeBody().within(() => {+ cy.button("Subscriptions").click();+ H.sendEmailAndVisitIt();+ });++ cy.log(+ "Links should be disabled in modular embedding and modular embedding SDK subscription emails",+ );+ cy.findAllByRole("table")+ .first()+ .findByText("Orders in a dashboard")+ .should("exist");+ cy.findAllByRole("link").should("not.exist");+ });+ });});});diff --git a/enterprise/frontend/src/embedding-sdk-ee/subscriptions/DashboardSubscriptionsButton.tsx b/enterprise/frontend/src/embedding-sdk-ee/subscriptions/DashboardSubscriptionsButton.tsxindex d92d493ad88..6436b442f60 100644--- a/enterprise/frontend/src/embedding-sdk-ee/subscriptions/DashboardSubscriptionsButton.tsx+++ b/enterprise/frontend/src/embedding-sdk-ee/subscriptions/DashboardSubscriptionsButton.tsx@@ -4,6 +4,7 @@ import type { DashboardSubscriptionsButtonProps } from "embedding-sdk-bundle/comimport { ToolbarButton } from "metabase/common/components/ToolbarButton";import { useHasEmailSetup } from "metabase/common/hooks";import { toggleSharing } from "metabase/dashboard/actions";+import { useDashboardContext } from "metabase/dashboard/context";import { useDispatch } from "metabase/lib/redux";/**@@ -15,9 +16,18 @@ export const DashboardSubscriptionsButton = (const dispatch = useDispatch();const handleClick = () => dispatch(toggleSharing());+ const { dashboard } = useDashboardContext();++ /**+ * Use the same logic as in the core app+ * @see {@link https://github.com/metabase/metabase/blob/71ed90d16cb7c64946135d404c1a79ef65995f03/frontend/src/metabase/notifications/NotificationsActionsMenu/DashboardSubscriptionMenuItem.tsx#L26-L28}+ */+ const hasDataCards = dashboard?.dashcards?.some(+ (dashCard) => !["text", "heading"].includes(dashCard.card.display),+ );// We decided not to show the subscriptions button if email is not set upconst hasEmailSetup = useHasEmailSetup();- if (!hasEmailSetup) {+ if (!hasEmailSetup || !hasDataCards) {return null;}diff --git a/enterprise/frontend/src/embedding-sdk-ee/subscriptions/DashboardSubscriptionsButton.unit.spec.tsx b/enterprise/frontend/src/embedding-sdk-ee/subscriptions/DashboardSubscriptionsButton.unit.spec.tsxindex 7b650f45c64..4798b8ec586 100644--- a/enterprise/frontend/src/embedding-sdk-ee/subscriptions/DashboardSubscriptionsButton.unit.spec.tsx+++ b/enterprise/frontend/src/embedding-sdk-ee/subscriptions/DashboardSubscriptionsButton.unit.spec.tsx@@ -2,22 +2,66 @@ import { screen, waitFor } from "@testing-library/react";import {findRequests,+ setupDashboardEndpoints,+ setupDashboardQueryMetadataEndpoint,setupNotificationChannelsEndpoints,} from "__support__/server-mocks";+import { setupDashcardQueryEndpoints } from "__support__/server-mocks/dashcard";import { renderWithProviders } from "__support__/ui";+import { DashboardContextProvider } from "metabase/dashboard/context";+import type { DashboardCard } from "metabase-types/api";+import {+ createMockCard,+ createMockDashboard,+ createMockDashboardCard,+ createMockDashboardQueryMetadata,+ createMockDataset,+ createMockStructuredDatasetQuery,+} from "metabase-types/api/mocks";+import {+ ORDERS_ID,+ createSampleDatabase,+} from "metabase-types/api/mocks/presets";import { DashboardSubscriptionsButton } from "./DashboardSubscriptionsButton";+const tableCard = createMockCard({+ id: 1,+ dataset_query: createMockStructuredDatasetQuery({+ query: { "source-table": ORDERS_ID },+ }),+ name: "Here is a card title",+});+const tableDashcard = createMockDashboardCard({+ id: 1,+ card_id: tableCard.id,+ card: tableCard,+});+interface SetupOpts {+ dashcards?: DashboardCard[];emailConfigured?: boolean;}-const setup = (opts: SetupOpts = {}) => {+const setup = ({+ emailConfigured,+ dashcards = [tableDashcard],+}: SetupOpts = {}) => {setupNotificationChannelsEndpoints({email: {- configured: opts.emailConfigured,+ configured: emailConfigured,},});- renderWithProviders(<DashboardSubscriptionsButton />);++ const dashboardId = 1;+ setupDashboardRelatedEndpoints(dashboardId, dashcards);+ renderWithProviders(+ <DashboardContextProvider+ dashboardId={dashboardId}+ navigateToNewCardFromDashboard={jest.fn()}+ >+ <DashboardSubscriptionsButton />+ </DashboardContextProvider>,+ );};describe("DashboardSubscriptionsButton", () => {@@ -27,19 +71,73 @@ describe("DashboardSubscriptionsButton", () => {expect(await screen.findByRole("button", { name: "Subscriptions" }),).toBeInTheDocument();- const gets = await findRequests("GET");- expect(gets).toHaveLength(1);+ const subscriptionChannelInfoRequests =+ await getSubscriptionChannelInfoRequests();+ expect(subscriptionChannelInfoRequests).toHaveLength(1);});it("should not render the subscriptions button when email is not configured", async () => {setup({ emailConfigured: false });// Ensure the API finishes loading, otherwise, the assertion below will always pass because the API hasn't returned yetawait waitFor(async () => {- const gets = await findRequests("GET");- expect(gets).toHaveLength(1);+ expect(await getSubscriptionChannelInfoRequests()).toHaveLength(1);+ });+ expect(+ screen.queryByRole("button", { name: "Subscriptions" }),+ ).not.toBeInTheDocument();+ });++ it("should not render the subscriptions button when there are no data cards on the dashboard even when email is configured", async () => {+ setup({+ emailConfigured: true,+ dashcards: [],+ });++ // Ensure the API finishes loading, otherwise, the assertion below will always pass because the API hasn't returned yet+ await waitFor(async () => {+ expect(await getDashboardRequests()).toHaveLength(1);});expect(screen.queryByRole("button", { name: "Subscriptions" }),).not.toBeInTheDocument();});});++function setupDashboardRelatedEndpoints(+ dashboardId: number,+ dashcards: DashboardCard[],+) {+ const dashboard = createMockDashboard({+ id: dashboardId,+ name: "Test Dashboard",+ dashcards,+ });+ const database = createSampleDatabase();++ setupDashboardEndpoints(dashboard);++ setupDashboardQueryMetadataEndpoint(+ dashboard,+ createMockDashboardQueryMetadata({+ databases: [database],+ }),+ );++ setupDashcardQueryEndpoints(dashboardId, tableDashcard, createMockDataset());++ return dashboardId;+}++async function getSubscriptionChannelInfoRequests() {+ const gets = await findRequests("GET");+ return gets.filter((req) =>+ req.url.match(new RegExp("/api/pulse/form_input$")),+ );+}++async function getDashboardRequests() {+ const gets = await findRequests("GET");+ return gets.filter((req) =>+ req.url.match(new RegExp(`/api/dashboard/\\d+(?!/)`)),+ );+}diff --git a/resources/migrations/058_update_migrations.yaml b/resources/migrations/058_update_migrations.yamlindex 0c7e1067e4d..e4b12d43671 100644--- a/resources/migrations/058_update_migrations.yaml+++ b/resources/migrations/058_update_migrations.yaml@@ -1311,6 +1311,28 @@ databaseChangeLog:referencedColumnNames: idconstraintName: fk_transform_ref_target_db_id+ - changeSet:+ id: v58.2025-12-18T16:14:03+ author: winlost+ comment: Add disable_links column to pulse table+ changes:+ - addColumn:+ tableName: pulse+ columns:+ - column:+ name: disable_links+ type: ${boolean.type}+ remarks: "Whether to disable email subscription links"+ defaultValueBoolean: false+ constraints:+ nullable: true+ rollback:+ - dropColumn:+ tableName: pulse+ columnName: disable_links++# >>>>>>>>>> DO NOT ADD NEW MIGRATIONS BELOW THIS LINE! ADD THEM ABOVE <<<<<<<<<<+########################################################################################################################## ADVICE:diff --git a/src/metabase/channel/email/dashboard_subscription.hbs b/src/metabase/channel/email/dashboard_subscription.hbsindex df70c381e21..d22f9267a9c 100644--- a/src/metabase/channel/email/dashboard_subscription.hbs+++ b/src/metabase/channel/email/dashboard_subscription.hbs@@ -5,7 +5,7 @@<td><div class="container" style="background-color: white; max-width: 555px; border-radius: 24px; margin: 0 auto; padding: 30px;">{{#if context.include_branding}}- <a href="https://www.metabase.com?utm_source=product&utm_medium=export&utm_campaign=exports_branding&utm_content=dashboard_subscription">+ <a {{#unless payload.disable_links}}href="https://www.metabase.com?utm_source=product&utm_medium=export&utm_campaign=exports_branding&utm_content=dashboard_subscription"{{/unless}}><div style="text-align: right; height: 28px; margin-bottom: 16px; color: {{payload.style.color_text_dark}};"><span style="font-size: 12px; vertical-align: middle;">Made with</span><img width="22.4" height="28" src="{{context.application_logo_url}}" style="vertical-align: middle; margin-inline: 4px;"/>@@ -19,7 +19,7 @@<img class="icon" style="padding-top: 4px; padding-right: 16px; width: 100%; height: auto; max-width: 20px" src="cid:{{computed.icon_cid}}"/></td><td>- <a class="title" href="{{{dashboard-url payload.dashboard.id payload.parameters}}}" style="font-size: 20px; font-weight: 700; padding-bottom: 4px;">+ <a class="title" {{#unless payload.disable_links}}href="{{{dashboard-url payload.dashboard.id payload.parameters}}}"{{/unless}} style="font-size: 20px; font-weight: 700; padding-bottom: 4px;">{{payload.dashboard.name}}</a></td>@@ -55,13 +55,15 @@<hr>{{/unless}}{{{computed.dashboard_content}}}- <hr>- <div class="footer" style="font-size: 11px; width: max-content; margin: 0 auto">- Sent from <a href="{{context.site_url}}" style="color: {{context.application_color}}">{{context.site_url}}</a>.- {{#if computed.management_url}}- <a href="{{computed.management_url}}" style="color: {{context.application_color}}">{{computed.management_text}}</a>- {{/if}}- </div>+ {{#unless payload.disable_links}}+ <hr>+ <div class="footer" style="font-size: 11px; width: max-content; margin: 0 auto">+ Sent from <a href="{{context.site_url}}" style="color: {{context.application_color}}">{{context.site_url}}</a>.+ {{#if computed.management_url}}+ <a href="{{computed.management_url}}" style="color: {{context.application_color}}">{{computed.management_text}}</a>+ {{/if}}+ </div>+ {{/unless}}</div></td></tr>diff --git a/src/metabase/channel/impl/email.clj b/src/metabase/channel/impl/email.cljindex 3b691100353..1f31ebb0964 100644--- a/src/metabase/channel/impl/email.clj+++ b/src/metabase/channel/impl/email.clj@@ -254,7 +254,8 @@result-attachmentshtml-contents] (reduce(fn [[merged-attachments result-attachments html-contents] part]- (let [{:keys [attachments content]} (render-part timezone part {:channel.render/include-title? true})+ (let [{:keys [attachments content]} (render-part timezone part {:channel.render/include-title? true+ :channel.render/disable-links? (boolean (:disable_links dashboard_subscription))})result-attachment (email.result-attachment/result-attachment part)][(merge merged-attachments attachments)(into result-attachments result-attachment)diff --git a/src/metabase/channel/render/card.clj b/src/metabase/channel/render/card.cljindex c34bc9ae6a2..4703d5c55a2 100644--- a/src/metabase/channel/render/card.clj+++ b/src/metabase/channel/render/card.clj@@ -25,6 +25,7 @@[:channel.render/include-buttons? {:description "default: false", :optional true} :boolean][:channel.render/include-title? {:description "default: false", :optional true} :boolean][:channel.render/include-description? {:description "default: false", :optional true} :boolean]+ [:channel.render/disable-links? {:description "default: false", :optional true} :boolean][:channel.render/include-inline-parameters? {:description "default: false", :optional true} :boolean]])(defn- card-href@@ -51,10 +52,11 @@[:tr[:td {:style (style/style {:padding :0:margin :0})}- [:a {:style (style/style (style/header-style))- :href title-href- :target "_blank"- :rel "noopener noreferrer"}+ [:a (cond-> {:style (style/style (style/header-style))+ :target "_blank"+ :rel "noopener noreferrer"}+ (not (:channel.render/disable-links? options))+ (assoc :href title-href))(h card-name)]][:td {:style (style/style {:text-align :right})}(when (:channel.render/include-buttons? options)@@ -200,13 +202,14 @@;; Provide a horizontal scrollbar for tables that overflow container width.;; Surrounding <p> element prevents buggy behavior when dragging scrollbar.[:div- [:a {:href attachment-href- :target "_blank"- :rel "noopener noreferrer"- :style (style/style- (style/section-style)- {:display :block- :text-decoration :none})}+ [:a (cond-> {:target "_blank"+ :rel "noopener noreferrer"+ :style (style/style+ (style/section-style)+ {:display :block+ :text-decoration :none})}+ (not (:channel.render/disable-links? options))+ (assoc :href attachment-href))titledescription(when (seq inline-parameters)diff --git a/src/metabase/embedding/util.clj b/src/metabase/embedding/util.cljindex 5e3def8d3b7..f200c6f4cd1 100644--- a/src/metabase/embedding/util.clj+++ b/src/metabase/embedding/util.clj@@ -5,12 +5,12 @@(def ^:private embedded-analytics-js-client "embedding-simple")(defn has-react-sdk-header?- "Check if the client has indicated it is from the Embedding SDK for React "+ "Check if the client has indicated it is from the Embedding SDK for React."[request](= (get-in request [:headers "x-metabase-client"]) embedding-sdk-client))(defn has-embedded-analytics-js-header?- "Check if the client has indicated it is from modular embedding"+ "Check if the client has indicated it is from modular embedding."[request](= (get-in request [:headers "x-metabase-client"]) embedded-analytics-js-client))@@ -19,3 +19,9 @@[request](or (has-react-sdk-header? request)(has-embedded-analytics-js-header? request)))++(defn modular-embedding-or-modular-embedding-sdk-context?+ "Check if the client is in modular embedding context."+ [client]+ (or (= client embedding-sdk-client)+ (= client embedded-analytics-js-client)))diff --git a/src/metabase/notification/payload/impl/dashboard.clj b/src/metabase/notification/payload/impl/dashboard.cljindex 7c1b05ec84a..97286d57be9 100644--- a/src/metabase/notification/payload/impl/dashboard.clj+++ b/src/metabase/notification/payload/impl/dashboard.clj@@ -42,7 +42,8 @@:color_text_light channel.render/color-text-light:color_text_medium channel.render/color-text-medium}:parameters parameters- :dashboard_subscription dashboard_subscription})))+ :dashboard_subscription dashboard_subscription+ :disable_links (:disable_links dashboard_subscription)})))(mu/defmethod notification.payload/skip-reason :notification/dashboard[{:keys [payload] :as _noti-payload}]diff --git a/src/metabase/pulse/api/pulse.clj b/src/metabase/pulse/api/pulse.cljindex 190d8cdf81b..09505ca87f6 100644--- a/src/metabase/pulse/api/pulse.clj+++ b/src/metabase/pulse/api/pulse.clj@@ -18,6 +18,7 @@[metabase.classloader.core :as classloader][metabase.collections.models.collection :as collection][metabase.config.core :as config]+ [metabase.embedding.util :as embed.util][metabase.events.core :as events][metabase.models.interface :as mi][metabase.notification.core :as notification]@@ -159,7 +160,8 @@[:collection_id {:optional true} [:maybe ms/PositiveInt]][:collection_position {:optional true} [:maybe ms/PositiveInt]][:dashboard_id {:optional true} [:maybe ms/PositiveInt]]- [:parameters {:optional true} [:maybe [:sequential :map]]]]]+ [:parameters {:optional true} [:maybe [:sequential :map]]]]+ request](perms/check-has-application-permission :subscription false)(let [pulse-data {:name name:creator_id api/*current-user-id*@@ -167,7 +169,9 @@:collection_id collection-id:collection_position collection-position:dashboard_id dashboard-id- :parameters parameters}]+ :parameters parameters+ :disable_links (embed.util/modular-embedding-or-modular-embedding-sdk-context?+ (get-in request [:headers "x-metabase-client"]))}](api/create-check :model/Pulse (assoc pulse-data :cards cards))(t2/with-transaction [_conn];; Adding a new pulse at `collection_position` could cause other pulses in this collection to change position,@@ -439,9 +443,11 @@[:cards [:+ models.pulse/CoercibleToCardRef]][:channels [:+ :map]][:skip_if_empty {:default false} [:maybe :boolean]]+ [:disable_links {:default false} [:maybe :boolean]][:collection_id {:optional true} [:maybe ms/PositiveInt]][:collection_position {:optional true} [:maybe ms/PositiveInt]]- [:dashboard_id {:optional true} [:maybe ms/PositiveInt]]]]+ [:dashboard_id {:optional true} [:maybe ms/PositiveInt]]]+ request];; Check permissions on cards that exist. Placeholders and iframes don't matter.(check-card-read-permissions(remove (fn [{:keys [id display]}]@@ -452,7 +458,11 @@(doseq [channel channels](pulse-channel/validate-email-domains channel))(notification/with-default-options {:notification/sync? true}- (pulse.send/send-pulse! (assoc body :creator_id api/*current-user-id*)))+ (pulse.send/send-pulse! (-> body+ (assoc :creator_id api/*current-user-id*)+ (assoc :disable_links+ (embed.util/modular-embedding-or-modular-embedding-sdk-context?+ (get-in request [:headers "x-metabase-client"])))))){:ok true});; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers todiff --git a/src/metabase/pulse/models/pulse.clj b/src/metabase/pulse/models/pulse.cljindex d2862b1aabf..e5bc1c6ba4e 100644--- a/src/metabase/pulse/models/pulse.clj+++ b/src/metabase/pulse/models/pulse.clj@@ -324,7 +324,10 @@[notification :- (ms/InstanceOf :model/Pulse)](-> notification(assoc :card (first (:cards notification)))- (dissoc :cards)))+ (dissoc :cards)+ ;; TODO (Kelvin 2025-12-19) Remove this once we support alerts on modular embedding,+ ;; as we only currently have `disable_links` column on Subscriptions.+ (dissoc :disable_links)))(mu/defn retrieve-alert :- [:maybe (ms/InstanceOf :model/Pulse)]"Fetch a single Alert by its `id` value, do the standard hydrations, and put it in the standard `Alert` format."@@ -541,7 +544,8 @@[:collection_id {:optional true} [:maybe ms/PositiveInt]][:collection_position {:optional true} [:maybe ms/PositiveInt]][:dashboard_id {:optional true} [:maybe ms/PositiveInt]]- [:parameters {:optional true} [:maybe [:sequential :map]]]]]+ [:parameters {:optional true} [:maybe [:sequential :map]]]+ [:disable_links {:optional true} [:maybe ms/BooleanValue]]]](let [pulse-id (create-notification-and-add-cards-and-channels! kvs cards channels)];; return the full Pulse (and record our create event).(u/prog1 (retrieve-pulse pulse-id)diff --git a/src/metabase/pulse/send.clj b/src/metabase/pulse/send.cljindex 3d6f5c2fbd8..15dac27c6c7 100644--- a/src/metabase/pulse/send.clj+++ b/src/metabase/pulse/send.clj@@ -67,6 +67,7 @@:dashboard_id (:id dashboard):parameters (:parameters pulse):skip_if_empty (:skip_if_empty pulse)+ :disable_links (:disable_links pulse):dashboard_subscription_dashcards (map#(merge {:card_id (:id %):dashboard_card_id (:dashboard_card_id %)}diff --git a/test/metabase/pulse/api/pulse_test.clj b/test/metabase/pulse/api/pulse_test.cljindex 2390ae34791..aea0456403f 100644--- a/test/metabase/pulse/api/pulse_test.clj+++ b/test/metabase/pulse/api/pulse_test.clj@@ -54,7 +54,7 @@(select-keyspulse[:id :name :created_at :updated_at :creator_id :collection_id :collection_position :entity_id :archived- :skip_if_empty :dashboard_id :parameters])+ :skip_if_empty :dashboard_id :parameters :disable_links]){:creator (user-details (t2/select-one 'User :id (:creator_id pulse))):cards (map pulse-card-details (:cards pulse)):channels (map pulse-channel-details (:channels pulse))}))@@ -164,7 +164,8 @@:archived false:dashboard_id nil:entity_id true- :parameters []})+ :parameters []+ :disable_links false})(def ^:private daily-email-channel{:enabled truediff --git a/test/metabase/pulse/dashboard_subscription_test.clj b/test/metabase/pulse/dashboard_subscription_test.cljindex a9f6b775259..1cae236f7b3 100644--- a/test/metabase/pulse/dashboard_subscription_test.clj+++ b/test/metabase/pulse/dashboard_subscription_test.clj@@ -1168,6 +1168,39 @@:channel/email first :message first :content(re-find #"<h1>dashboard description</h1>")))))))+(deftest dashboard-disable-links-test+ (testing "Dashboard with links disabled"+ (mt/with-temp [:model/Card {card-id :id} {:name "Test card"+ :dataset_query {:database (mt/id)+ :type :native+ :native {:query "select * from orders limit 1"}}+ :display :table}+ :model/Dashboard {dashboard-id :id} {:name "dashboard subscription with disabled links"}+ :model/DashboardCard {dashboard-card-id :id} {:dashboard_id dashboard-id+ :card_id card-id}+ :model/Pulse {pulse-id :id} {:name "Pulse Name"+ :dashboard_id dashboard-id+ :disable_links true}+ :model/PulseCard _ {:pulse_id pulse-id+ :card_id card-id+ :dashboard_card_id dashboard-card-id}+ :model/PulseChannel {pc-id :id} {:pulse_id pulse-id}+ :model/PulseChannelRecipient _ {:user_id (pulse.test-util/rasta-id)+ :pulse_channel_id pc-id}]+ (let [pulse (t2/select-one :model/Pulse pulse-id)+ has-link? (fn [pulse]+ (->> (pulse.test-util/with-captured-channel-send-messages!+ (pulse.send/send-pulse! pulse))+ :channel/email first :message first :content+ (re-find #"href=")+ (= "href=")))]+ (testing "test that disable_links: false will keep links in the email subscription"+ (is (true? (has-link? (assoc pulse :disable_links false)))))+ (testing "test that disable_links: nil will keep links in the email subscription"+ (is (true? (has-link? (assoc pulse :disable_links nil)))))+ (testing "test that disable_links: true will disable all links in the email subscription"+ (is (false? (has-link? pulse))))))))+(deftest attachments-test(tests!{:card (pulse.test-util/checkins-query-card {})}diff --git a/test/metabase/pulse/models/pulse_test.clj b/test/metabase/pulse/models/pulse_test.cljindex 35978c80e01..b408a6fc6d1 100644--- a/test/metabase/pulse/models/pulse_test.clj+++ b/test/metabase/pulse/models/pulse_test.clj@@ -52,7 +52,8 @@:dashboard_id nil:skip_if_empty false:archived false- :parameters []})+ :parameters []+ :disable_links false})(deftest retrieve-pulse-test(testing "this should cover all the basic Pulse attributes"