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
2627bdf6
Unverified
Commit
2627bdf6
authored
2 years ago
by
metamben
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Hydrate app ID on app collection bookmarks (#25024)
parent
e9d84d5d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/models/bookmark.clj
+7
-3
7 additions, 3 deletions
src/metabase/models/bookmark.clj
test/metabase/api/bookmark_test.clj
+10
-6
10 additions, 6 deletions
test/metabase/api/bookmark_test.clj
with
17 additions
and
9 deletions
src/metabase/models/bookmark.clj
+
7
−
3
View file @
2627bdf6
(
ns
metabase.models.bookmark
(
:require
[
clojure.string
:as
str
]
[
metabase.db.connection
:as
mdb.connection
]
[
metabase.models.app
:refer
[
App
]]
[
metabase.models.card
:refer
[
Card
]]
[
metabase.models.collection
:refer
[
Collection
]]
[
metabase.models.dashboard
:refer
[
Dashboard
]]
...
...
@@ -30,7 +31,8 @@
(
s/optional-key
:dataset
)
(
s/maybe
s/Bool
)
(
s/optional-key
:display
)
(
s/maybe
s/Str
)
(
s/optional-key
:authority_level
)
(
s/maybe
s/Str
)
(
s/optional-key
:description
)
(
s/maybe
s/Str
)})
(
s/optional-key
:description
)
(
s/maybe
s/Str
)
(
s/optional-key
:app_id
)
(
s/maybe
su/IntGreaterThanOrEqualToZero
)})
(
s/defn
^
:private
normalize-bookmark-result
:-
BookmarkResult
"Normalizes bookmark results. Bookmarks are left joined against the card, collection, and dashboard tables, but only
...
...
@@ -41,7 +43,7 @@
normalized-result
(
zipmap
(
map
unqualify-key
(
keys
result
))
(
vals
result
))
id-str
(
str
(
:type
normalized-result
)
"-"
(
:item_id
normalized-result
))]
(
->
normalized-result
(
select-keys
[
:item_id
:type
:name
:dataset
:description
:display
:authority_level
])
(
select-keys
[
:item_id
:type
:name
:dataset
:description
:display
:authority_level
:app_id
])
(
assoc
:id
id-str
))))
(
defn-
bookmarks-union-query
...
...
@@ -91,11 +93,13 @@
[
:collection.name
(
db/qualify
'Collection
:name
)]
[
:collection.authority_level
(
db/qualify
'Collection
:authority_level
)]
[
:collection.description
(
db/qualify
'Collection
:description
)]
[
:collection.archived
(
db/qualify
'Collection
:archived
)]]
[
:collection.archived
(
db/qualify
'Collection
:archived
)]
[
:app.id
(
db/qualify
'Collection
:app_id
)]]
:from
[[(
bookmarks-union-query
user-id
)
:bookmark
]]
:left-join
[[
Card
:card
]
[
:=
:bookmark.card_id
:card.id
]
[
Dashboard
:dashboard
]
[
:=
:bookmark.dashboard_id
:dashboard.id
]
[
Collection
:collection
]
[
:=
:bookmark.collection_id
:collection.id
]
[
App
:app
]
[
:=
:app.collection_id
:collection.id
]
[
BookmarkOrdering
:bookmark_ordering
]
[
:and
[
:=
:bookmark_ordering.user_id
user-id
]
[
:=
:bookmark_ordering.type
:bookmark.type
]
...
...
This diff is collapsed.
Click to expand it.
test/metabase/api/bookmark_test.clj
+
10
−
6
View file @
2627bdf6
(
ns
metabase.api.bookmark-test
"Tests for /api/bookmark endpoints."
(
:require
[
clojure.test
:refer
:all
]
[
metabase.models.app
:refer
[
App
]]
[
metabase.models.bookmark
:refer
[
BookmarkOrdering
CardBookmark
CollectionBookmark
DashboardBookmark
]]
...
...
@@ -16,7 +17,8 @@
(
testing
"POST /api/bookmark/:model/:model-id"
(
mt/with-temp*
[
Collection
[
collection
{
:name
"Test Collection"
}]
Card
[
card
{
:name
"Test Card"
:display
"area"
}]
Dashboard
[
dashboard
{
:name
"Test Dashboard"
}]]
Dashboard
[
dashboard
{
:name
"Test Dashboard"
}]
App
[
app
{
:collection_id
(
:id
collection
)
,
:dashboard_id
(
:id
dashboard
)}]]
(
testing
"check that we can bookmark a Collection"
(
is
(
=
(
u/the-id
collection
)
(
->>
(
mt/user-http-request
:rasta
:post
200
(
str
"bookmark/collection/"
(
u/the-id
collection
)))
...
...
@@ -26,7 +28,7 @@
(
->>
(
mt/user-http-request
:rasta
:post
200
(
str
"bookmark/card/"
(
u/the-id
card
)))
:card_id
))))
(
let
[
card-result
(
->>
(
mt/user-http-request
:rasta
:get
200
"bookmark"
)
(
filter
#
(
=
(
:type
%
)
"card"
))
(
filter
#
(
=
(
:type
%
)
"card"
))
first
)]
(
testing
"check a card bookmark has `:display` key"
(
is
(
contains?
card-result
:display
)))
...
...
@@ -37,10 +39,12 @@
(
->>
(
mt/user-http-request
:rasta
:post
200
(
str
"bookmark/dashboard/"
(
u/the-id
dashboard
)))
:dashboard_id
))))
(
testing
"check that we can retreive the user's bookmarks"
(
is
(
=
#
{
"card"
"collection"
"dashboard"
}
(
->>
(
mt/user-http-request
:rasta
:get
200
"bookmark"
)
(
map
:type
)
set
))))
(
let
[
result
(
mt/user-http-request
:rasta
:get
200
"bookmark"
)]
(
is
(
=
#
{
"card"
"collection"
"dashboard"
}
(
into
#
{}
(
map
:type
)
result
)))
(
testing
"that app_id is hydrated on app collections"
(
is
(
partial=
[{
:app_id
(
:id
app
)}]
(
filter
#
(
=
(
:type
%
)
"collection"
)
result
))))))
(
testing
"check that we can delete bookmarks"
(
mt/user-http-request
:rasta
:delete
204
(
str
"bookmark/card/"
(
u/the-id
card
)))
(
is
(
=
#
{
"collection"
"dashboard"
}
...
...
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