Skip to content
Snippets Groups Projects
Unverified Commit 028df278 authored by Tom Robinson's avatar Tom Robinson
Browse files

Merge branch 'collections' of github.com:metabase/metabase into collections

parents 9fe2de99 100e350c
Branches
Tags
No related merge requests found
......@@ -172,7 +172,15 @@ Update a `Card`.
## `GET /api/collection/`
Fetch a list of all (non-archived) Collections that the current user has read permissions for.
Fetch a list of all Collections that the current user has read permissions for.
This includes `:can_write`, which means whether the current user is allowed to add or remove Cards to this Collection; keep in mind
that regardless of this status you must be a superuser to modify properties of Collections themselves.
By default, this returns non-archived Collections, but instead you can show archived ones by passing `?archived=true`.
##### PARAMS:
* **`archived`** value may be nil, or if non-nil, value must be a valid boolean (true or false).
## `GET /api/collection/:id`
......
......@@ -6,14 +6,21 @@
[metabase.db :as db]
(metabase.models [card :refer [Card]]
[collection :refer [Collection], :as collection]
[hydrate :refer [hydrate]]
[interface :as models])
[metabase.util.schema :as su]))
(api/defendpoint GET "/"
"Fetch a list of all (non-archived) Collections that the current user has read permissions for."
[]
(filterv models/can-read? (db/select Collection :archived false {:order-by [[:%lower.name :asc]]})))
"Fetch a list of all Collections that the current user has read permissions for.
This includes `:can_write`, which means whether the current user is allowed to add or remove Cards to this Collection; keep in mind
that regardless of this status you must be a superuser to modify properties of Collections themselves.
By default, this returns non-archived Collections, but instead you can show archived ones by passing `?archived=true`."
[archived]
{archived (s/maybe su/BooleanString)}
(-> (filterv models/can-read? (db/select Collection :archived (Boolean/parseBoolean archived) {:order-by [[:%lower.name :asc]]}))
(hydrate :can_write)))
(api/defendpoint GET "/:id"
"Fetch a specific (non-archived) Collection, including cards that belong to it."
......
......@@ -60,7 +60,7 @@
* `(partial current-user-has-full-permissions? :read)` (you must also implement `perms-objects-set` to use this)
* `(partial current-user-has-partial-permissions? :read)` (you must also implement `perms-objects-set` to use this)")
(can-write? ^Boolean [instance], ^Boolean [entity, ^Integer id]
(^{:hydrate :can_write} can-write? ^Boolean [instance], ^Boolean [entity, ^Integer id]
"Return whether `*current-user*` has *write* permissions for an object. You should use one of these implmentations:
* `(constantly true)`
......
......@@ -32,6 +32,15 @@
(perms/grant-collection-read-permissions! (group/all-users) collection-2)
(map :name ((user->client :rasta) :get 200 "collection"))))
;; Check that if we pass `?archived=true` we instead see archived cards
(tu/expect-with-temp [Collection [collection-1 {:name "Archived Collection", :archived true}]
Collection [collection-2 {:name "Regular Collection"}]]
["Archived Collection"]
(do
(perms/grant-collection-read-permissions! (group/all-users) collection-1)
(perms/grant-collection-read-permissions! (group/all-users) collection-2)
(map :name ((user->client :rasta) :get 200 "collection" :archived :true))))
;; check that we can see collection details (GET /api/collection/:id)
(expect
"Coin Collection"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment