Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update database listing endpoint to account of org.inherits #299

Merged
merged 3 commits into from
Apr 1, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/metabase/api/meta/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@
"Fetch all `Databases` for an `Org`."
[org]
{org Required}
(read-check Org org)
(-> (sel :many Database :organization_id org (order :name))
(hydrate :organization)))
(let-404 [{:keys [id inherits] :as org} (sel :one Org :id org)]
(read-check org)
(-> (if inherits
;; orgs which `inherit` get access to ALL databases
(sel :many Database (order :name))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I just realized you could do this. But you can write

(sel :many Database (order :name) (where (if inherits {}
                                             {:organization_id id})))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! that one's actually been bugging me for a while when we have a part of a query that's conditional. this'll make it much easier to read and reduce redundant code writing queries.

;; otherwise we filter to just databases attached to the org
(sel :many Database :organization_id id (order :name)))
(hydrate :organization))))

(defendpoint POST "/"
"Add a new `Database` for `Org`."
Expand Down