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

Hydrating personal_collection_id should force creation of Personal Collections

parent dcc4870d
Branches
Tags
No related merge requests found
......@@ -1002,7 +1002,12 @@
{:batched-hydrate :personal_collection_id}
[users]
(when (seq users)
;; efficiently create a map of user ID -> personal collection ID
(let [user-id->collection-id (db/select-field->id :personal_owner_id Collection
:personal_owner_id [:in (set (map u/get-id users))])]
;; now for each User, try to find the corresponding ID out of that map. If it's not present (the personal
;; Collection hasn't been created yet), then instead call `user->personal-collection-id`, which will create it
;; as a side-effect. This will ensure this property never comes back as `nil`
(for [user users]
(assoc user :personal_collection_id (user-id->collection-id (u/get-id user)))))))
(assoc user :personal_collection_id (or (user-id->collection-id (u/get-id user))
(user->personal-collection-id (u/get-id user))))))))
......@@ -7,14 +7,16 @@
[card :refer [Card]]
[collection :as collection :refer [Collection]]
[dashboard :refer [Dashboard]]
[permissions :refer [Permissions] :as perms]
[permissions :as perms :refer [Permissions]]
[permissions-group :as group :refer [PermissionsGroup]]
[pulse :refer [Pulse]]
[user :refer [User]]]
[metabase.test.data.users :as test-users]
[metabase.test.util :as tu]
[metabase.util :as u]
[toucan.db :as db]
[toucan
[db :as db]
[hydrate :refer [hydrate]]]
[toucan.util.test :as tt]))
(defn force-create-personal-collections!
......@@ -1460,6 +1462,13 @@
(let [personal-collection (collection/user->personal-collection my-cool-user)]
(db/update! Collection (u/get-id personal-collection) :personal_owner_id (test-users/user->id :crowberto)))))
;; Does hydrating `:personal_collection_id` force creation of Personal Collections?
(expect
(tt/with-temp User [temp-user]
(-> (hydrate temp-user :personal_collection_id)
:personal_collection_id
integer?)))
;;; +----------------------------------------------------------------------------------------------------------------+
;;; | Moving Collections "Across the Boundary" |
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment