Skip to content
Snippets Groups Projects
Unverified Commit 9cf39ef1 authored by Daniel Higginbotham's avatar Daniel Higginbotham Committed by GitHub
Browse files

permissions bugs (#10918)

fix bugs around setting data permissions for new database
parent 44e8d06f
No related branches found
No related tags found
No related merge requests found
...@@ -9,7 +9,9 @@ ...@@ -9,7 +9,9 @@
[util :as u]] [util :as u]]
[metabase.api.common :as api-common] [metabase.api.common :as api-common]
[metabase.models.interface :as mi] [metabase.models.interface :as mi]
[toucan.db :as tdb])) [metabase.test.util] ;; extensions
[toucan.db :as tdb]
[toucan.util.test :as tt]))
(defn init! (defn init!
[] []
...@@ -31,12 +33,16 @@ ...@@ -31,12 +33,16 @@
(stop!) (stop!)
(start!)) (start!))
(defn run-tests (defn reload-run-tests
[& ns-names] [& ns-names]
(doseq [ns-name ns-names] (doseq [ns-name ns-names]
(require ns-name :reload)) (require ns-name :reload))
(expectations/run-tests ns-names)) (expectations/run-tests ns-names))
(defn run-tests
[& ns-names]
(expectations/run-tests ns-names))
(defmacro require-model (defmacro require-model
"Rather than requiring all models inn the ns declaration, make it easy to require the ones you need for your current session" "Rather than requiring all models inn the ns declaration, make it easy to require the ones you need for your current session"
[model-sym] [model-sym]
......
...@@ -42,8 +42,9 @@ ...@@ -42,8 +42,9 @@
(defn- dejsonify-dbs [dbs] (defn- dejsonify-dbs [dbs]
(into {} (for [[db-id {:keys [native schemas]}] dbs] (into {} (for [[db-id {:keys [native schemas]}] dbs]
{(->int db-id) {:native (keyword native) {(->int db-id) (cond-> {}
:schemas (dejsonify-schemas schemas)}}))) native (assoc :native (keyword native))
schemas (assoc :schemas (dejsonify-schemas schemas)))})))
(defn- dejsonify-groups [groups] (defn- dejsonify-groups [groups]
(into {} (for [[group-id dbs] groups] (into {} (for [[group-id dbs] groups]
......
...@@ -697,7 +697,8 @@ ...@@ -697,7 +697,8 @@
returns the newly created `PermissionsRevision` entry." returns the newly created `PermissionsRevision` entry."
([new-graph :- StrictPermissionsGraph] ([new-graph :- StrictPermissionsGraph]
(let [old-graph (graph) (let [old-graph (graph)
[old new] (data/diff (:groups old-graph) (:groups new-graph))] [old new] (data/diff (:groups old-graph) (:groups new-graph))
old (or old {})]
(when (or (seq old) (seq new)) (when (or (seq old) (seq new))
(log-permissions-changes old new) (log-permissions-changes old new)
(check-revision-numbers old-graph new-graph) (check-revision-numbers old-graph new-graph)
......
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
"Tests for `/api/permissions` endpoints." "Tests for `/api/permissions` endpoints."
(:require [expectations :refer :all] (:require [expectations :refer :all]
[metabase.models [metabase.models
[database :refer [Database]]
[permissions :as perms] [permissions :as perms]
[permissions-group :as group :refer [PermissionsGroup]]] [permissions-group :as group :refer [PermissionsGroup]]
[table :refer [Table]]]
[metabase.test.data :as data] [metabase.test.data :as data]
[metabase.test.data.users :as test-users] [metabase.test.data.users :as test-users]
[metabase.util :as u] [metabase.util :as u]
...@@ -70,3 +72,19 @@ ...@@ -70,3 +72,19 @@
[:groups (u/get-id group) (data/id) :schemas] [:groups (u/get-id group) (data/id) :schemas]
{"PUBLIC" {(data/id :venues) {:read :all, :query :segmented}}})) {"PUBLIC" {(data/id :venues) {:read :all, :query :segmented}}}))
(get-in (perms/graph) [:groups (u/get-id group) (data/id) :schemas "PUBLIC"]))) (get-in (perms/graph) [:groups (u/get-id group) (data/id) :schemas "PUBLIC"])))
;; permissions for new dba
(expect
:all
(let [new-id (inc (data/id))]
(tt/with-temp* [PermissionsGroup [group]
Database [{db-id :id}]
Table [_ {:db_id db-id}]]
(test-users/create-users-if-needed!)
((test-users/user->client :crowberto) :put 200 "permissions/graph"
(assoc-in (perms/graph)
[:groups (u/get-id group) db-id :schemas]
:all))
(get-in (perms/graph) [:groups (u/get-id group) db-id :schemas]))))
;; figure out failing case for when old doesn't exist
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