Skip to content
Snippets Groups Projects
Unverified Commit eadff81f authored by Cam Saul's avatar Cam Saul
Browse files

Add root collection to effective_ancestors

parent ecf627cd
No related branches found
No related tags found
No related merge requests found
......@@ -135,11 +135,7 @@
;;; -------------------------------------------- GET /api/collection/root --------------------------------------------
(defn- root-collection []
;; add in some things for the FE to display since the 'Root' Collection isn't real and wouldn't normally have
;; these things
(assoc (collection-detail collection/root-collection)
:name (tru "Our analytics")
:id "root"))
(collection-detail collection/root-collection-with-ui-details))
(api/defendpoint GET "/root"
"Return the 'Root' Collection object with standard details added"
......
......@@ -184,6 +184,12 @@
"Special placeholder object representing the Root Collection, which isn't really a real Collection."
(map->RootCollection {::is-root? true}))
(def ^RootCollection root-collection-with-ui-details
"The special Root Collection placeholder object with some extra details to facilitate displaying it on the FE."
(assoc root-collection
:name (tru "Our analytics")
:id "root"))
(defn- is-root-collection? [x]
(instance? RootCollection x))
......@@ -273,7 +279,7 @@
(when-let [ancestor-ids (seq (location-path->ids location))]
(db/select [Collection :name :id] :id [:in ancestor-ids] {:order-by [:%lower.name]})))
(s/defn effective-ancestors :- [CollectionInstance]
(s/defn effective-ancestors :- [(s/cond-pre RootCollection CollectionInstance)]
"Fetch the ancestors of a `collection`, filtering out any ones the current User isn't allowed to see. This is used
in the UI to power the 'breadcrumb' path to the location of a given Collection. For example, suppose we have four
Collections, nested like:
......@@ -282,11 +288,11 @@
The ancestors of D are:
A > B > C
[Root] > A > B > C
If the current User is allowed to see A and C, but not B, `effective-ancestors` of D will be:
A > C
[Root] > A > C
Thus the existence of C will be kept hidden from the current User, and for all intents and purposes the current User
can effectively treat A as the parent of C."
......@@ -294,7 +300,7 @@
[collection :- CollectionWithLocationAndIDOrRoot]
(if (is-root-collection? collection)
[]
(filter i/can-read? (ancestors collection))))
(filter i/can-read? (cons root-collection-with-ui-details (ancestors collection)))))
(s/defn parent-id :- (s/maybe su/IntGreaterThanZero)
"Get the immediate parent `collection` id, if set."
......
......@@ -190,7 +190,7 @@
:can_write true
:name "Lucky Pigeon's Personal Collection"
:personal_owner_id (user->id :lucky)
:effective_ancestors ()
:effective_ancestors [{:metabase.models.collection/is-root? true, :name "Our analytics", :id "root", :can_write true}]
:effective_location "/"
:parent_id nil
:id (u/get-id (collection/user->personal-collection (user->id :lucky)))
......
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