Skip to content

Commit

Permalink
feat(SharingCollection): Add revokeGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
cballevre committed Mar 19, 2024
1 parent c7691dd commit 3dc066b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
19 changes: 16 additions & 3 deletions docs/api/cozy-stack-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,7 @@ Implements the `DocumentCollection` API along with specific methods for
* [.getDiscoveryLink(sharingId, sharecode)](#SharingCollection+getDiscoveryLink) ⇒ <code>string</code>
* [.addRecipients(options)](#SharingCollection+addRecipients)
* [.revokeRecipient(sharing, recipientIndex)](#SharingCollection+revokeRecipient)
* [.revokeGroup(sharing, groupIndex)](#SharingCollection+revokeGroup)
* [.revokeSelf(sharing)](#SharingCollection+revokeSelf)
* [.revokeAllRecipients(sharing)](#SharingCollection+revokeAllRecipients)

Expand Down Expand Up @@ -1853,9 +1854,21 @@ Revoke only one recipient of the sharing.

| Param | Type | Description |
| --- | --- | --- |
| sharing | <code>object</code> | Sharing Object |
| sharing | [<code>Sharing</code>](#Sharing) | Sharing Object |
| recipientIndex | <code>number</code> | Index of this recipient in the members array of the sharing |

<a name="SharingCollection+revokeGroup"></a>

### sharingCollection.revokeGroup(sharing, groupIndex)
Revoke only one group of the sharing.

**Kind**: instance method of [<code>SharingCollection</code>](#SharingCollection)

| Param | Type | Description |
| --- | --- | --- |
| sharing | [<code>Sharing</code>](#Sharing) | Sharing Object |
| groupIndex | <code>number</code> | Index of this group in the groups array of the sharing |

<a name="SharingCollection+revokeSelf"></a>

### sharingCollection.revokeSelf(sharing)
Expand All @@ -1865,7 +1878,7 @@ Remove self from the sharing.

| Param | Type | Description |
| --- | --- | --- |
| sharing | <code>object</code> | Sharing Object |
| sharing | [<code>Sharing</code>](#Sharing) | Sharing Object |

<a name="SharingCollection+revokeAllRecipients"></a>

Expand All @@ -1877,7 +1890,7 @@ from the owner's cozy

| Param | Type | Description |
| --- | --- | --- |
| sharing | <code>object</code> | Sharing Objects |
| sharing | [<code>Sharing</code>](#Sharing) | Sharing Objects |

<a name="TriggerCollection"></a>

Expand Down
25 changes: 22 additions & 3 deletions packages/cozy-stack-client/src/SharingCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,26 @@ const normalizeSharing = sharing => normalizeDoc(sharing, SHARING_DOCTYPE)
* @property {string=} update
* @property {string=} remove
*/

/**
* @typedef {object} Recipient An io.cozy.contact
*/

/**
* @typedef {object} Sharing An io.cozy.sharings document
*/

/**
* @typedef {object} SharingPolicy Define the add/update/remove policies for a sharing
* @property {string} add
* @property {string} update
* @property {string} remove
*/

/**
* @typedef {(undefined|'one-way'|'two-way')} SharingType Define how a document is synced between sharing's owner and receivers.
*/

/**
* @typedef {object} RelationshipItem Define a recipient that can be used as target of a sharing
* @property {string} id - Recipient's ID
Expand Down Expand Up @@ -205,7 +210,7 @@ class SharingCollection extends DocumentCollection {
/**
* Revoke only one recipient of the sharing.
*
* @param {object} sharing Sharing Object
* @param {Sharing} sharing Sharing Object
* @param {number} recipientIndex Index of this recipient in the members array of the sharing
*/
revokeRecipient(sharing, recipientIndex) {
Expand All @@ -214,10 +219,24 @@ class SharingCollection extends DocumentCollection {
uri`/sharings/${sharing._id}/recipients/${recipientIndex}`
)
}

/**
* Revoke only one group of the sharing.
*
* @param {Sharing} sharing Sharing Object
* @param {number} groupIndex Index of this group in the groups array of the sharing
*/
revokeGroup(sharing, groupIndex) {
return this.stackClient.fetchJSON(
'DELETE',
uri`/sharings/${sharing._id}/groups/${groupIndex}`
)
}

/**
* Remove self from the sharing.
*
* @param {object} sharing Sharing Object
* @param {Sharing} sharing Sharing Object
*/
revokeSelf(sharing) {
return this.stackClient.fetchJSON(
Expand All @@ -229,7 +248,7 @@ class SharingCollection extends DocumentCollection {
* Revoke the sharing for all the members. Must be called
* from the owner's cozy
*
* @param {object} sharing Sharing Objects
* @param {Sharing} sharing Sharing Objects
*/
revokeAllRecipients(sharing) {
return this.stackClient.fetchJSON(
Expand Down
15 changes: 15 additions & 0 deletions packages/cozy-stack-client/src/SharingCollection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,21 @@ describe('SharingCollection', () => {
})
})

describe('revokeGroup', () => {
beforeEach(() => {
client.fetch.mockReset()
client.fetchJSON.mockResolvedValue({ data: [] })
})

it('should call the right route', async () => {
await collection.revokeGroup(SHARING, 1)
expect(client.fetchJSON).toHaveBeenCalledWith(
'DELETE',
`/sharings/${SHARING._id}/groups/1`
)
})
})

describe('addRecipients', () => {
beforeEach(() => {
client.fetch.mockReset()
Expand Down

0 comments on commit 3dc066b

Please sign in to comment.