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
Remove unused HTTP action code paths (#69764)
bryanbe492dc637d9
diff --git a/enterprise/backend/test/metabase_enterprise/serialization/v2/extract_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/v2/extract_test.cljindex 229e04cf7e5..b52241763ed 100644--- a/enterprise/backend/test/metabase_enterprise/serialization/v2/extract_test.clj+++ b/enterprise/backend/test/metabase_enterprise/serialization/v2/extract_test.clj@@ -1124,43 +1124,6 @@(is (= #{[{:model "Card" :id card-eid-1}]}(set (serdes/dependencies ser)))))))))))))-(deftest http-action-test- (mt/with-empty-h2-app-db!- (ts/with-temp-dpc [:model/User {ann-id :id} {:first_name "Ann"- :last_name "Wilson"- :email "[email protected]"}- :model/Database {db-id :id :as db} {:name "My Database"}]- (mt/with-db db- (mt/with-actions [{card-id-1 :id- card-eid-1 :entity_id}- {:name "Source question"- :database_id db-id- :type :model- :query_type :native- :dataset_query (mt/native-query {:query "select 1"})- :creator_id ann-id}-- {:keys [action-id]}- {:name "My Action"- :type :http- :template {:method "GET", :url "https://camsaul.com"}- :creator_id ann-id- :model_id card-id-1}]- (let [action (action/select-action :id action-id)]- (testing "action"- (let [ser (ts/extract-one "Action" action-id)]- (is (=? {:serdes/meta [{:model "Action" :id (:entity_id action) :label "my_action"}]- :creator_id "[email protected]"- :type "http"- :created_at string?- :model_id card-eid-1- :http [{:template {}}]}- ser))- (is (not (contains? ser :id)))- (testing "depends on the Model"- (is (= #{[{:model "Card" :id card-eid-1}]}- (set (serdes/dependencies ser)))))))))))))-(deftest query-action-test(mt/with-empty-h2-app-db!(ts/with-temp-dpc [:model/User {ann-id :id} {:first_name "Ann"diff --git a/src/metabase/actions_rest/api.clj b/src/metabase/actions_rest/api.cljindex 4e204419552..80e55ad1cd0 100644--- a/src/metabase/actions_rest/api.clj+++ b/src/metabase/actions_rest/api.clj@@ -81,6 +81,10 @@{:keys [model_id parameters database_id]action-type :type:as action} :- ::actions.schema/action.for-insert]+ (when (= action-type :http)+ (throw (ex-info (tru "HTTP actions are not supported.")+ {:type :http+ :status-code 400})))(when (and (nil? database_id)(= action-type :query))(throw (ex-info (tru "Must provide a database_id for query actions")@@ -116,8 +120,16 @@[:id ::actions.schema/id]]_query-paramsaction :- ::actions.schema/action.for-update]+ (when (= (:type action) :http)+ (throw (ex-info (tru "HTTP actions are not supported.")+ {:type :http+ :status-code 400})))(actions/check-actions-enabled! id)(let [existing-action (api/write-check :model/Action id)]+ (when (= (:type existing-action) :http)+ (throw (ex-info (tru "HTTP actions are not supported.")+ {:type :http+ :status-code 400})))(actions/update! (assoc action :id id) existing-action))(let [{:keys [parameters type] :as action} (actions/select-action :id id)](analytics/track-event! :snowplow/action@@ -199,6 +211,10 @@{:keys [parameters], :as _body} :- [:maybe [:map[:parameters {:optional true} [:maybe [:map-of :keyword any?]]]]]](let [{:keys [type] :as action} (api/check-404 (actions/select-action :id id :archived false))]+ (when (= type :http)+ (throw (ex-info (tru "HTTP actions are not supported.")+ {:type :http+ :status-code 400})))(analytics/track-event! :snowplow/action{:event :action-executed:source :model_detaildiff --git a/test/metabase/actions/models_test.clj b/test/metabase/actions/models_test.cljindex 28aea6f29f3..face93eec5f 100644--- a/test/metabase/actions/models_test.clj+++ b/test/metabase/actions/models_test.clj@@ -119,16 +119,6 @@(->> (action/select-action :id action-id):parameters (map :id) set)))))))))))-(deftest hydrate-http-action-test- (mt/test-drivers (mt/normal-drivers-with-feature :actions/custom)- (mt/with-actions-test-data-and-actions-enabled- (mt/with-actions [{:keys [action-id] :as _context} {:type :http}]- (is (partial= {:id action-id- :name "Echo Example"- :parameters [{:id "id" :type :number}- {:id "fail" :type :text}]}- (action/select-action :id action-id)))))))-(deftest hydrate-creator-test(mt/test-drivers (mt/normal-drivers-with-feature :actions/custom)(mt/with-actions-test-data-and-actions-enableddiff --git a/test/metabase/actions_rest/api_test.clj b/test/metabase/actions_rest/api_test.cljindex f31c6dca548..86bf65655cf 100644--- a/test/metabase/actions_rest/api_test.clj+++ b/test/metabase/actions_rest/api_test.clj@@ -62,16 +62,7 @@(defn- all-actions-default[card-id]- [{:name "Get example"- :description "A dummy HTTP action"- :type "http"- :model_id card-id- :template {:method "GET"- :url "https://example.com/{{x}}"}- :parameters [{:id "x" :type "text"}]- :response_handle ".body"- :error_handle ".status >= 400"}- {:name "Query example"+ [{:name "Query example":description "A simple update query action":type "query":model_id card-id@@ -91,17 +82,7 @@(mt/with-non-admin-groups-no-root-collection-perms(mt/with-actions-test-data-tables #{"users"}(mt/with-actions [{card-id :id} {:type :model :dataset_query (mt/mbql-query users)}- action-1 {:name "Get example"- :type :http- :model_id card-id- :template {:method "GET"- :url "https://example.com/{{x}}"}- :parameters [{:id "x" :type "text"}]- :public_uuid (str (random-uuid))- :made_public_by_id (mt/user->id :crowberto)- :response_handle ".body"- :error_handle ".status >= 400"}- action-2 {:name "Query example"+ action-1 {:name "Query example":type :query:model_id card-id:dataset_query (update (mt/native-query {:query "update venues set name = 'foo' where id = {{x}}"})@@ -109,7 +90,7 @@:database_id (mt/id):parameters [{:id "x" :type "number"}]:visualization_settings {:position "top"}}- action-3 {:name "Implicit example"+ action-2 {:name "Implicit example":type :implicit:model_id card-id:kind "row/create"@@ -124,7 +105,7 @@:visualization_settings {:position "top"}:archived true}](let [response (mt/user-http-request :crowberto :get 200 (str "action?model-id=" card-id))]- (is (= (map :action-id [action-1 action-2 action-3])+ (is (= (map :action-id [action-1 action-2])(map :id response)))(doseq [action response:when (= (:type action) "query")]@@ -138,7 +119,7 @@(testing "Can list all actions"(let [response (mt/user-http-request :crowberto :get 200 "action")action-ids (into #{} (map :id) response)]- (is (set/subset? (into #{} (map :action-id) [action-1 action-2 action-3])+ (is (set/subset? (into #{} (map :action-id) [action-1 action-2])action-ids))(doseq [action response:when (= (:type action) "query")]@@ -149,7 +130,7 @@(is (not (contains? action-ids (:id archived)))))(testing "Does not return actions on models without permissions"(let [rasta-list (mt/user-http-request :rasta :get 200 "action")]- (is (empty? (set/intersection (into #{} (map :action-id) [action-1 action-2 action-3])+ (is (empty? (set/intersection (into #{} (map :action-id) [action-1 action-2])(into #{} (map :id) rasta-list)))))))))))))(deftest get-action-test@@ -259,10 +240,7 @@(= (:type initial-action) "query")(assoc :dataset_query- (lib/native-query (mt/metadata-provider) "update users set name = 'bar' where id = {{x}}"))-- (= (:type initial-action) "http")- (-> (assoc :response_handle ".body.result" :description nil))))+ (lib/native-query (mt/metadata-provider) "update users set name = 'bar' where id = {{x}}"))))expected-fn (fn [m](-> m(cond-> (= (:type initial-action) "implicit")@@ -388,16 +366,16 @@(deftest action-parameters-test(mt/with-actions-enabled- (mt/with-temp [:model/Card {card-id :id} {:type :model}]+ (mt/with-temp [:model/Card {card-id :id} {:type :model+ :dataset_query (mt/mbql-query venues)}](mt/with-model-cleanup [:model/Action]- (let [initial-action {:name "Get example"- :type "http"- :model_id card-id- :template {:method "GET"- :url "https://example.com/{{x}}"- :parameters [{:id "x" :type "text"}]}- :response_handle ".body"- :error_handle ".status >= 400"}+ (let [initial-action {:name "Query example"+ :type "query"+ :model_id card-id+ :database_id (mt/id)+ :dataset_query (update (mt/native-query {:query "update venues set name = 'foo' where id = {{x}}"})+ :type name)+ :parameters [{:id "x" :type "number"}]}created-action (mt/user-http-request :crowberto :post 200 "action" initial-action)action-id (u/the-id created-action)action-path (str "action/" action-id)]@@ -410,30 +388,10 @@(testing "Required fields"(is (=? {:errors {:name "string"},:specific-errors {:name ["missing required key, received: nil"]}}- (mt/user-http-request :crowberto :post 400 "action" {:type "http"})))+ (mt/user-http-request :crowberto :post 400 "action" {:type "query"})))(is (=? {:errors {:model_id "Valid Card ID"}:specific-errors {:model_id ["missing required key, received: nil"]}}- (mt/user-http-request :crowberto :post 400 "action" {:type "http" :name "test"}))))- (testing "Handles need to be valid jq"- (is (=? {:errors {:response_handle "nullable must be a valid json-query, something like '.item.title'"}- :specific-errors {:response_handle ["must be a valid json-query, something like '.item.title', received: \"body\""]}}- (mt/user-http-request :crowberto :post 400 "action" (assoc initial-action :response_handle "body"))))- (is (=? {:errors {:error_handle "nullable must be a valid json-query, something like '.item.title'"}- :specific-errors {:error_handle ["must be a valid json-query, something like '.item.title', received: \"x\""]}}- (mt/user-http-request :crowberto :post 400 "action" (assoc initial-action :error_handle "x"))))))- (testing "Validate PUT"- (testing "Template needs method and url"- (is (=? {:specific-errors- {:template {:method ["missing required key, received: nil"], :url ["missing required key, received: nil"]}},- :errors {:template {:method "enum of GET, POST, PUT, DELETE, PATCH", :url "string with length >= 1"}}}- (mt/user-http-request :crowberto :put 400 action-path {:type "http" :template {}}))))- (testing "Handles need to be valid jq"- (is (=? {:errors {:response_handle "nullable must be a valid json-query, something like '.item.title'"},- :specific-errors {:response_handle ["must be a valid json-query, something like '.item.title', received: \"body\""]}}- (mt/user-http-request :crowberto :put 400 action-path (assoc initial-action :response_handle "body"))))- (is (=? {:errors {:error_handle "nullable must be a valid json-query, something like '.item.title'"},- :specific-errors {:error_handle ["must be a valid json-query, something like '.item.title', received: \"x\""]}}- (mt/user-http-request :crowberto :put 400 action-path (assoc initial-action :error_handle "x")))))))))))+ (mt/user-http-request :crowberto :post 400 "action" {:type "query" :name "test"}))))))))));;; +----------------------------------------------------------------------------------------------------------------+;;; | PUBLIC SHARING ENDPOINTS |@@ -651,7 +609,6 @@{create-action-id :action-id} {:type :implicit :kind "row/create"}{update-action-id :action-id} {:type :implicit :kind "row/update"}{delete-action-id :action-id} {:type :implicit :kind "row/delete"}- {http-action-id :action-id} {:type :http}{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."@@ -661,10 +618,7 @@(is (= "Not found."(mt/user-http-request :rasta :get 404 (format "action/%d/execute" Integer/MAX_VALUE) :parameters (json/encode {:id 1})))))- (testing "returns empty map for actions that are not implicit"- (is (= {}- (mt/user-http-request :crowberto :get 200 (format "action/%d/execute" http-action-id) :parameters (json/encode {: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})))))diff --git a/test/metabase/dashboards_rest/api_test.clj b/test/metabase/dashboards_rest/api_test.cljindex 8044527507a..bf8ad452899 100644--- a/test/metabase/dashboards_rest/api_test.clj+++ b/test/metabase/dashboards_rest/api_test.clj@@ -3886,40 +3886,6 @@:user-id (str (mt/user->id :crowberto))}(last (snowplow-test/pop-event-data-and-user-id!)))))))))))))-(deftest dashcard-http-action-execution-test- (mt/test-drivers (mt/normal-drivers-with-feature :actions)- (mt/with-actions-test-data-and-actions-enabled- (mt/with-actions [{:keys [action-id model-id]} {:type :http}]- (testing "Executing dashcard with action"- (mt/with-temp [:model/Dashboard {dashboard-id :id} {}- :model/DashboardCard {dashcard-id :id} {:dashboard_id dashboard-id- :action_id action-id- :card_id model-id}]- (let [execute-path (format "dashboard/%s/dashcard/%s/execute"- dashboard-id- dashcard-id)]- (testing "Should be able to execute an action"- (is (= {:the_parameter 1}- (mt/user-http-request :crowberto :post 200 execute-path- {:parameters {"id" 1}}))))- (testing "Should handle errors"- (is (= {:remote-status 400- :message "oops"}- (mt/user-http-request :crowberto :post 400 execute-path- {:parameters {"id" 1 "fail" "true"}}))))- (testing "Extra parameter should fail gracefully"- (is (partial= {:message "No destination parameter found for #{\"extra\"}. Found: #{\"id\" \"fail\"}"}- (mt/user-http-request :crowberto :post 400 execute-path- {:parameters {"extra" 1}}))))- (testing "Missing parameter should fail gracefully"- (is (has-valid-action-execution-error-message?- (mt/user-http-request :crowberto :post 400 execute-path- {:parameters {}}))))- (testing "Sending an invalid number should fail gracefully"- (is (has-valid-action-execution-error-message?- (mt/user-http-request :crowberto :post 400 execute-path- {:parameters {"id" "BAD"}})))))))))))-(deftest dashcard-implicit-action-execution-insert-test(mt/test-drivers (mt/normal-drivers-with-feature :actions)(mt/with-actions-test-data-and-actions-enabled