Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
792260c8
Unverified
Commit
792260c8
authored
6 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
Hydrating personal_collection_id should force creation of Personal Collections
parent
dcc4870d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/models/collection.clj
+6
-1
6 additions, 1 deletion
src/metabase/models/collection.clj
test/metabase/models/collection_test.clj
+11
-2
11 additions, 2 deletions
test/metabase/models/collection_test.clj
with
17 additions
and
3 deletions
src/metabase/models/collection.clj
+
6
−
1
View file @
792260c8
...
...
@@ -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
))))))))
This diff is collapsed.
Click to expand it.
test/metabase/models/collection_test.clj
+
11
−
2
View file @
792260c8
...
...
@@ -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" |
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment