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

feat(SharingColl): Add shortcut option to getDiscoveryLink #1580

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/api/cozy-stack-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -1854,7 +1854,7 @@ Implements the `DocumentCollection` API along with specific methods for
* [.get(id)](#SharingCollection+get) ⇒ [<code>Sharing</code>](#Sharing)
* [.create(params)](#SharingCollection+create)
* ~~[.share(document, recipients, sharingType, description, [previewPath])](#SharingCollection+share)~~
* [.getDiscoveryLink(sharingId, sharecode)](#SharingCollection+getDiscoveryLink) ⇒ <code>string</code>
* [.getDiscoveryLink(sharingId, sharecode, [options])](#SharingCollection+getDiscoveryLink) ⇒ <code>string</code>
* [.addRecipients(options)](#SharingCollection+addRecipients)
* [.revokeRecipient(sharing, recipientIndex)](#SharingCollection+revokeRecipient)
* [.revokeGroup(sharing, groupIndex)](#SharingCollection+revokeGroup)
Expand Down Expand Up @@ -1909,7 +1909,7 @@ Creates a new Sharing. See https://docs.cozy.io/en/cozy-stack/sharing/#post-shar

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

### sharingCollection.getDiscoveryLink(sharingId, sharecode) ⇒ <code>string</code>
### sharingCollection.getDiscoveryLink(sharingId, sharecode, [options]) ⇒ <code>string</code>
getDiscoveryLink - Returns the URL of the page that can be used to accept a sharing. See https://docs.cozy.io/en/cozy-stack/sharing/#get-sharingssharing-iddiscovery

**Kind**: instance method of [<code>SharingCollection</code>](#SharingCollection)
Expand All @@ -1918,6 +1918,8 @@ getDiscoveryLink - Returns the URL of the page that can be used to accept a shar
| --- | --- | --- |
| sharingId | <code>string</code> | Id of the sharing |
| sharecode | <code>string</code> | Code of the sharing |
| [options] | <code>object</code> | Options |
| [options.shortcut] | <code>boolean</code> | If true, add a shortcut to the sharing in the user's cozy and skip the OAuth authorize page. |

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

Expand Down
15 changes: 11 additions & 4 deletions packages/cozy-stack-client/src/SharingCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,18 @@ class SharingCollection extends DocumentCollection {
*
* @param {string} sharingId - Id of the sharing
* @param {string} sharecode - Code of the sharing
* @param {object} [options] - Options
* @param {boolean} [options.shortcut] - If true, add a shortcut to the sharing in the user's cozy and skip the OAuth authorize page.
* @returns {string}
*/
getDiscoveryLink(sharingId, sharecode) {
getDiscoveryLink(sharingId, sharecode, options) {
const { shortcut } = options || {}
const searchParams = new URLSearchParams()
searchParams.append('sharecode', sharecode)
if (shortcut) searchParams.append('shortcut', true)

return this.stackClient.fullpath(
`/sharings/${sharingId}/discovery?sharecode=${sharecode}`
`/sharings/${sharingId}/discovery?${searchParams}`
)
}

Expand Down Expand Up @@ -287,8 +294,8 @@ export const getSharingRules = (document, sharingType) => {
logger.warn(
`sharingType is deprecated and will be removed. We now set this default rules: ${getSharingRulesWithoutWarning(
document
)}} \n
If this default rules do not fill your need, please set custom rules
)}} \n
If this default rules do not fill your need, please set custom rules
by using the 'rules' object of the SharingCollection.create() method`
)
}
Expand Down
17 changes: 17 additions & 0 deletions packages/cozy-stack-client/src/SharingCollection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,4 +538,21 @@ describe('SharingCollection', () => {
)
})
})

describe('getDiscoveryLink', () => {
it('should call the route without a shortcut param', () => {
client.fullpath.mockImplementation(path => path)
const result = collection.getDiscoveryLink('sharingID', 'abc123')
expect(result).toBe('/sharings/sharingID/discovery?sharecode=abc123')
})
it('should call the route with a shortcut param', () => {
client.fullpath.mockImplementation(path => path)
const result = collection.getDiscoveryLink('sharingID', 'abc123', {
shortcut: true
})
expect(result).toBe(
'/sharings/sharingID/discovery?sharecode=abc123&shortcut=true'
)
})
})
})
Loading