Skip to content

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

Format the blocked table's ID as a plain number in error message (#82772)

Nathan Voxlandf2364b1d2711
diff --git a/src/metabase/query_permissions/impl.clj b/src/metabase/query_permissions/impl.clj
index 3f202e39b65..3b01c2b6f32 100644
--- a/src/metabase/query_permissions/impl.clj
+++ b/src/metabase/query_permissions/impl.clj
@@ -375,7 +375,7 @@
:unrestricted
database-id
%)
- (throw (perms-exception (tru "You do not have permission to view data of table {0} in result_metadata." %)
+ (throw (perms-exception (tru "You do not have permission to view data of table {0} in result_metadata." (str %))
{database-id {:perms/view-data {% :unrestricted}}})))
table-ids)))
diff --git a/test/metabase/query_permissions/impl_test.clj b/test/metabase/query_permissions/impl_test.clj
index 7da4d82ea86..b47e07b06c2 100644
--- a/test/metabase/query_permissions/impl_test.clj
+++ b/test/metabase/query_permissions/impl_test.clj
@@ -385,3 +385,15 @@
(let [query (mt/mbql-query orders)]
(is (false? (query-perms/can-run-query? query)))
(is (false? (query-perms/can-run-query? query false true))))))))
+
+(deftest check-result-metadata-data-perms-error-message-test
+ (testing "the denied table's ID reads as a plain number, with no digit-grouping separator"
+ ;; `tru` runs its arguments through MessageFormat, which formats a bare integer for the current locale: a
+ ;; four-digit ID comes out as "1,595". IDs only reach four digits on busy instances, so the ID is passed as a
+ ;; string to keep the message stable whatever its magnitude.
+ (mt/with-no-data-perms-for-all-users!
+ (mt/with-current-user (mt/user->id :rasta)
+ (is (thrown-with-msg?
+ clojure.lang.ExceptionInfo
+ #"You do not have permission to view data of table 1595 in result_metadata\."
+ (query-perms/check-result-metadata-data-perms (mt/id) [{:name "NAME", :table_id 1595}])))))))