Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

API cleaning: random fixes from an abandoned branch (#85311)

Timothy S. Dean88fd639149b7
diff --git a/docs/developers-guide/api-changelog.md b/docs/developers-guide/api-changelog.md
index 3d7bacd21f9..75e5094d466 100644
--- a/docs/developers-guide/api-changelog.md
+++ b/docs/developers-guide/api-changelog.md
@@ -16,6 +16,9 @@ title: API changelog
(`sensitive`). Pass the new `include_sensitive_fields=true` to get them, for tables whose data model the current user
can edit, as with `GET /api/table/:id/query_metadata`.
+- `POST /api/ee/serialization/export` accepts a `dirname` of 1-255 characters from `A-Z a-z 0-9 _ - . %`
+ that does not start with `.` or `-`. Other values get `400 Bad Request`.
+
## Metabase 0.65.0
- `POST /api/transform` and `PUT /api/transform/:id` answer a target table that already exists with
diff --git a/enterprise/backend/src/metabase_enterprise/audit_app/api/analytics_dev.clj b/enterprise/backend/src/metabase_enterprise/audit_app/api/analytics_dev.clj
index fd3c293eba2..b2b8eac8ad3 100644
--- a/enterprise/backend/src/metabase_enterprise/audit_app/api/analytics_dev.clj
+++ b/enterprise/backend/src/metabase_enterprise/audit_app/api/analytics_dev.clj
@@ -27,7 +27,7 @@
[]
(let [collection (analytics-dev/find-analytics-collection)]
(when-not collection
- (throw (ex-info "Analytics collection not found" {:status 404})))
+ (throw (ex-info "Analytics collection not found" {:status-code 404})))
(let [temp-dir (Files/createTempDirectory "analytics-export" (make-array FileAttribute 0))
parent-dir (doto (.toFile temp-dir) .mkdirs)
export-dir (doto (io/file parent-dir "instance_analytics") .mkdirs)
diff --git a/enterprise/backend/src/metabase_enterprise/permission_debug/api.clj b/enterprise/backend/src/metabase_enterprise/permission_debug/api.clj
index d87e5d3fd08..16d0528b918 100644
--- a/enterprise/backend/src/metabase_enterprise/permission_debug/api.clj
+++ b/enterprise/backend/src/metabase_enterprise/permission_debug/api.clj
@@ -4,7 +4,8 @@
[metabase-enterprise.permission-debug.impl :as permission-debug.impl]
[metabase.api.common :as api]
[metabase.api.macros :as api.macros]
- [metabase.api.routes.common :refer [+auth]]))
+ [metabase.api.routes.common :refer [+auth]]
+ [metabase.util.malli.schema :as ms]))
;; TODO (Cam 10/28/25) -- fix this endpoint so it uses kebab-case for query parameters for consistency with the rest
;; of the REST API
@@ -68,7 +69,7 @@
{:keys [user_id model_id action_type]
:or {}} :- [:map {:closed true}
[:user_id pos-int?]
- [:model_id :string]
+ [:model_id ms/PositiveInt]
[:action_type permission-debug.impl/ActionType]]
_body]
(permission-debug.impl/debug-permissions
diff --git a/enterprise/backend/src/metabase_enterprise/permission_debug/impl.clj b/enterprise/backend/src/metabase_enterprise/permission_debug/impl.clj
index 7590f8e51de..c5846426dfb 100644
--- a/enterprise/backend/src/metabase_enterprise/permission_debug/impl.clj
+++ b/enterprise/backend/src/metabase_enterprise/permission_debug/impl.clj
@@ -49,7 +49,7 @@
"Arguments for the Debugger function. The model type being operated on is inferred by the requested action type"
[:map
[:user-id pos-int?]
- [:model-id :string]
+ [:model-id pos-int?]
[:action-type ActionType]])
(defmulti debug-permissions
@@ -86,7 +86,7 @@
{:decision "allow"
:model-type (case (namespace action-type)
"card" "card")
- :model-id model-id
+ :model-id (str model-id)
:segment #{}
:message [(tru "Superuser is allowed full access")]
:data {}
@@ -143,10 +143,10 @@
(mu/defmethod debug-permissions :card/read :- DebuggerSchema
[{:keys [user-id model-id] :as _debug-info} :- DebuggerArguments]
- (let [can-read? (user-can-read? :model/Card (Integer/parseInt model-id) user-id)]
+ (let [can-read? (user-can-read? :model/Card model-id user-id)]
{:decision (if can-read? "allow" "denied")
:model-type "card"
- :model-id model-id
+ :model-id (str model-id)
:segment #{}
:message [(if can-read?
(tru "User has permission to read this card")
@@ -199,15 +199,14 @@
[{:keys [user-id model-id] :as debug-info} :- DebuggerArguments]
(merge-permission-check
(debug-permissions (assoc debug-info :action-type :card/read))
- (let [card-id (Integer/parseInt model-id)
- card (permission-debug.db/card card-id)
+ (let [card (permission-debug.db/card model-id)
blocked-by-group (check-table-permissions user-id card
{:perms/view-data :blocked}
{:perms/view-data :legacy-no-self-service})]
{:decision (if (seq blocked-by-group) "denied" "allow")
:segment #{}
:model-type "card"
- :model-id model-id
+ :model-id (str model-id)
:message [(if (seq blocked-by-group)
(tru "User does not have permission to query this card")
(tru "User has permission to query this card"))]
@@ -219,8 +218,7 @@
[{:keys [user-id model-id] :as debug-info} :- DebuggerArguments]
(merge-permission-check
(debug-permissions (assoc debug-info :action-type :card/query))
- (let [card-id (Integer/parseInt model-id)
- card (permission-debug.db/card card-id)
+ (let [card (permission-debug.db/card model-id)
limited-by-group (check-table-permissions user-id card
{:perms/download-results :ten-thousand-rows}
{:perms/download-results :one-million-rows})
@@ -232,7 +230,7 @@
(seq limited-by-group) "limited"
:else "allow")
:model-type "card"
- :model-id model-id
+ :model-id (str model-id)
:segment #{}
:message [(cond
(seq blocked-by-group) (tru "User does not have permission to download data from this card")
diff --git a/enterprise/backend/src/metabase_enterprise/serialization/api.clj b/enterprise/backend/src/metabase_enterprise/serialization/api.clj
index 0827c015e42..216b2851b2b 100644
--- a/enterprise/backend/src/metabase_enterprise/serialization/api.clj
+++ b/enterprise/backend/src/metabase_enterprise/serialization/api.clj
@@ -20,6 +20,7 @@
[metabase.util :as u]
[metabase.util.compress :as u.compress]
[metabase.util.date-2 :as u.date]
+ [metabase.util.i18n :refer [deferred-tru]]
[metabase.util.log :as log]
[metabase.util.malli :as mu]
[metabase.util.malli.schema :as ms]
@@ -223,8 +224,12 @@
:as _query-params}
:- [:map {:closed true}
[:dirname {:optional true} [:maybe
- {:description "name of directory and archive file (default: `<instance-name>-<YYYY-MM-dd_HH-mm>`)"}
- string?]]
+ {:description (deferred-tru "name of directory and archive file (default: `<instance-name>-<YYYY-MM-dd_HH-mm>`): 1-255 characters from A-Z a-z 0-9 _ - . %, not starting with . or -")}
+ (mu/with-api-error-message
+ ;; `%`: the default name is a slug, which percent-encodes non-ASCII
+ [:re #"^[A-Za-z0-9_%][A-Za-z0-9._%-]{0,254}$"]
+ (deferred-tru "name of directory and archive file (default: `<instance-name>-<YYYY-MM-dd_HH-mm>`): 1-255 characters from A-Z a-z 0-9 _ - . %, not starting with . or -")
+ (deferred-tru "1-255 characters from A-Z a-z 0-9 _ - . %, not starting with . or -"))]]
[:collection {:optional true} [:maybe
{:description "collections' db ids/entity-ids to serialize"}
(ms/QueryVectorOf
@@ -252,16 +257,18 @@
:full-stacktrace full-stacktrace?}
export-dirname (or dirname
(format "%s-%s"
- (u/slugify (appearance/site-name))
+ ;; + 17 for the timestamp = 255, so the default passes the `dirname` schema
+ (u/slugify (appearance/site-name) {:max-length 238})
(u.date/format "YYYY-MM-dd_HH-mm" (t/local-date-time))))
;; Eager setup (target resolution, escape analysis) must run before the streaming response opens
;; so a failure can still set a non-200 status. extract-entities! captures its logs into log-output
;; (so escape-analysis warnings land in export.log) and honors full_stacktrace for genuine failures.
log-output (ByteArrayOutputStream.)
entities (extract-entities! opts log-output full-stacktrace?)]
- (sr/streaming-response {:content-type "application/gzip" :status 200} [output _cancel-chan]
- (sr/set-header! "Content-Disposition"
- (format "attachment; filename=\"%s.tar.gz\"" export-dirname))
+ (sr/streaming-response {:content-type "application/gzip"
+ :status 200
+ :headers {"Content-Disposition" (format "attachment; filename=\"%s.tar.gz\""
+ export-dirname)}} [output _cancel-chan]
(let [start (System/nanoTime)
result (serialize-to-stream! output export-dirname entities log-output opts)]
(track-export-event! collection opts start result)))))
diff --git a/enterprise/backend/src/metabase_enterprise/stale/api.clj b/enterprise/backend/src/metabase_enterprise/stale/api.clj
index c08c56fb9c5..8529d70061b 100644
--- a/enterprise/backend/src/metabase_enterprise/stale/api.clj
+++ b/enterprise/backend/src/metabase_enterprise/stale/api.clj
@@ -110,7 +110,7 @@
(throw (ex-info (str "invalid before_date: '"
before_date
"' expected format: 'yyyy-MM-dd'")
- {:status 400}))))
+ {:status-code 400}))))
(t/minus (t/local-date) (t/months 6)))
collection (if (= id :root)
collection/root-collection
diff --git a/enterprise/backend/test/metabase_enterprise/permission_debug/api_test.clj b/enterprise/backend/test/metabase_enterprise/permission_debug/api_test.clj
index acd6c55baef..3901795f158 100644
--- a/enterprise/backend/test/metabase_enterprise/permission_debug/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/permission_debug/api_test.clj
@@ -114,7 +114,19 @@
(mt/user-http-request :crowberto :get "ee/permission_debug"
:user_id "invalid"
:model_id "999"
- :action_type "card/read"))))))
+ :action_type "card/read"))))
+ (testing "should reject a non-numeric model_id"
+ (is (=? {:errors {:model_id string?}}
+ (mt/user-http-request :crowberto :get 400 "ee/permission_debug"
+ :user_id "1"
+ :model_id "abc"
+ :action_type "card/read"))))
+ (testing "should reject a model_id with a trailing newline"
+ (is (=? {:errors {:model_id string?}}
+ (mt/user-http-request :crowberto :get 400 "ee/permission_debug"
+ :user_id "1"
+ :model_id "123\n"
+ :action_type "card/read"))))))
(deftest permission-debug-response-schema-test
(testing "GET /api/ee/permission_debug response schema validation"
diff --git a/enterprise/backend/test/metabase_enterprise/permission_debug/impl_test.clj b/enterprise/backend/test/metabase_enterprise/permission_debug/impl_test.clj
index 978ed92512e..218d3437985 100644
--- a/enterprise/backend/test/metabase_enterprise/permission_debug/impl_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/permission_debug/impl_test.clj
@@ -23,7 +23,7 @@
(let [regular-user-id (mt/user->id :rasta)
result (permission-debug.impl/debug-permissions
{:user-id regular-user-id
- :model-id (str (:id card))
+ :model-id (:id card)
:action-type :card/read})]
(is (= "allow" (:decision result)))
(is (= #{} (:segment result)))
@@ -38,7 +38,7 @@
(with-temp-revoke-collection-perms! (perms/all-users-group) collection
(let [result (permission-debug.impl/debug-permissions
{:user-id regular-user-id
- :model-id (str (:id card))
+ :model-id (:id card)
:action-type :card/read})]
(is (= "denied" (:decision result)))
(is (= #{} (:segment result)))
@@ -52,7 +52,7 @@
(let [admin-user-id (mt/user->id :crowberto)
result (permission-debug.impl/debug-permissions
{:user-id admin-user-id
- :model-id (str (:id card))
+ :model-id (:id card)
:action-type :card/read})]
(is (= "allow" (:decision result)))))))
@@ -65,7 +65,7 @@
(perms/set-table-permission! (perms/all-users-group) (mt/id :checkins) :perms/view-data :unrestricted)
(let [result (permission-debug.impl/debug-permissions
{:user-id regular-user-id
- :model-id (str (:id card))
+ :model-id (:id card)
:action-type :card/query})]
(is (= "allow" (:decision result)))
(is (= #{} (:segment result)))
@@ -84,7 +84,7 @@
(perms/set-table-permission! (perms/all-users-group) (mt/id :checkins) :perms/view-data :unrestricted)
(let [result (permission-debug.impl/debug-permissions
{:user-id regular-user-id
- :model-id (str (:id card))
+ :model-id (:id card)
:action-type :card/query})]
(is (= "denied" (:decision result)))
(is (= #{} (:segment result)))
@@ -100,7 +100,7 @@
(perms/set-table-permission! (perms/all-users-group) (mt/id :checkins) :perms/view-data :blocked)
(let [result (permission-debug.impl/debug-permissions
{:user-id regular-user-id
- :model-id (str (:id card))
+ :model-id (:id card)
:action-type :card/query})]
(is (= "denied" (:decision result)))
(is (= #{} (:segment result)))
@@ -121,7 +121,7 @@
(perms/set-table-permission! (perms/all-users-group) (mt/id :checkins) :perms/view-data :blocked)
(let [result (permission-debug.impl/debug-permissions
{:user-id regular-user-id
- :model-id (str (:id card))
+ :model-id (:id card)
:action-type :card/query})]
(is (= "allow" (:decision result)))
(is (= #{} (:segment result)))
@@ -138,7 +138,7 @@
(let [admin-user-id (mt/user->id :crowberto)
result (permission-debug.impl/debug-permissions
{:user-id admin-user-id
- :model-id (str (:id card))
+ :model-id (:id card)
:action-type :card/query})]
(is (= "allow" (:decision result)))))))
@@ -153,7 +153,7 @@
(perms/set-database-permission! (perms/all-users-group) (mt/id) :perms/view-data :unrestricted)
(let [result (permission-debug.impl/debug-permissions
{:user-id regular-user-id
- :model-id (str (:id card))
+ :model-id (:id card)
:action-type :card/query})]
(is (= "allow" (:decision result)))
(is (= #{} (:segment result)))
@@ -172,7 +172,7 @@
(perms/set-database-permission! (perms/all-users-group) (mt/id) :perms/view-data :unrestricted)
(let [result (permission-debug.impl/debug-permissions
{:user-id regular-user-id
- :model-id (str (:id card))
+ :model-id (:id card)
:action-type :card/query})]
(is (= "allow" (:decision result)))
(is (= #{} (:segment result)))
@@ -192,7 +192,7 @@
(perms/set-table-permission! (perms/all-users-group) (mt/id :venues) :perms/view-data :blocked)
(let [result (permission-debug.impl/debug-permissions
{:user-id regular-user-id
- :model-id (str (:id card))
+ :model-id (:id card)
:action-type :card/query})]
(is (= "denied" (:decision result)))
(is (= #{} (:segment result)))
@@ -211,7 +211,7 @@
(perms/set-database-permission! (perms/all-users-group) (mt/id) :perms/view-data :blocked)
(let [result (permission-debug.impl/debug-permissions
{:user-id regular-user-id
- :model-id (str (:id card))
+ :model-id (:id card)
:action-type :card/query})]
(is (= "denied" (:decision result)))
(is (= #{} (:segment result)))
@@ -249,7 +249,7 @@
(perms/set-table-permission! (perms/all-users-group) (mt/id :checkins) :perms/view-data :blocked)
(let [result (permission-debug.impl/debug-permissions
{:user-id regular-user-id
- :model-id (str (:id joined-card))
+ :model-id (:id joined-card)
:action-type :card/query})]
(is (= "denied" (:decision result)))
(is (= #{} (:segment result)))
@@ -267,7 +267,7 @@
(perms/set-table-permission! (perms/all-users-group) (mt/id :checkins) :perms/download-results :one-million-rows)
(let [result (permission-debug.impl/debug-permissions
{:user-id regular-user-id
- :model-id (str (:id card))
+ :model-id (:id card)
:action-type :card/download-data})]
(is (= "allow" (:decision result)))
(is (= #{} (:segment result)))
@@ -287,7 +287,7 @@
(perms/set-table-permission! (perms/all-users-group) (mt/id :checkins) :perms/download-results :one-million-rows)
(let [result (permission-debug.impl/debug-permissions
{:user-id regular-user-id
- :model-id (str (:id card))
+ :model-id (:id card)
:action-type :card/download-data})]
(is (= "denied" (:decision result)))
(is (= #{} (:segment result)))
@@ -304,7 +304,7 @@
(perms/set-table-permission! (perms/all-users-group) (mt/id :checkins) :perms/download-results :no)
(let [result (permission-debug.impl/debug-permissions
{:user-id regular-user-id
- :model-id (str (:id card))
+ :model-id (:id card)
:action-type :card/download-data})]
(is (= "denied" (:decision result)))
(is (= #{} (:segment result)))
@@ -325,7 +325,7 @@
(perms/set-table-permission! (perms/all-users-group) (mt/id :checkins) :perms/download-results :no)
(let [result (permission-debug.impl/debug-permissions
{:user-id regular-user-id
- :model-id (str (:id card))
+ :model-id (:id card)
:action-type :card/download-data})]
(is (= "allow" (:decision result)))
(is (= #{} (:segment result)))
@@ -345,7 +345,7 @@
(let [admin-user-id (mt/user->id :crowberto)
result (permission-debug.impl/debug-permissions
{:user-id admin-user-id
- :model-id (str (:id card))
+ :model-id (:id card)
:action-type :card/download-data})]
(is (= "allow" (:decision result)))))))
@@ -359,7 +359,7 @@
(perms/set-table-permission! (perms/all-users-group) (mt/id :checkins) :perms/download-results :ten-thousand-rows)
(let [result (permission-debug.impl/debug-permissions
{:user-id regular-user-id
- :model-id (str (:id card))
+ :model-id (:id card)
:action-type :card/download-data})]
(is (= "limited" (:decision result)))
(is (= #{} (:segment result)))
@@ -381,7 +381,7 @@
(perms/set-table-permission! (perms/all-users-group) (mt/id :checkins) :perms/download-results :no)
(let [result (permission-debug.impl/debug-permissions
{:user-id regular-user-id
- :model-id (str (:id card))
+ :model-id (:id card)
:action-type :card/download-data})]
(is (= "limited" (:decision result)))
(is (= #{} (:segment result)))
diff --git a/enterprise/backend/test/metabase_enterprise/serialization/api_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/api_test.clj
index 8de67a242c4..06ee5b7de5b 100644
--- a/enterprise/backend/test/metabase_enterprise/serialization/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/serialization/api_test.clj
@@ -200,6 +200,54 @@
(is (= known-files
(set (.list (io/file api.serialization/parent-dir)))))))))
+(deftest export-dirname-validation-test
+ (mt/with-premium-features #{:serialization}
+ (testing "dirname outside the whitelist is a 400"
+ (doseq [dirname [""
+ "../backups"
+ "a/b"
+ "a\\b"
+ "a\"b"
+ "a\r\nb"
+ ".."
+ "."
+ "-rf"
+ ".hidden"
+ (apply str (repeat 256 "a"))]]
+ (testing (pr-str dirname)
+ (is (=? {:errors {:dirname string?}}
+ (mt/user-http-request :crowberto :post 400 "ee/serialization/export" {}
+ :dirname dirname :all_collections false :data_model false :settings false))))))
+ (testing "the 400 for a bad dirname states the rule"
+ (is (=? {:errors {:dirname #".*: 1-255 characters from A-Z a-z 0-9 _ - \. %, not starting with \. or -"}}
+ (mt/user-http-request :crowberto :post 400 "ee/serialization/export" {}
+ :dirname ".hidden" :all_collections false :data_model false :settings false))))
+ (testing "a plain dirname names both the archive root directory and the download file"
+ (let [{:keys [body headers]} (mt/user-http-request-full-response
+ :crowberto :post 200 "ee/serialization/export" {}
+ :dirname "my-export_2" :all_collections false :data_model false :settings false)]
+ (is (= "attachment; filename=\"my-export_2.tar.gz\""
+ (get headers "Content-Disposition")))
+ (is (every? #(str/starts-with? % "my-export_2/") (entry-names body)))))
+ (testing "a percent-encoded dirname, as the default name has for a non-ASCII site name, is accepted"
+ (is (= "attachment; filename=\"%E4%B8%AD-2026-10-27_12-00.tar.gz\""
+ (-> (mt/user-http-request-full-response
+ :crowberto :post 200 "ee/serialization/export" {}
+ :dirname "%E4%B8%AD-2026-10-27_12-00" :all_collections false :data_model false :settings false)
+ (get-in [:headers "Content-Disposition"])))))
+ (testing "the default dirname for a long non-ASCII site name passes the dirname rule when sent back"
+ (mt/with-temporary-setting-values [site-name (apply str (repeat 40 "中"))]
+ (let [default-dirname (->> (mt/user-http-request-full-response
+ :crowberto :post 200 "ee/serialization/export" {}
+ :all_collections false :data_model false :settings false)
+ :headers
+ (#(get % "Content-Disposition"))
+ (re-find #"filename=\"(.*)\.tar\.gz\"")
+ second)]
+ (is (<= (count default-dirname) 255))
+ (mt/user-http-request :crowberto :post 200 "ee/serialization/export" {}
+ :dirname default-dirname :all_collections false :data_model false :settings false))))))
+
(defn- search-result-count [model search-string]
(:total
(search/search
diff --git a/enterprise/backend/test/metabase_enterprise/stale/api_test.clj b/enterprise/backend/test/metabase_enterprise/stale/api_test.clj
index f35e231d9a2..11a5990245e 100644
--- a/enterprise/backend/test/metabase_enterprise/stale/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/stale/api_test.clj
@@ -138,6 +138,13 @@
(map :name)
set)))))))))
+(deftest malformed-before-date-is-a-400-test
+ (mt/with-premium-features #{:collection-cleanup}
+ (testing "An unparseable before_date is a client error, not a server error"
+ (is (= "invalid before_date: 'not-a-date' expected format: 'yyyy-MM-dd'"
+ (mt/user-http-request :crowberto :get 400 "ee/stale/root"
+ :before_date "not-a-date"))))))
+
(deftest can-fetch-stale-candidates-2
(mt/with-premium-features #{:collection-cleanup}
(testing "I can get stale items from the root collection"
diff --git a/resources/openapi/openapi.json b/resources/openapi/openapi.json
index 1e42661908a..5b444d6e881 100644
--- a/resources/openapi/openapi.json
+++ b/resources/openapi/openapi.json
@@ -29005,11 +29005,13 @@
"type" : "integer"
}
}, {
+ "description" : "value must be an integer greater than zero.",
"in" : "query",
"name" : "model_id",
"required" : true,
"schema" : {
- "type" : "string"
+ "minimum" : 1,
+ "type" : "integer"
}
}, {
"in" : "query",
@@ -29020,6 +29022,17 @@
"type" : "string"
}
} ],
+ "requestBody" : {
+ "content" : {
+ "application/json" : {
+ "schema" : {
+ "additionalProperties" : false,
+ "properties" : { },
+ "type" : "object"
+ }
+ }
+ }
+ },
"responses" : {
"2XX" : {
"content" : {
@@ -31150,12 +31163,14 @@
"description" : "Serialize and retrieve Metabase instance.\n\n Outputs `.tar.gz` file with serialization results and an `export.log` file.\n On error outputs serialization logs directly.",
"operationId" : "post-api-ee-serialization-export",
"parameters" : [ {
- "description" : "name of directory and archive file (default: `<instance-name>-<YYYY-MM-dd_HH-mm>`)",
+ "description" : "name of directory and archive file (default: `<instance-name>-<YYYY-MM-dd_HH-mm>`): 1-255 characters from A-Z a-z 0-9 _ - . %, not starting with . or -",
"in" : "query",
"name" : "dirname",
"required" : false,
"schema" : {
"oneOf" : [ {
+ "description" : "name of directory and archive file (default: `<instance-name>-<YYYY-MM-dd_HH-mm>`): 1-255 characters from A-Z a-z 0-9 _ - . %, not starting with . or -",
+ "pattern" : "^[A-Za-z0-9_%][A-Za-z0-9._%-]{0,254}$",
"type" : "string"
}, {
"type" : "null"
@@ -31189,7 +31204,7 @@
}, {
"in" : "query",
"name" : "all_collections",
- "required" : true,
+ "required" : false,
"schema" : {
"default" : true,
"type" : "boolean"
@@ -31197,7 +31212,7 @@
}, {
"in" : "query",
"name" : "settings",
- "required" : true,
+ "required" : false,
"schema" : {
"default" : true,
"type" : "boolean"
@@ -31205,7 +31220,7 @@
}, {
"in" : "query",
"name" : "data_model",
- "required" : true,
+ "required" : false,
"schema" : {
"default" : true,
"type" : "boolean"
@@ -31213,15 +31228,7 @@
}, {
"in" : "query",
"name" : "field_values",
- "required" : true,
- "schema" : {
- "default" : false,
- "type" : "boolean"
- }
- }, {
- "in" : "query",
- "name" : "database_secrets",
- "required" : true,
+ "required" : false,
"schema" : {
"default" : false,
"type" : "boolean"
@@ -31229,7 +31236,7 @@
}, {
"in" : "query",
"name" : "continue_on_error",
- "required" : true,
+ "required" : false,
"schema" : {
"default" : false,
"type" : "boolean"
@@ -31237,7 +31244,7 @@
}, {
"in" : "query",
"name" : "full_stacktrace",
- "required" : true,
+ "required" : false,
"schema" : {
"default" : false,
"type" : "boolean"
@@ -43000,13 +43007,14 @@
"tags" : [ "/api/table" ]
},
"put" : {
- "description" : "Update all `Table` in `ids`.\n\n Deprecated, should use PUT /table/edit from now on.",
+ "description" : "Update all `Table` in `ids`.\n\n Deprecated: use `POST /api/data-studio/table/edit`.",
"operationId" : "put-api-table",
"parameters" : [ ],
"requestBody" : {
"content" : {
"application/json" : {
"schema" : {
+ "additionalProperties" : false,
"properties" : {
"caveats" : {
"oneOf" : [ {
@@ -43015,6 +43023,15 @@
"type" : "null"
} ]
},
+ "collection_id" : {
+ "oneOf" : [ {
+ "description" : "value must be an integer greater than zero.",
+ "minimum" : 1,
+ "type" : "integer"
+ }, {
+ "type" : "null"
+ } ]
+ },
"data_authority" : {
"oneOf" : [ {
"$ref" : "#/components/schemas/metabase.warehouse-schema-rest.api.table.data-authority-write"
@@ -43058,6 +43075,14 @@
"type" : "null"
} ]
},
+ "field_order" : {
+ "oneOf" : [ {
+ "enum" : [ "alphabetical", "custom", "database", "smart" ],
+ "type" : "string"
+ }, {
+ "type" : "null"
+ } ]
+ },
"ids" : {
"items" : {
"description" : "value must be an integer greater than zero.",
@@ -45332,9 +45357,9 @@
}, {
"in" : "query",
"name" : "archived",
- "required" : true,
+ "required" : false,
"schema" : {
- "default" : "false",
+ "default" : false,
"type" : "boolean"
}
}, {
diff --git a/src/metabase/notification/models.clj b/src/metabase/notification/models.clj
index 3614c13e53f..32e684b1df9 100644
--- a/src/metabase/notification/models.clj
+++ b/src/metabase/notification/models.clj
@@ -319,7 +319,7 @@
template-type (notification.db/channel-template-channel-type template-id)]
(when (not= channel-type template-type)
(throw (ex-info "Channel type and template type mismatch"
- {:status 400
+ {:status-code 400
:channel-type channel-type
:template-type template-type}))))))
diff --git a/src/metabase/timeline/api/timeline.clj b/src/metabase/timeline/api/timeline.clj
index b035ab8a61b..26b4e594ba6 100644
--- a/src/metabase/timeline/api/timeline.clj
+++ b/src/metabase/timeline/api/timeline.clj
@@ -78,7 +78,7 @@
[:id ms/PositiveInt]]
{:keys [include archived start end]} :- [:map {:closed true}
[:include {:optional true} ::include]
- [:archived {:default :false} ms/BooleanValue]
+ [:archived {:default false} ms/BooleanValue]
[:start {:optional true} ms/TemporalString]
[:end {:optional true} ms/TemporalString]]]
(let [archived? archived
diff --git a/src/metabase/warehouse_schema_rest/api/table.clj b/src/metabase/warehouse_schema_rest/api/table.clj
index 21c3aa0fb62..6e9b73949b9 100644
--- a/src/metabase/warehouse_schema_rest/api/table.clj
+++ b/src/metabase/warehouse_schema_rest/api/table.clj
@@ -184,10 +184,9 @@
(fn [response]
(dissoc response :json_query :context :cached :average_execution_time))))))))))
-(def ^:private TableUpdateBodySingle
- "Body of `PUT /api/table/:id`."
- [:map {:closed true}
- [:display_name {:optional true} [:maybe ms/NonBlankString]]
+(def ^:private table-update-entries
+ "User-settable Table columns, as optional `:map` entries."
+ [[:display_name {:optional true} [:maybe ms/NonBlankString]]
[:entity_type {:optional true} [:maybe EntityType]]
[:visibility_type {:optional true} [:maybe TableVisibilityType]]
[:description {:optional true} [:maybe :string]]
@@ -202,22 +201,15 @@
[:owner_user_id {:optional true} [:maybe :int]]
[:collection_id {:optional true} [:maybe ms/PositiveInt]]])
+(def ^:private TableUpdateBodySingle
+ "Body of `PUT /api/table/:id`."
+ (into [:map {:closed true}] table-update-entries))
+
(def ^:private TableUpdateBodyBulk
"Body of the deprecated `PUT /api/table/`."
- [:map {:closed true}
- [:ids [:sequential ms/PositiveInt]]
- [:display_name {:optional true} [:maybe ms/NonBlankString]]
- [:entity_type {:optional true} [:maybe EntityType]]
- [:visibility_type {:optional true} [:maybe TableVisibilityType]]
- [:description {:optional true} [:maybe :string]]
- [:caveats {:optional true} [:maybe :string]]
- [:points_of_interest {:optional true} [:maybe :string]]
- [:show_in_getting_started {:optional true} [:maybe :boolean]]
- [:data_authority {:optional true} [:maybe ::data-authority-write]]
- [:data_source {:optional true} [:maybe :string]]
- [:data_layer {:optional true} [:maybe :string]]
- [:owner_email {:optional true} [:maybe :string]]
- [:owner_user_id {:optional true} [:maybe :int]]])
+ (into [:map {:closed true}
+ [:ids [:sequential ms/PositiveInt]]]
+ table-update-entries))
(mu/defn ^:private update-table!*
"Takes an existing table and the changes, updates in the database and optionally calls `table/update-field-positions!`
@@ -305,7 +297,7 @@
(api.macros/defendpoint :put "/"
"Update all `Table` in `ids`.
- Deprecated, should use PUT /table/edit from now on."
+ Deprecated: use `POST /api/data-studio/table/edit`."
[_route-params
_query-params
{:keys [ids], :as body} :- TableUpdateBodyBulk]
diff --git a/test/metabase/notification/api/notification_test.clj b/test/metabase/notification/api/notification_test.clj
index a800bdc3148..e2e999058cc 100644
--- a/test/metabase/notification/api/notification_test.clj
+++ b/test/metabase/notification/api/notification_test.clj
@@ -233,7 +233,15 @@
(-> (mt/user-http-request :crowberto :post 200 "notification" {:creator_id (mt/user->id :rasta)
:payload {:card_id card-id}
:payload_type "notification/card"})
- :creator_id)))))))
+ :creator_id))))
+ (testing "a handler whose template has another channel type is a 400"
+ (mt/with-temp [:model/ChannelTemplate {slack-tmpl-id :id} {:channel_type :channel/slack}]
+ (is (= "Channel type and template type mismatch"
+ (mt/user-http-request :crowberto :post 400 "notification"
+ {:payload {:card_id card-id}
+ :payload_type "notification/card"
+ :handlers [{:channel_type "channel/email"
+ :template_id slack-tmpl-id}]}))))))))
(deftest notification-with-custom-template-test
(mt/with-model-cleanup [:model/Notification]
diff --git a/test/metabase/timeline/api/timeline_test.clj b/test/metabase/timeline/api/timeline_test.clj
index 5517acc11a4..59ce78a52eb 100644
--- a/test/metabase/timeline/api/timeline_test.clj
+++ b/test/metabase/timeline/api/timeline_test.clj
@@ -66,6 +66,20 @@
(is (= '()
(->> (collection-timelines-request coll-c true) first :events)))))))
+(deftest timeline-events-archived-test
+ (testing "GET /api/timeline/:id?include=events"
+ (mt/with-temp [:model/Timeline tl {:name "Timeline"}
+ :model/TimelineEvent _event {:name "event" :timeline_id (u/the-id tl)}
+ :model/TimelineEvent _event-old {:name "event-old" :timeline_id (u/the-id tl) :archived true}]
+ (testing "without `archived` returns only un-archived events"
+ (is (= #{"event"}
+ (event-names [(mt/user-http-request :rasta :get 200 (str "timeline/" (u/the-id tl))
+ :include "events")]))))
+ (testing "with `archived=true` returns archived and un-archived events"
+ (is (= #{"event" "event-old"}
+ (event-names [(mt/user-http-request :rasta :get 200 (str "timeline/" (u/the-id tl))
+ :include "events" :archived true)])))))))
+
(deftest collection-archived-timelines-test
(testing "GET /api/timeline/collection/:id?archived=true returns only archived timelines"
(mt/with-temp [:model/Collection coll-b {:name "Collection B"}
diff --git a/test/metabase/warehouse_schema_rest/api/table_test.clj b/test/metabase/warehouse_schema_rest/api/table_test.clj
index b852c0d00a4..4cd0a5d0116 100644
--- a/test/metabase/warehouse_schema_rest/api/table_test.clj
+++ b/test/metabase/warehouse_schema_rest/api/table_test.clj
@@ -8,6 +8,7 @@
[clojure.test :refer :all]
[metabase.api.response :as api.response]
[metabase.api.test-util :as api.test-util]
+ [metabase.collections.core :as collections]
[metabase.driver :as driver]
[metabase.driver.sql-jdbc.connection :as sql-jdbc.conn]
[metabase.driver.util :as driver.u]
@@ -1609,6 +1610,55 @@
(is (= [nil nil]
(map #(user-table-fn :visibility_type %) [t1 t2]))))))
+(deftest bulk-update-tables-collection-id-persists-test
+ (testing "PUT /api/table with an ids vector sets collection_id on every listed table"
+ (mt/with-temp [:model/Collection {coll-id :id} {:type collections/library-data-collection-type}
+ :model/Table {t1 :id} {:db_id (mt/id)}
+ :model/Table {t2 :id} {:db_id (mt/id)}]
+ (mt/user-http-request :crowberto :put 200 "table"
+ {:ids [t1 t2] :collection_id coll-id})
+ (is (= [coll-id coll-id]
+ (map #(user-table-fn :collection_id %) [t1 t2])))
+ (testing "and leaves is_published as it was, as PUT /api/table/:id does"
+ (is (= [false false]
+ (map #(user-table-fn :is_published %) [t1 t2])))))))
+
+(deftest bulk-update-tables-collection-id-checks-test
+ (mt/with-temp [:model/Collection {plain-coll-id :id} {}
+ :model/Collection {library-coll-id :id} {:type collections/library-data-collection-type}
+ :model/Table {t1 :id} {:db_id (mt/id)}
+ :model/Table {t2 :id} {:db_id (mt/id)}]
+ (doseq [[desc user status coll-id] [["a missing collection is a 404" :crowberto 404 Integer/MAX_VALUE]
+ ["a collection outside the Library is a 400" :crowberto 400 plain-coll-id]
+ ["a non-admin is a 403" :rasta 403 library-coll-id]]]
+ (testing (str "PUT /api/table with collection_id: " desc)
+ (mt/user-http-request user :put status "table"
+ {:ids [t1 t2] :collection_id coll-id})
+ (is (= [nil nil]
+ (map #(user-table-fn :collection_id %) [t1 t2])))))))
+
+(deftest bulk-update-tables-field-order-persists-test
+ (testing "PUT /api/table with an ids vector sets field_order on every listed table"
+ (mt/with-temp [:model/Table {t1 :id} {:db_id (mt/id)}
+ :model/Table {t2 :id} {:db_id (mt/id)}
+ :model/Field _ {:table_id t1 :name "b" :database_position 0 :position 0}
+ :model/Field _ {:table_id t1 :name "a" :database_position 1 :position 1}
+ :model/Field _ {:table_id t2 :name "d" :database_position 0 :position 0}
+ :model/Field _ {:table_id t2 :name "c" :database_position 1 :position 1}]
+ (let [response (mt/user-http-request :crowberto :put 200 "table"
+ {:ids [t1 t2] :field_order "alphabetical"})]
+ (is (= [:alphabetical :alphabetical]
+ (map #(user-table-fn :field_order %) [t1 t2])))
+ (testing "the response lists each table's fields in the new order"
+ (is (= {t1 ["a" "b"] t2 ["c" "d"]}
+ (into {} (map (juxt :id #(map :name (:fields %)))) response))))
+ (testing "the new positions are stored"
+ (is (= [["a" "b"] ["c" "d"]]
+ (for [table-id [t1 t2]]
+ (->> (t2/hydrate (t2/select-one :model/Table :id table-id) :fields)
+ :fields
+ (map :name))))))))))
+
;;; ---------------------------------- #83937 dimension-backfill canary -----------------------------------
(defn- counting-dimension-pairs