Skip to content

Commit a4d46b1

Browse files
committed
feat: Add shared_docs parameter
This param allows to skip the shared docs list for each sharing, which can be slow and costful for large sharings
1 parent baea78d commit a4d46b1

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

docs/api/cozy-stack-client.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,6 +1895,7 @@ Implements the `DocumentCollection` API along with specific methods for
18951895
**Kind**: global class
18961896

18971897
* [SharingCollection](#SharingCollection)
1898+
* [.findByDoctype(doctype, [options])](#SharingCollection+findByDoctype) ⇒ <code>object</code>
18981899
* [.get(id)](#SharingCollection+get)[<code>Sharing</code>](#Sharing)
18991900
* [.fetchSharedDrives()](#SharingCollection+fetchSharedDrives) ⇒ <code>Promise.&lt;{data: Array.&lt;Sharing&gt;}&gt;</code>
19001901
* [.create(params)](#SharingCollection+create)
@@ -1905,6 +1906,20 @@ Implements the `DocumentCollection` API along with specific methods for
19051906
* [.revokeSelf(sharing)](#SharingCollection+revokeSelf)
19061907
* [.revokeAllRecipients(sharing)](#SharingCollection+revokeAllRecipients)
19071908

1909+
<a name="SharingCollection+findByDoctype"></a>
1910+
1911+
### sharingCollection.findByDoctype(doctype, [options]) ⇒ <code>object</code>
1912+
Finds all sharings for a given doctype
1913+
1914+
**Kind**: instance method of [<code>SharingCollection</code>](#SharingCollection)
1915+
**Returns**: <code>object</code> - The response
1916+
1917+
| Param | Type | Description |
1918+
| --- | --- | --- |
1919+
| doctype | <code>string</code> | The doctype |
1920+
| [options] | [<code>SharingRulesOptions</code>](#SharingRulesOptions) | The options |
1921+
| [options.withSharedDocs] | <code>boolean</code> | If true, the response will include the shared documents |
1922+
19081923
<a name="SharingCollection+get"></a>
19091924

19101925
### sharingCollection.get(id) ⇒ [<code>Sharing</code>](#Sharing)

packages/cozy-stack-client/src/SharingCollection.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,18 @@ const normalizeSharing = normalizeDoctypeJsonApi(SHARING_DOCTYPE)
5454
* `io.cozy.sharings`.
5555
*/
5656
class SharingCollection extends DocumentCollection {
57-
async findByDoctype(doctype) {
57+
/**
58+
* Finds all sharings for a given doctype
59+
*
60+
* @param {string} doctype The doctype
61+
* @param {SharingRulesOptions} [options] The options
62+
* @param {boolean} [options.withSharedDocs] If true, the response will include the shared documents
63+
* @returns {object} The response
64+
*/
65+
async findByDoctype(doctype, { withSharedDocs = true } = {}) {
5866
const resp = await this.stackClient.fetchJSON(
5967
'GET',
60-
uri`/sharings/doctype/${doctype}`
68+
uri`/sharings/doctype/${doctype}?shared_docs=${withSharedDocs}`
6169
)
6270
return {
6371
...resp,

packages/cozy-stack-client/src/SharingCollection.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('SharingCollection', () => {
5353
await collection.findByDoctype('io.cozy.files')
5454
expect(client.fetchJSON).toHaveBeenCalledWith(
5555
'GET',
56-
'/sharings/doctype/io.cozy.files'
56+
'/sharings/doctype/io.cozy.files?shared_docs=true'
5757
)
5858
})
5959
})

0 commit comments

Comments
 (0)