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
65344a05
Unverified
Commit
65344a05
authored
6 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
Include Root Collection in GET /api/collection response
parent
9c201c10
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/api/collection.clj
+23
-11
23 additions, 11 deletions
src/metabase/api/collection.clj
test/metabase/api/collection_test.clj
+10
-5
10 additions, 5 deletions
test/metabase/api/collection_test.clj
with
33 additions
and
16 deletions
src/metabase/api/collection.clj
+
23
−
11
View file @
65344a05
...
@@ -20,6 +20,8 @@
...
@@ -20,6 +20,8 @@
[
db
:as
db
]
[
db
:as
db
]
[
hydrate
:refer
[
hydrate
]]]))
[
hydrate
:refer
[
hydrate
]]]))
(
declare
root-collection
)
(
api/defendpoint
GET
"/"
(
api/defendpoint
GET
"/"
"Fetch a list of all Collections that the current user has read permissions for (`:can_write` is returned as an
"Fetch a list of all Collections that the current user has read permissions for (`:can_write` is returned as an
additional property of each Collection so you can tell which of these you have write permissions for.)
additional property of each Collection so you can tell which of these you have write permissions for.)
...
@@ -28,10 +30,18 @@
...
@@ -28,10 +30,18 @@
`?archived=true`."
`?archived=true`."
[
archived
]
[
archived
]
{
archived
(
s/maybe
su/BooleanString
)}
{
archived
(
s/maybe
su/BooleanString
)}
(
as->
(
db/select
Collection
:archived
(
Boolean/parseBoolean
archived
)
(
let
[
archived?
(
Boolean/parseBoolean
archived
)]
{
:order-by
[[
:%lower.name
:asc
]]})
collections
(
as->
(
db/select
Collection
:archived
archived?
(
filter
mi/can-read?
collections
)
{
:order-by
[[
:%lower.name
:asc
]]})
collections
(
hydrate
collections
:can_write
)))
(
filter
mi/can-read?
collections
)
;; include Root Collection at beginning or results if archived isn't `true`
(
if
archived?
collections
(
cons
(
root-collection
)
collections
))
(
hydrate
collections
:can_write
)
;; remove the :metabase.models.collection/is-root? tag since FE doesn't need it
(
for
[
collection
collections
]
(
dissoc
collection
::collection/is-root?
)))))
;;; --------------------------------- Fetching a single Collection & its 'children' ----------------------------------
;;; --------------------------------- Fetching a single Collection & its 'children' ----------------------------------
...
@@ -121,18 +131,20 @@
...
@@ -121,18 +131,20 @@
{
:model
(
keyword
model
)
{
:model
(
keyword
model
)
:archived?
(
Boolean/parseBoolean
archived
)}))
:archived?
(
Boolean/parseBoolean
archived
)}))
;;; -------------------------------------------- GET /api/collection/root --------------------------------------------
;;; -------------------------------------------- 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"
))
(
api/defendpoint
GET
"/root"
(
api/defendpoint
GET
"/root"
"Return the 'Root' Collection object with standard details added"
"Return the 'Root' Collection object with standard details added"
[]
[]
(
->
(
collection-detail
collection/root-collection
)
(
dissoc
(
root-collection
)
::collection/is-root?
))
;; add in some things for the FE to display since the 'Root' Collection isn't real and wouldn't normally have
;; these things
(
assoc
:name
(
tru
"Our analytics"
)
:id
"root"
)
(
dissoc
::collection/is-root?
)))
(
api/defendpoint
GET
"/root/items"
(
api/defendpoint
GET
"/root/items"
"Fetch objects that the current user should see at their root level. As mentioned elsewhere, the 'Root' Collection
"Fetch objects that the current user should see at their root level. As mentioned elsewhere, the 'Root' Collection
...
...
This diff is collapsed.
Click to expand it.
test/metabase/api/collection_test.clj
+
10
−
5
View file @
65344a05
...
@@ -28,14 +28,16 @@
...
@@ -28,14 +28,16 @@
;; check that we can get a basic list of collections
;; check that we can get a basic list of collections
;; (for the purposes of test purposes remove the personal collections)
;; (for the purposes of test purposes remove the personal collections)
(
tt/expect-with-temp
[
Collection
[
collection
]]
(
tt/expect-with-temp
[
Collection
[
collection
]]
[(
assoc
(
into
{}
collection
)
:can_write
true
)]
[{
:parent_id
nil,
:effective_location
nil,
:effective_ancestors
()
,
:can_write
true,
:name
"Our analytics"
,
:id
"root"
}
(
assoc
(
into
{}
collection
)
:can_write
true
)]
(
for
[
collection
((
user->client
:crowberto
)
:get
200
"collection"
)
(
for
[
collection
((
user->client
:crowberto
)
:get
200
"collection"
)
:when
(
not
(
:personal_owner_id
collection
))]
:when
(
not
(
:personal_owner_id
collection
))]
collection
))
collection
))
;; We should only see our own Personal Collections!
;; We should only see our own Personal Collections!
(
expect
(
expect
[
"Lucky Pigeon's Personal Collection"
]
[
"Our analytics"
"Lucky Pigeon's Personal Collection"
]
(
do
(
do
(
collection-test/force-create-personal-collections!
)
(
collection-test/force-create-personal-collections!
)
;; now fetch those Collections as the Lucky bird
;; now fetch those Collections as the Lucky bird
...
@@ -43,7 +45,8 @@
...
@@ -43,7 +45,8 @@
;; ...unless we are *admins*
;; ...unless we are *admins*
(
expect
(
expect
[
"Crowberto Corv's Personal Collection"
[
"Our analytics"
"Crowberto Corv's Personal Collection"
"Lucky Pigeon's Personal Collection"
"Lucky Pigeon's Personal Collection"
"Rasta Toucan's Personal Collection"
"Rasta Toucan's Personal Collection"
"Trash Bird's Personal Collection"
]
"Trash Bird's Personal Collection"
]
...
@@ -54,7 +57,8 @@
...
@@ -54,7 +57,8 @@
;; check that we don't see collections if we don't have permissions for them
;; check that we don't see collections if we don't have permissions for them
(
expect
(
expect
[
"Collection 1"
[
"Our analytics"
"Collection 1"
"Rasta Toucan's Personal Collection"
]
"Rasta Toucan's Personal Collection"
]
(
tt/with-temp*
[
Collection
[
collection-1
{
:name
"Collection 1"
}]
(
tt/with-temp*
[
Collection
[
collection-1
{
:name
"Collection 1"
}]
Collection
[
collection-2
{
:name
"Collection 2"
}]]
Collection
[
collection-2
{
:name
"Collection 2"
}]]
...
@@ -64,7 +68,8 @@
...
@@ -64,7 +68,8 @@
;; check that we don't see collections if they're archived
;; check that we don't see collections if they're archived
(
expect
(
expect
[
"Rasta Toucan's Personal Collection"
[
"Our analytics"
"Rasta Toucan's Personal Collection"
"Regular Collection"
]
"Regular Collection"
]
(
tt/with-temp*
[
Collection
[
collection-1
{
:name
"Archived Collection"
,
:archived
true
}]
(
tt/with-temp*
[
Collection
[
collection-1
{
:name
"Archived Collection"
,
:archived
true
}]
Collection
[
collection-2
{
:name
"Regular Collection"
}]]
Collection
[
collection-2
{
:name
"Regular Collection"
}]]
...
...
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