Skip to content
Snippets Groups Projects
Unverified Commit 338fbab1 authored by Ngoc Khuat's avatar Ngoc Khuat Committed by GitHub
Browse files

Remove auto-incremented fields from "create implicit actions" (#28985)

parent 609c9116
No related branches found
No related tags found
No related merge requests found
......@@ -217,6 +217,7 @@
:target [:variable [:template-tag (u/slugify (:name field))]]
:type (:base_type field)
:required (:database_required field)
:is-auto-increment (:database_is_auto_increment field)
::field-id (:id field)
::pk? (isa? (:semantic_type field) :type/PK)})))]]
[(:id card) parameters]))))
......@@ -243,14 +244,18 @@
(if (= (:type action) :implicit)
(let [model-id (:model_id action)
saved-params (m/index-by :id parameters)
action-kind (:kind action)
implicit-params (cond->> (get model-id->implicit-parameters model-id)
:always
(map (fn [param] (merge param (get saved-params (:id param)))))
(= "row/delete" (:kind action))
(= "row/delete" action-kind)
(filter ::pk?)
(contains? #{"row/update" "row/delete"} (:kind action))
(= "row/create" action-kind)
(remove :is-auto-increment)
(contains? #{"row/update" "row/delete"} action-kind)
(map (fn [param] (cond-> param (::pk? param) (assoc :required true))))
:always
......
......@@ -22,6 +22,7 @@
(def TableMetadataField
"Schema for a given Field as provided in `describe-table`."
{:name su/NonBlankString
:database-type (s/maybe su/NonBlankString) ; blank if the Field is all NULL & untyped, i.e. in Mongo
:base-type su/FieldType
......
......@@ -214,8 +214,10 @@
expected-fn (fn [m]
(cond-> m
(= (:type initial-action) "implicit")
(assoc :parameters [{:id "id" :type "type/BigInteger" :special "hello"}]
:database_id (mt/id))))
(assoc :database_id (mt/id)
:parameters (if (= "row/create" (:kind initial-action))
[]
[{:id "id" :type "type/BigInteger" :special "hello"}]))))
updated-action (update-fn initial-action)]
(testing "Create fails with"
(testing "no permission"
......
......@@ -2697,7 +2697,7 @@
(is (partial= {:name "Birds"}
new-row)))
(testing "Extra parameter should fail gracefully"
(is (partial= {:message "No destination parameter found for #{\"extra\"}. Found: #{\"id\" \"name\"}"}
(is (partial= {:message "No destination parameter found for #{\"extra\"}. Found: #{\"name\"}"}
(mt/user-http-request :crowberto :post 400 execute-path
{:parameters {"extra" 1}}))))
(testing "Missing other parameters should fail gracefully"
......
......@@ -50,7 +50,7 @@
"json_bit → 1234" "json_bit → 1234123412314"
"json_bit → boop" "json_bit → doop" "json_bit → genres"
"json_bit → noop" "json_bit → published" "json_bit → title"
"json_bit → zoop" })]
"json_bit → zoop"})]
(is (= model-columns (t2/select-one-fn (comp set
(partial map :name)
:result_metadata)
......@@ -140,3 +140,17 @@
Exception
#"Actions must be made with models, not cards"
(t2/update! Action action-id {:archived false}))))))))
(deftest exclude-auto-increment-fields-for-create-implicit-actions-test
(mt/test-drivers (mt/normal-drivers-with-feature :actions/custom)
(mt/with-actions-enabled
(doseq [kind ["row/create" "row/update" "row/delete"]]
(testing (format "for implicit action with kind=%s we should %s include auto incremented fields"
kind (if (= "row/create" kind) "not" ""))
(mt/with-actions [{:keys [action-id]} {:type :implicit
:kind kind}]
(let [parameters (:parameters (action/select-action :id action-id))
id-parameter (first (filter #(= "id" (:id %)) parameters))]
(if (= "row/create" kind)
(is (nil? id-parameter))
(is (some? id-parameter))))))))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment