Skip to content
Snippets Groups Projects
Commit 100e350c authored by Cam Saül's avatar Cam Saül
Browse files

Include :can_write with GET /api/collection

parent a1cccd1b
No related branches found
No related tags found
No related merge requests found
......@@ -173,11 +173,14 @@ Update a `Card`.
## `GET /api/collection/`
Fetch a list of all Collections that the current user has read permissions for.
By default, this returns non-archived Collections, but you
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 boolean.
* **`archived`** value may be nil, or if non-nil, value must be a valid boolean (true or false).
## `GET /api/collection/:id`
......
......@@ -6,16 +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 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]]})))
(-> (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)`
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment