Skip to content
Snippets Groups Projects
Commit 329af5c5 authored by Cam Saül's avatar Cam Saül Committed by GitHub
Browse files

Merge pull request #3438 from metabase/add-native-permissions-to-GET-database

Add :native_permissions to dbs in GET /api/database :heavy_plus_sign:
parents 5769fdff 5568b231
No related branches found
No related tags found
No related merge requests found
......@@ -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`."
......
......@@ -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}]
......
......@@ -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
......
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