diff --git a/src/metabase/api/database.clj b/src/metabase/api/database.clj index 9fd4b44ac26f761d44928641ee0153ed4f5dcedb..1c77dff6070605e851630852d36c88ebc2af6296 100644 --- a/src/metabase/api/database.clj +++ b/src/metabase/api/database.clj @@ -13,6 +13,7 @@ [field :refer [Field]] [hydrate :refer [hydrate]] [interface :as models] + [permissions :as perms] [table :refer [Table]]) (metabase [sample-data :as sample-data] [util :as u]))) @@ -34,11 +35,19 @@ (for [db dbs] (assoc db :tables (get db-id->tables (:id db) []))))) +(defn- add-native-perms-info [dbs] + (for [db dbs] + (let [user-has-perms? (fn [f] (perms/set-has-full-permissions? @*current-user-permissions-set* (f (u/get-id db))))] + (assoc db :native_permissions (cond + (user-has-perms? perms/native-readwrite-path) :readwrite + (user-has-perms? perms/native-read-path) :read + :else :none))))) + (defn- dbs-list [include-tables?] (when-let [dbs (seq (filter models/can-read? (db/select Database {:order-by [:%lower.name]})))] - (if-not include-tables? - dbs - (add-tables dbs)))) + (add-native-perms-info (if-not include-tables? + dbs + (add-tables dbs))))) (defendpoint GET "/" "Fetch all `Databases`." diff --git a/src/metabase/models/card.clj b/src/metabase/models/card.clj index d08020efd4b83fc7f9e0ce2ed8485a889bfd7e1a..ffa4f0db257f12c8f7cd577fda62b2261b400db7 100644 --- a/src/metabase/models/card.clj +++ b/src/metabase/models/card.clj @@ -36,6 +36,7 @@ (db/select Label, :id [:in label-ids], {:order-by [:%lower.name]}) [])) + ;;; ------------------------------------------------------------ Permissions Checking ------------------------------------------------------------ (defn- permissions-path-set:mbql [{database-id :database, :as query}] diff --git a/test/metabase/api/database_test.clj b/test/metabase/api/database_test.clj index 1bf92fc37dda2996e78c48448f51902d72da8bd4..764ee504cca7b904973be31cf52b7cc9c7c3376d 100644 --- a/test/metabase/api/database_test.clj +++ b/test/metabase/api/database_test.clj @@ -163,6 +163,7 @@ :id $ :updated_at $ :name "test-data" + :native_permissions "readwrite" :is_sample false :is_full_sync true :description nil @@ -175,6 +176,7 @@ :id $ :updated_at $ :name $ + :native_permissions "readwrite" :is_sample false :is_full_sync true :description nil @@ -195,6 +197,7 @@ :id $ :updated_at $ :name $ + :native_permissions "readwrite" :is_sample false :is_full_sync true :description nil @@ -211,6 +214,7 @@ :id $ :updated_at $ :name "test-data" + :native_permissions "readwrite" :is_sample false :is_full_sync true :description nil