Skip to content

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

Use a generic error message for the parameter-permission 403 (#81762)

Nicola Mometto0b4bbf042786
diff --git a/src/metabase/query_permissions/impl.clj b/src/metabase/query_permissions/impl.clj
index 77cd2fe0338..c5c9d513cf9 100644
--- a/src/metabase/query_permissions/impl.clj
+++ b/src/metabase/query_permissions/impl.clj
@@ -466,12 +466,8 @@
(doseq [table-id table-ids
:let [database-id (table-id->database-id table-id)]]
(when-not (can-query-table? database-id table-id)
- (throw (ex-info (tru "You must have data permissions to add a parameter referencing the Table {0}."
- (pr-str (t2/select-one-fn :name :model/Table :id table-id)))
- {:status-code 403
- :database-id database-id
- :table-id table-id
- :actual-permissions @api/*current-user-permissions-set*})))))))
+ (throw (ex-info (tru "You must have data permissions to add a parameter referencing this Field.")
+ {:status-code 403})))))))
(mu/defn check-run-permissions-for-query
"Make sure the Current User has the appropriate permissions to run `query`. We don't want Users saving Cards with
diff --git a/test/metabase/dashboards_rest/api_test.clj b/test/metabase/dashboards_rest/api_test.clj
index 202376e5df1..8e6925933f7 100644
--- a/test/metabase/dashboards_rest/api_test.clj
+++ b/test/metabase/dashboards_rest/api_test.clj
@@ -2415,14 +2415,14 @@
(do-with-add-card-parameter-mapping-permissions-fixtures!
(fn [{:keys [card-id mappings add-card! dashcards]}]
(data-perms/set-database-permission! (perms-group/all-users) (mt/id) :perms/view-data :unrestricted)
- (is (=? {:message "You must have data permissions to add a parameter referencing the Table \"VENUES\"."}
- (add-card! 403)))
+ (is (= "You must have data permissions to add a parameter referencing this Field."
+ (add-card! 403)))
(is (= []
(dashcards)))
(testing "Permissions for a different table in the same DB should not count"
(data-perms/set-table-permission! (perms-group/all-users) (mt/id :categories) :perms/create-queries :query-builder)
- (is (=? {:message "You must have data permissions to add a parameter referencing the Table \"VENUES\"."}
- (add-card! 403)))
+ (is (= "You must have data permissions to add a parameter referencing this Field."
+ (add-card! 403)))
(is (= []
(dashcards))))
(testing "If they have data permissions, it should be ok"
@@ -2535,8 +2535,8 @@
(do-with-update-cards-parameter-mapping-permissions-fixtures!
(fn [{:keys [dashboard-id card-id original-mappings update-mappings! update-size! new-dashcard-info new-mappings]}]
(testing "Should *NOT* be allowed to update the `:parameter_mappings` without proper data permissions"
- (is (=? {:message "You must have data permissions to add a parameter referencing the Table \"VENUES\"."}
- (update-mappings! 403)))
+ (is (= "You must have data permissions to add a parameter referencing this Field."
+ (update-mappings! 403)))
(is (= original-mappings
(t2/select-one-fn :parameter_mappings :model/DashboardCard :dashboard_id dashboard-id, :card_id card-id))))
(testing "Changing another column should be ok even without data permissions."
@@ -5857,7 +5857,7 @@
{:dashcards [{:id -1 :card_id card-id :row 0 :col 0 :size_x 4 :size_y 4
:parameter_mappings mapping}]
:tabs []}))]
- (is (=? {:message #"(?i).*data permissions.*PRODUCTS.*"} (put! 403)))
+ (is (= "You must have data permissions to add a parameter referencing this Field." (put! 403)))
(data-perms/set-table-permission! (perms-group/all-users) (mt/id :products) :perms/view-data :unrestricted)
(data-perms/set-table-permission! (perms-group/all-users) (mt/id :products) :perms/create-queries :query-builder)
(is (=? [{:parameter_mappings [{:parameter_id "_ID_"
diff --git a/test/metabase/documents/api/document_test.clj b/test/metabase/documents/api/document_test.clj
index 7150ff4aa97..6c5c8694725 100644
--- a/test/metabase/documents/api/document_test.clj
+++ b/test/metabase/documents/api/document_test.clj
@@ -295,9 +295,9 @@
:parameters [{:id "pid" :name "p" :slug "p" :type "category"
:target [:dimension [:field (mt/id :venues :name) nil]]}]}]
(testing "the Card endpoint refuses it — the control"
- (is (re-find #"VENUES"
- (:message (mt/user-http-request :rasta :post 403 "card"
- (assoc card-body :collection_id coll-id))))))
+ (is (= "You must have data permissions to add a parameter referencing this Field."
+ (mt/user-http-request :rasta :post 403 "card"
+ (assoc card-body :collection_id coll-id)))))
(testing "the Document endpoint must refuse it too"
(mt/user-http-request :rasta :post 403 "document/"
{:name "d"
diff --git a/test/metabase/queries_rest/api/card_test.clj b/test/metabase/queries_rest/api/card_test.clj
index 82c338cad0b..8829c925f12 100644
--- a/test/metabase/queries_rest/api/card_test.clj
+++ b/test/metabase/queries_rest/api/card_test.clj
@@ -1571,6 +1571,21 @@
[:trace [:sequential :any]]]
(create-card! :rasta 403))))))))))
+(deftest create-card-parameter-permissions-generic-error-test
+ (testing "POST /api/card"
+ (testing "the 403 for a parameter field the user cannot query names neither the table nor its ids"
+ (mt/with-temp-copy-of-db
+ (mt/with-no-data-perms-for-all-users!
+ ;; the entire response body is the generic message
+ (is (= "You must have data permissions to add a parameter referencing this Field."
+ (mt/user-http-request :rasta :post 403 "card"
+ (assoc (card-with-name-and-query)
+ :parameters [{:id "abc123"
+ :type "category"
+ :name "x"
+ :slug "x"
+ :target [:dimension [:field (mt/id :venues :name) nil]]}])))))))))
+
(deftest ^:parallel create-card-with-type-and-dataset-test
;; Use `:rollback-only` like the sibling tests below. Otherwise, the two Cards created through the API
;; commit and leak into later tests that scan the Card table.