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
GDGT-1933 Dashboard actions prefetch sends parameter values in URL query string (#77939)
Kamil Mielnik70abeae73341
diff --git a/.clj-kondo/ratchets.edn b/.clj-kondo/ratchets.ednindex 0ad9849f5cb..d1e05ec5329 100644--- a/.clj-kondo/ratchets.edn+++ b/.clj-kondo/ratchets.edn@@ -24,7 +24,7 @@:metabase/namespace-name 4:metabase/prefer-with-dynamic-fn-redefs 25:metabase/test-helpers-use-non-thread-safe-functions 17- :metabase/validate-defendpoint-has-response-schema 444+ :metabase/validate-defendpoint-has-response-schema 441:metabase/validate-defendpoint-query-params-use-kebab-case 40:metabase/validate-defendpoint-route-uses-kebab-case 44:metabase/validate-deftest 8diff --git a/docs/developers-guide/api-changelog.md b/docs/developers-guide/api-changelog.mdindex e45fc0f8094..269db2f5389 100644--- a/docs/developers-guide/api-changelog.md+++ b/docs/developers-guide/api-changelog.md@@ -8,6 +8,16 @@ title: API changelog- Self-hosted environments must now explicitly enable transforms before beginning to use them via the API. Admins can enable transforms in Data Studio or by setting the MB_TRANSFORMS_ENABLED environment variable to true.+- The endpoints that fetch prefill values for action forms have been converted from GET to POST so that parameter values are sent in the JSON request body instead of the URL query string. `parameters` is now a JSON object in the request body rather than a JSON-encoded query-string parameter:++ - `GET /api/action/:action-id/execute` has been replaced by `POST /api/action/:action-id/execute/values`.+ - `GET /api/dashboard/:dashboard-id/dashcard/:dashcard-id/execute` has been replaced by+ `POST /api/dashboard/:dashboard-id/dashcard/:dashcard-id/execute/values`.+ - `GET /api/public/dashboard/:uuid/dashcard/:dashcard-id/execute` has been replaced by+ `POST /api/public/dashboard/:uuid/dashcard/:dashcard-id/execute/values`.++ The GET variants have been removed without a deprecation period.+## Metabase 0.61.0- `POST /api/metabot/describe/card` and `POST /api/metabot/describe/dashboard/:id` have been removed. These endpointsdiff --git a/e2e/test/scenarios/actions/actions-in-object-detail-view.cy.spec.js b/e2e/test/scenarios/actions/actions-in-object-detail-view.cy.spec.jsindex 30f299b204b..edaad373f55 100644--- a/e2e/test/scenarios/actions/actions-in-object-detail-view.cy.spec.js+++ b/e2e/test/scenarios/actions/actions-in-object-detail-view.cy.spec.js@@ -24,9 +24,7 @@ describe(beforeEach(() => {cy.intercept("GET", "/api/action?model-id=*").as("getModelActions");cy.intercept("POST", "/api/action/*/execute").as("executeAction");- cy.intercept("GET", "/api/action/*/execute?parameters=*").as(- "prefetchValues",- );+ cy.intercept("POST", "/api/action/*/execute/values").as("prefetchValues");H.restore("postgres-writable");H.resetTestTable({ type: "postgres", table: WRITABLE_TEST_TABLE });diff --git a/e2e/test/scenarios/actions/actions-on-dashboards.cy.spec.js b/e2e/test/scenarios/actions/actions-on-dashboards.cy.spec.jsindex 7fba662b5a5..27d761f8dbc 100644--- a/e2e/test/scenarios/actions/actions-on-dashboards.cy.spec.js+++ b/e2e/test/scenarios/actions/actions-on-dashboards.cy.spec.js@@ -22,10 +22,9 @@ const MODEL_NAME = "Test Action Model";cy.intercept("PUT", "/api/action/*").as("updateAction");cy.intercept("GET", "/api/action?model-id=*").as("getModelActions");- cy.intercept(- "GET",- "/api/dashboard/*/dashcard/*/execute?parameters=*",- ).as("prefetchValues");+ cy.intercept("POST", "/api/dashboard/*/dashcard/*/execute/values").as(+ "prefetchValues",+ );cy.intercept("POST", "/api/dashboard/*/dashcard/*/execute").as("executeAction",@@ -1086,7 +1085,7 @@ describe("action error handling", { tags: ["@external", "@actions"] }, () => {cy.intercept("GET", "/api/action").as("getActions");cy.intercept("GET", /\/api\/card\/\d+/).as("getModel");- cy.intercept("GET", "/api/dashboard/*/dashcard/*/execute?parameters=*").as(+ cy.intercept("POST", "/api/dashboard/*/dashcard/*/execute/values").as("prefetchValues",);cy.intercept("POST", "/api/dashboard/*/dashcard/*/execute").as(@@ -1137,10 +1136,9 @@ describe(cy.intercept("PUT", "/api/action/*").as("updateAction");cy.intercept("GET", "/api/action?model-id=*").as("getModelActions");- cy.intercept(- "GET",- "/api/dashboard/*/dashcard/*/execute?parameters=*",- ).as("executePrefetch");+ cy.intercept("POST", "/api/dashboard/*/dashcard/*/execute/values").as(+ "executePrefetch",+ );});describe("Inline action edit", () => {diff --git a/e2e/test/scenarios/actions/actions-reproductions.cy.spec.js b/e2e/test/scenarios/actions/actions-reproductions.cy.spec.jsindex 29b2cb2e46d..5d94fdae45c 100644--- a/e2e/test/scenarios/actions/actions-reproductions.cy.spec.js+++ b/e2e/test/scenarios/actions/actions-reproductions.cy.spec.js@@ -210,9 +210,7 @@ describe("Issue 32974", { tags: ["@external", "@actions"] }, () => {beforeEach(() => {cy.intercept("GET", "/api/action?model-id=*").as("getModelActions");cy.intercept("POST", "/api/action/*/execute").as("executeAction");- cy.intercept("GET", "/api/action/*/execute?parameters=*").as(- "prefetchValues",- );+ cy.intercept("POST", "/api/action/*/execute/values").as("prefetchValues");H.restore("postgres-writable");H.resetTestTable({ type: "postgres", table: TEST_TABLE });diff --git a/frontend/src/metabase-types/api/actions.ts b/frontend/src/metabase-types/api/actions.tsindex b5777e292b3..50ce2a4262b 100644--- a/frontend/src/metabase-types/api/actions.ts+++ b/frontend/src/metabase-types/api/actions.ts@@ -235,6 +235,12 @@ export interface PrefetchDashcardValuesRequest {parameters: ParametersForActionExecution;}+export interface PrefetchPublicDashcardValuesRequest {+ dashboardId: DashboardId;+ dashcardId: DashCardId;+ parameters: ParametersForActionExecution;+}+export type ActionExecutionResult = Record<string, unknown>;export type GetPublicAction = Pick<WritebackActionBase,diff --git a/frontend/src/metabase/actions/containers/ActionExecuteModal/ActionExecuteModal.unit.spec.tsx b/frontend/src/metabase/actions/containers/ActionExecuteModal/ActionExecuteModal.unit.spec.tsxindex 9da8248c56f..8dd1a1ca2a6 100644--- a/frontend/src/metabase/actions/containers/ActionExecuteModal/ActionExecuteModal.unit.spec.tsx+++ b/frontend/src/metabase/actions/containers/ActionExecuteModal/ActionExecuteModal.unit.spec.tsx@@ -1,7 +1,9 @@-import fetchMock from "fetch-mock";import { useCallback } from "react";-import { setupActionsEndpoints } from "__support__/server-mocks";+import {+ setupActionsEndpoints,+ setupPrefetchActionValuesEndpoint,+} from "__support__/server-mocks";import {renderWithProviders,screen,@@ -37,13 +39,6 @@ const implicitUpdateAction = createMockImplicitQueryAction({parameters: [parameter1, parameter2],});-function setupPrefetch() {- fetchMock.get(`path:/api/action/${implicitUpdateAction.id}/execute`, {- parameter_1: "uno",- parameter_2: "dos",- });-}-function TestActionExecuteModal(props?: Partial<ActionExecuteModalProps>) {const dispatch = useDispatch();const fetchInitialValues = useCallback(@@ -69,7 +64,10 @@ function TestActionExecuteModal(props?: Partial<ActionExecuteModalProps>) {function setup(props?: Partial<ActionExecuteModalProps>) {setupActionsEndpoints([implicitUpdateAction]);- setupPrefetch();+ setupPrefetchActionValuesEndpoint(implicitUpdateAction.id, {+ parameter_1: "uno",+ parameter_2: "dos",+ });renderWithProviders(<TestActionExecuteModal {...props} />);}diff --git a/frontend/src/metabase/actions/containers/ActionParametersInputForm/ActionParametersInputForm.unit.spec.tsx b/frontend/src/metabase/actions/containers/ActionParametersInputForm/ActionParametersInputForm.unit.spec.tsxindex 672c353fcd8..58e4026ddfd 100644--- a/frontend/src/metabase/actions/containers/ActionParametersInputForm/ActionParametersInputForm.unit.spec.tsx+++ b/frontend/src/metabase/actions/containers/ActionParametersInputForm/ActionParametersInputForm.unit.spec.tsx@@ -1,7 +1,7 @@import userEvent from "@testing-library/user-event";-import fetchMock from "fetch-mock";import _ from "underscore";+import { setupPrefetchDashcardValuesEndpoint } from "__support__/server-mocks";import { getIcon, render, screen, waitFor } from "__support__/ui";import {createMockActionParameter,@@ -69,13 +69,6 @@ async function setupModal(options?: Partial<ActionParametersInputModalProps>) {);}-function setupPrefetch() {- fetchMock.get("path:/api/dashboard/123/dashcard/456/execute", {- parameter_1: "uno",- parameter_2: "dos",- });-}-describe("Actions > ActionParametersInputForm", () => {it("should render an action form", async () => {await setup();@@ -157,7 +150,10 @@ describe("Actions > ActionParametersInputForm", () => {});it('should change the submit button label to "update" for an implicit update action', async () => {- setupPrefetch();+ setupPrefetchDashcardValuesEndpoint(123, 456, {+ parameter_1: "uno",+ parameter_2: "dos",+ });await setup({action: createMockImplicitQueryAction({diff --git a/frontend/src/metabase/api/action.ts b/frontend/src/metabase/api/action.tsindex 450cc727305..7061d4b4b40 100644--- a/frontend/src/metabase/api/action.ts+++ b/frontend/src/metabase/api/action.ts@@ -152,9 +152,9 @@ export const actionApi = Api.injectEndpoints({PrefetchActionValuesRequest>({query: ({ id, parameters }) => ({- method: "GET",- url: `/api/action/${id}/execute`,- params: { parameters: JSON.stringify(parameters) },+ method: "POST",+ url: `/api/action/${id}/execute/values`,+ body: { parameters },}),// Prefetch is an imperative fetch-and-discard with row-specific params// that rarely repeat, so there's nothing to gain from caching entries.@@ -175,9 +175,9 @@ export const actionApi = Api.injectEndpoints({PrefetchDashcardValuesRequest>({query: ({ dashboardId, dashcardId, parameters }) => ({- method: "GET",- url: `/api/dashboard/${dashboardId}/dashcard/${dashcardId}/execute`,- params: { parameters: JSON.stringify(parameters) },+ method: "POST",+ url: `/api/dashboard/${dashboardId}/dashcard/${dashcardId}/execute/values`,+ body: { parameters },}),// Prefetch is an imperative fetch-and-discard with per-dashcard params// that rarely repeat, so there's nothing to gain from caching entries.diff --git a/frontend/src/metabase/api/public.ts b/frontend/src/metabase/api/public.tsindex 9daf483e07f..0b21aa76ca0 100644--- a/frontend/src/metabase/api/public.ts+++ b/frontend/src/metabase/api/public.ts@@ -8,6 +8,7 @@ import type {Dataset,Document,ParametersForActionExecution,+ PrefetchPublicDashcardValuesRequest,WritebackAction,} from "metabase-types/api";@@ -42,13 +43,6 @@ export type ExecutePublicDashcardActionRequest = {parameters: ParametersForActionExecution;};-export type PrefetchPublicDashcardValuesRequest = {- dashboardId: DashboardId;- dashcardId: DashCardId;- // Already JSON-stringified by the caller and passed through the query string.- parameters?: string;-};-export type PublicCardQueryRequest = {uuid: string;// `parameters` is JSON-stringified because public links apply parameters@@ -127,10 +121,10 @@ export const publicApi = Api.injectEndpoints({ParametersForActionExecution,PrefetchPublicDashcardValuesRequest>({- query: ({ dashboardId, dashcardId, ...params }) => ({- method: "GET",- url: `/api/public/dashboard/${dashboardId}/dashcard/${dashcardId}/execute`,- params,+ query: ({ dashboardId, dashcardId, parameters }) => ({+ method: "POST",+ url: `/api/public/dashboard/${dashboardId}/dashcard/${dashcardId}/execute/values`,+ body: { parameters },}),keepUnusedDataFor: 0,}),diff --git a/frontend/src/metabase/dashboard/components/ActionViz/Action.unit.spec.tsx b/frontend/src/metabase/dashboard/components/ActionViz/Action.unit.spec.tsxindex 7499670e79f..209c7fc9a50 100644--- a/frontend/src/metabase/dashboard/components/ActionViz/Action.unit.spec.tsx+++ b/frontend/src/metabase/dashboard/components/ActionViz/Action.unit.spec.tsx@@ -5,6 +5,7 @@ import {setupActionEndpoints,setupCardsEndpoints,setupDatabasesEndpoints,+ setupPrefetchDashcardValuesEndpoint,} from "__support__/server-mocks";import { createMockEntitiesState } from "__support__/store";import {@@ -132,7 +133,7 @@ async function setup({const card = checkNotNull(dashcard.card);if (getActionIsEnabledInDatabase(dashcard)) {- fetchMock.get(ACTION_EXEC_MOCK_PATH, {});+ setupPrefetchDashcardValuesEndpoint(DASHBOARD_ID, DASHCARD_ID, {});fetchMock.post(ACTION_EXEC_MOCK_PATH, { "rows-updated": 1 });// for ActionCreator modal (action edit modal)diff --git a/frontend/src/metabase/dashboard/components/ActionViz/ActionVizForm.tsx b/frontend/src/metabase/dashboard/components/ActionViz/ActionVizForm.tsxindex 1543111cd1b..187aa867649 100644--- a/frontend/src/metabase/dashboard/components/ActionViz/ActionVizForm.tsx+++ b/frontend/src/metabase/dashboard/components/ActionViz/ActionVizForm.tsx@@ -95,17 +95,7 @@ function ActionVizForm({return {};}- if (getDashboardType(dashboard.id) === "public") {- return runRtkEndpoint(- {- dashboardId: dashboard.id,- dashcardId: dashcard.id,- parameters: JSON.stringify(dashcardParamValues),- },- dispatch,- publicApi.endpoints.prefetchPublicDashcardValues,- );- }+ const isPublic = getDashboardType(dashboard.id) === "public";return runRtkEndpoint({@@ -114,7 +104,9 @@ function ActionVizForm({parameters: dashcardParamValues,},dispatch,- actionApi.endpoints.prefetchDashcardValues,+ isPublic+ ? publicApi.endpoints.prefetchPublicDashcardValues+ : actionApi.endpoints.prefetchDashcardValues,);}, [dashboard.id, dashcard.id, dashcardParamValues, dispatch]);diff --git a/frontend/src/metabase/dashboard/components/ActionViz/ActionVizForm.unit.spec.tsx b/frontend/src/metabase/dashboard/components/ActionViz/ActionVizForm.unit.spec.tsxindex 7ab7251e130..c11d079266f 100644--- a/frontend/src/metabase/dashboard/components/ActionViz/ActionVizForm.unit.spec.tsx+++ b/frontend/src/metabase/dashboard/components/ActionViz/ActionVizForm.unit.spec.tsx@@ -1,6 +1,6 @@import userEvent from "@testing-library/user-event";-import fetchMock from "fetch-mock";+import { setupPrefetchDashcardValuesEndpoint } from "__support__/server-mocks";import { renderWithProviders, screen, waitFor } from "__support__/ui";import {createMockActionDashboardCard,@@ -54,16 +54,6 @@ const dashcard = createMockActionDashboardCard();const dashboard = createMockDashboard();-function setupPrefetch() {- fetchMock.get(- `path:/api/dashboard/${dashboard.id}/dashcard/${dashcard.id}/execute`,- {- parameter_1: "uno",- parameter_2: "dos",- },- );-}-const defaultProps: ActionFormProps = {action: mockAction,dashcard,@@ -82,7 +72,10 @@ const defaultProps: ActionFormProps = {};function setup(options?: Partial<ActionFormProps>) {- setupPrefetch();+ setupPrefetchDashcardValuesEndpoint(dashboard.id, dashcard.id, {+ parameter_1: "uno",+ parameter_2: "dos",+ });renderWithProviders(<ActionVizForm {...defaultProps} {...options} />);}diff --git a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailPanel.unit.spec.tsx b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailPanel.unit.spec.tsxindex ce94779a61c..d0e3885645d 100644--- a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailPanel.unit.spec.tsx+++ b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailPanel.unit.spec.tsx@@ -1,11 +1,11 @@import userEvent from "@testing-library/user-event";-import fetchMock from "fetch-mock";import { createMockMetadata } from "__support__/metadata";import {setupActionsEndpoints,setupCardDataset,setupDatabasesEndpoints,+ setupPrefetchActionValuesEndpoint,} from "__support__/server-mocks";import { testDataset } from "__support__/testDataset";import { renderWithProviders, screen, waitFor, within } from "__support__/ui";@@ -234,10 +234,6 @@ const actionsFromDatabaseWithDisabledActions = actions.map((action) => ({database_id: databaseWithActionsDisabled.id,}));-function setupPrefetch() {- fetchMock.get(`path:/api/action/${implicitUpdateAction.id}/execute`, {});-}-function setup(options: Partial<ObjectDetailProps> &Required<Pick<ObjectDetailProps, "question">>,@@ -476,7 +472,7 @@ describe("ObjectDetailPanel", () => {setupDatabasesEndpoints([databaseWithActionsEnabled]);setupActionsEndpoints(actions);setup({ question: mockDataset });- setupPrefetch();+ setupPrefetchActionValuesEndpoint(implicitUpdateAction.id, {});expect(screen.queryByTestId("action-execute-modal"),diff --git a/frontend/test/__support__/server-mocks/action.ts b/frontend/test/__support__/server-mocks/action.tsindex e1f813a87f5..cb1426452b2 100644--- a/frontend/test/__support__/server-mocks/action.ts+++ b/frontend/test/__support__/server-mocks/action.ts@@ -2,8 +2,12 @@ import fetchMock from "fetch-mock";import type {CardId,+ DashCardId,+ DashboardId,GetPublicAction,+ ParametersForActionExecution,WritebackAction,+ WritebackActionId,} from "metabase-types/api";import {createMockImplicitQueryAction,@@ -64,3 +68,21 @@ export function setupListPublicActionsEndpoint() {fetchMock.get("path:/api/action/public", publicActions);}++export function setupPrefetchActionValuesEndpoint(+ actionId: WritebackActionId,+ values: ParametersForActionExecution,+) {+ fetchMock.post(`path:/api/action/${actionId}/execute/values`, values);+}++export function setupPrefetchDashcardValuesEndpoint(+ dashboardId: DashboardId,+ dashcardId: DashCardId,+ values: ParametersForActionExecution,+) {+ fetchMock.post(+ `path:/api/dashboard/${dashboardId}/dashcard/${dashcardId}/execute/values`,+ values,+ );+}diff --git a/src/metabase/actions_rest/api.clj b/src/metabase/actions_rest/api.cljindex 8aee2396097..5ba649ff060 100644--- a/src/metabase/actions_rest/api.clj+++ b/src/metabase/actions_rest/api.clj@@ -14,7 +14,6 @@[metabase.queries.core :as queries][metabase.util :as u][metabase.util.i18n :refer [tru]]- [metabase.util.json :as json][metabase.util.malli.schema :as ms][toucan2.core :as t2]))@@ -183,20 +182,19 @@(t2/update! :model/Action id {:public_uuid nil, :made_public_by_id nil}){:status 204, :body nil})-;; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to-;; use our API + we will need it when we make auto-TypeScript-signature generation happen-;;-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}-(api.macros/defendpoint :get "/:action-id/execute"- "Fetches the values for filling in execution parameters. Pass PK parameters and values to select."+(api.macros/defendpoint :post "/:action-id/execute/values" :- [:map-of :string :any]+ "Fetches the values for filling in execution parameters. Pass PK parameters and values to select.++ Parameters are sent in the request body rather than the query string so their values stay out of URLs and logs."[{:keys [action-id]} :- [:map[:action-id ms/PositiveInt]]+ _query-params{:keys [parameters]} :- [:map- [:parameters ms/JSONString]]]+ [:parameters [:map-of :string :any]]]](actions/check-actions-enabled! action-id)(-> (actions/select-action :id action-id :archived false)api/read-check- (actions/fetch-values (json/decode parameters))))+ (actions/fetch-values parameters)))(defn- remap-parameter-keys"Translate incoming `parameters` keys to the destination parameter `:id` thediff --git a/src/metabase/dashboards_rest/api.clj b/src/metabase/dashboards_rest/api.cljindex a928bbac260..f48c5cb9ac3 100644--- a/src/metabase/dashboards_rest/api.clj+++ b/src/metabase/dashboards_rest/api.clj@@ -1392,21 +1392,20 @@;;; ---------------------------------- Executing the action associated with a Dashcard --------------------------------;; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to-;; use our API + we will need it when we make auto-TypeScript-signature generation happen-;;-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}-(api.macros/defendpoint :get "/:dashboard-id/dashcard/:dashcard-id/execute"- "Fetches the values for filling in execution parameters. Pass PK parameters and values to select."+(api.macros/defendpoint :post "/:dashboard-id/dashcard/:dashcard-id/execute/values" :- [:map-of :string :any]+ "Fetches the values for filling in execution parameters. Pass PK parameters and values to select.++ Parameters are sent in the request body rather than the query string so their values stay out of URLs and logs."[{:keys [dashboard-id dashcard-id]} :- [:map[:dashboard-id ms/PositiveInt][:dashcard-id ms/PositiveInt]]+ _query-params{:keys [parameters]} :- [:map- [:parameters {:optional true} ms/JSONString]]]+ [:parameters {:optional true} [:maybe [:map-of :string :any]]]]](api/read-check :model/Dashboard dashboard-id)(actions/fetch-values(api/check-404 (actions/dashcard->action dashcard-id))- (json/decode parameters)))+ parameters));; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to;; use our API + we will need it when we make auto-TypeScript-signature generation happendiff --git a/src/metabase/public_sharing_rest/api.clj b/src/metabase/public_sharing_rest/api.cljindex 306095ef1fe..6683f4bd3a4 100644--- a/src/metabase/public_sharing_rest/api.clj+++ b/src/metabase/public_sharing_rest/api.clj@@ -383,23 +383,22 @@:format-rows? format_rows:pivot? pivot_results}))))-;; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to-;; use our API + we will need it when we make auto-TypeScript-signature generation happen-;;-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}-(api.macros/defendpoint :get "/dashboard/:uuid/dashcard/:dashcard-id/execute"- "Fetches the values for filling in execution parameters. Pass PK parameters and values to select."+(api.macros/defendpoint :post "/dashboard/:uuid/dashcard/:dashcard-id/execute/values" :- [:map-of :string :any]+ "Fetches the values for filling in execution parameters. Pass PK parameters and values to select.++ Parameters are sent in the request body rather than the query string so their values stay out of URLs and logs."[{:keys [uuid dashcard-id]} :- [:map[:uuid ms/UUIDString][:dashcard-id ms/PositiveInt]]+ _query-params{:keys [parameters]} :- [:map- [:parameters ms/JSONString]]]+ [:parameters [:map-of :string :any]]]](public-sharing.validation/check-public-sharing-enabled)(let [dashboard-id (api/check-404 (t2/select-one-pk :model/Dashboard :public_uuid uuid :archived false))](api/check-404 (t2/select-one-pk :model/DashboardCard :id dashcard-id :dashboard_id dashboard-id))(actions/fetch-values(api/check-404 (actions/dashcard->action dashcard-id))- (json/decode parameters))))+ parameters)))(def ^:private dashcard-execution-throttle (throttle/make-throttler :dashcard-id :attempts-threshold 5000))diff --git a/test/metabase/actions_rest/api_test.clj b/test/metabase/actions_rest/api_test.cljindex 46802c5bef5..63be18690a9 100644--- a/test/metabase/actions_rest/api_test.clj+++ b/test/metabase/actions_rest/api_test.clj@@ -14,7 +14,6 @@[metabase.test :as mt][metabase.test.fixtures :as fixtures][metabase.util :as u]- [metabase.util.json :as json][metabase.util.malli.schema :as ms][toucan2.core :as t2]))@@ -678,7 +677,7 @@:visualization_settings {:fields {"name" {:id "name":hidden true}}}}](testing "Hidden parameter should fail gracefully"- (testing "GET /api/action/:id/execute"+ (testing "POST /api/action/:id/execute"(is (partial= {:message "No destination parameter found for #{\"name\"}. Found: #{\"last_login\" \"id\"}"}(mt/user-http-request :crowberto :post 400 (format "action/%s/execute" action-id){:parameters {:name "Darth Vader"}})))))))))@@ -690,8 +689,8 @@(mt/with-actions [_ {:type :model :dataset_query (mt/mbql-query users)}{action-id :action-id} {:type :implicit :kind "row/update"}](testing "a prefetched temporal value round-trips unchanged through an update execution (#32840)"- (let [fetch! #(mt/user-http-request :crowberto :get 200 (format "action/%d/execute" action-id)- :parameters (json/encode {:id 1}))+ (let [fetch! #(mt/user-http-request :crowberto :post 200 (format "action/%d/execute/values" action-id)+ {:parameters {"id" 1}}){:keys [last_login] :as fetched} (fetch!)local-value (.format ^java.time.OffsetDateTime last_login(java.time.format.DateTimeFormatter/ofPattern "yyyy-MM-dd'T'HH:mm:ss"))]@@ -711,26 +710,26 @@{query-action-id :action-id} {:type :query}](testing "403 if user does not have permission to view the action"(is (= "You don't have permissions to do that."- (mt/user-http-request :rasta :get 403 (format "action/%d/execute" update-action-id) :parameters (json/encode {:id 1})))))+ (mt/user-http-request :rasta :post 403 (format "action/%d/execute/values" update-action-id) {:parameters {"id" 1}}))))(testing "404 if id does not exist"(is (= "Not found."- (mt/user-http-request :rasta :get 404 (format "action/%d/execute" Integer/MAX_VALUE) :parameters (json/encode {:id 1})))))+ (mt/user-http-request :rasta :post 404 (format "action/%d/execute/values" Integer/MAX_VALUE) {:parameters {"id" 1}}))))(testing "returns empty map for query actions (not implicit)"(is (= {}- (mt/user-http-request :crowberto :get 200 (format "action/%d/execute" query-action-id) :parameters (json/encode {:id 1})))))+ (mt/user-http-request :crowberto :post 200 (format "action/%d/execute/values" query-action-id) {:parameters {"id" 1}}))))(testing "Can't fetch for create action"(is (= "Values can only be fetched for actions that require a Primary Key."- (mt/user-http-request :crowberto :get 400 (format "action/%d/execute" create-action-id) :parameters (json/encode {:id 1})))))+ (mt/user-http-request :crowberto :post 400 (format "action/%d/execute/values" create-action-id) {:parameters {"id" 1}}))))(testing "fetch for update action return name and id"(is (= {:id 1 :name "Red Medicine"}- (mt/user-http-request :crowberto :get 200 (format "action/%d/execute" update-action-id) :parameters (json/encode {:id 1})))))+ (mt/user-http-request :crowberto :post 200 (format "action/%d/execute/values" update-action-id) {:parameters {"id" 1}}))))(testing "fetch for delete action returns the id only"(is (= {:id 1}- (mt/user-http-request :crowberto :get 200 (format "action/%d/execute" delete-action-id) :parameters (json/encode {:id 1})))))+ (mt/user-http-request :crowberto :post 200 (format "action/%d/execute/values" delete-action-id) {:parameters {"id" 1}}))))(mt/with-actions-disabled(testing "error if actions is disabled"(is (= "Actions are not enabled."- (:message (mt/user-http-request :crowberto :get 400 (format "action/%d/execute" delete-action-id) :parameters (json/encode {:id 1})))))))))))+ (:message (mt/user-http-request :crowberto :post 400 (format "action/%d/execute/values" delete-action-id) {:parameters {"id" 1}}))))))))));; This is just to test the flow, a comprehensive tests for error type ares in;; [[metabase.driver.sql-jdbc.actions-test/action-error-handling-test]]diff --git a/test/metabase/dashboards_rest/api_test.clj b/test/metabase/dashboards_rest/api_test.cljindex e7c1dba8a0d..eb10c447619 100644--- a/test/metabase/dashboards_rest/api_test.clj+++ b/test/metabase/dashboards_rest/api_test.clj@@ -4146,7 +4146,7 @@{:keys [action-id model-id]} {:type :implicit:visualization_settings {:fields {"name" {:id "name":hidden true}}}}]- (testing "Supplying a hidden parameter value should fail gracefully for GET /api/dashboard/:id/dashcard/:id/execute"+ (testing "Supplying a hidden parameter value should fail gracefully for POST /api/dashboard/:id/dashcard/:id/execute"(mt/with-temp [:model/Dashboard {dashboard-id :id} {}:model/DashboardCard {dashcard-id :id} {:dashboard_id dashboard-id:action_id action-id@@ -4312,16 +4312,16 @@:model/DashboardCard {dashcard-id :id} {:dashboard_id dashboard-id:card_id model-id:action_id action-id}]- (let [path (format "dashboard/%s/dashcard/%s/execute" dashboard-id dashcard-id)]+ (let [path (format "dashboard/%s/dashcard/%s/execute/values" dashboard-id dashcard-id)](testing "It succeeds with appropriate parameters"(is (partial= {:id 1 :name "African"}- (mt/user-http-request :crowberto :get 200- path :parameters (json/encode {"id" 1})))))+ (mt/user-http-request :crowberto :post 200+ path {:parameters {"id" 1}}))))(testing "Missing pk parameter should fail gracefully"(is (partial= "Missing primary key parameter: \"id\""(mt/user-http-request- :crowberto :get 400- path :parameters (json/encode {"name" 1}))))))))))))+ :crowberto :post 400+ path {:parameters {"name" 1}})))))))))))(deftest dashcard-implicit-action-only-expose-and-allow-model-fields(mt/test-drivers (mt/normal-drivers-with-feature :actions)@@ -4336,9 +4336,10 @@(testing "Dashcard should only have id and name params"(is (partial= {:dashcards [{:action {:parameters [{:id "id"} {:id "name"}]}}]}(mt/user-http-request :crowberto :get 200 (format "dashboard/%s" dashboard-id)))))- (let [execute-path (format "dashboard/%s/dashcard/%s/execute" dashboard-id dashcard-id)]+ (let [execute-path (format "dashboard/%s/dashcard/%s/execute" dashboard-id dashcard-id)+ values-path (format "dashboard/%s/dashcard/%s/execute/values" dashboard-id dashcard-id)](testing "Prefetch should limit to id and name"- (let [values (mt/user-http-request :crowberto :get 200 execute-path :parameters (json/encode {:id 1}))]+ (let [values (mt/user-http-request :crowberto :post 200 values-path {:parameters {"id" 1}})](is (= {:id 1 :name "Red Medicine"} values))))(testing "Update should only allow name"(is (= {:rows-updated 1}@@ -4366,10 +4367,11 @@(testing "Dashcard should only have id and name params"(is (partial= {:dashcards [{:action {:parameters [{:id "id"} {:id "name"}]}}]}(mt/user-http-request :crowberto :get 200 (format "dashboard/%s" dashboard-id)))))- (let [execute-path (format "dashboard/%s/dashcard/%s/execute" dashboard-id dashcard-id)]+ (let [execute-path (format "dashboard/%s/dashcard/%s/execute" dashboard-id dashcard-id)+ values-path (format "dashboard/%s/dashcard/%s/execute/values" dashboard-id dashcard-id)](testing "Prefetch should only return non-hidden fields"(is (= {:id 1 :name "Red Medicine"} ; price is hidden- (mt/user-http-request :crowberto :get 200 execute-path :parameters (json/encode {:id 1})))))+ (mt/user-http-request :crowberto :post 200 values-path {:parameters {"id" 1}}))))(testing "Update should only allow name"(is (= {:rows-updated 1}(mt/user-http-request :crowberto :post 200 execute-path {:parameters {"id" 1 "name" "Blueberries"}})))diff --git a/test/metabase/public_sharing_rest/api_test.clj b/test/metabase/public_sharing_rest/api_test.cljindex 70e338123d8..6e11c61b33f 100644--- a/test/metabase/public_sharing_rest/api_test.clj+++ b/test/metabase/public_sharing_rest/api_test.clj@@ -771,10 +771,11 @@(testing "Dashcard should only have id and name params"(is (partial= {:dashcards [{:action {:parameters [{:id "id"} {:id "name"}]}}]}(mt/user-http-request :crowberto :get 200 (format "public/dashboard/%s" dashboard-uuid)))))- (let [execute-path (format "public/dashboard/%s/dashcard/%s/execute" dashboard-uuid (:id dashcard))]+ (let [execute-path (format "public/dashboard/%s/dashcard/%s/execute" dashboard-uuid (:id dashcard))+ values-path (format "public/dashboard/%s/dashcard/%s/execute/values" dashboard-uuid (:id dashcard))](testing "Prefetch should only return non-hidden fields"(is (= {:id 1 :name "Red Medicine"} ; price is hidden- (mt/user-http-request :crowberto :get 200 execute-path :parameters (json/encode {:id 1})))))+ (mt/user-http-request :crowberto :post 200 values-path {:parameters {"id" 1}}))))(testing "Update should not allow hidden fields to be updated"(is (= {:rows-updated 1}(mt/user-http-request :crowberto :post 200 execute-path {:parameters {"id" 1 "name" "Blueberries"}})))@@ -782,7 +783,7 @@(mt/user-http-request :crowberto :post 400 execute-path {:parameters {"id" 1 "name" "Blueberries" "price" 1234}})))))))))))))(deftest public-dashboard-action-prefill-validates-dashcard-belongs-to-dashboard-test- (testing "GET prefill should validate that the dashcard belongs to the dashboard"+ (testing "prefill should validate that the dashcard belongs to the dashboard"(mt/with-temporary-setting-values [enable-public-sharing true](mt/test-drivers (mt/normal-drivers-with-feature :actions)(mt/with-actions-test-data-tables #{"venues" "categories"}@@ -799,10 +800,10 @@:card_id card-id}](testing "dashcard from a different dashboard should 404"(is (= "Not found."- (client/client :get 404- (format "public/dashboard/%s/dashcard/%s/execute"+ (client/client :post 404+ (format "public/dashboard/%s/dashcard/%s/execute/values"public-uuid (:id other-dashcard))- :parameters (json/encode {:id 1}))))))))))))))+ {:parameters {"id" 1}})))))))))))))(deftest get-public-dashboard-actions-test(testing "GET /api/public/dashboard/:uuid"@@ -1669,9 +1670,9 @@:card_id model-id}](is (partial= {:id 1 :name "African"}(client/client- :get 200- (format "public/dashboard/%s/dashcard/%s/execute" (:public_uuid dash) dashcard-id)- :parameters (json/encode {:id 1}))))))))))+ :post 200+ (format "public/dashboard/%s/dashcard/%s/execute/values" (:public_uuid dash) dashcard-id)+ {:parameters {"id" 1}})))))))));;; --------------------------------- POST /api/public/action/:uuid/execute ----------------------------------