Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1030972

Browse files
committedFeb 21, 2025·
feat: Manage rules for shared drive sharing
Shared drive sharing have special sharing rules.
1 parent ff5eda8 commit 1030972

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed
 

‎docs/api/cozy-stack-client.md

+28
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ CouchDB transforms $nor into $and with $ne operators</p>
171171
<dt><a href="#getSharingRulesForFile">getSharingRulesForFile(document)</a> ⇒ <code><a href="#Rule">Array.&lt;Rule&gt;</a></code></dt>
172172
<dd><p>Compute the rules that define how to share a File. See <a href="https://docs.cozy.io/en/cozy-stack/sharing-design/#description-of-a-sharing">https://docs.cozy.io/en/cozy-stack/sharing-design/#description-of-a-sharing</a></p>
173173
</dd>
174+
<dt><a href="#getSharingRulesForSharedDrive">getSharingRulesForSharedDrive(document)</a> ⇒ <code><a href="#Rule">Array.&lt;Rule&gt;</a></code></dt>
175+
<dd><p>Compute the rules that define a shared drive.</p>
176+
</dd>
174177
<dt><a href="#getSharingPolicyForFile">getSharingPolicyForFile(document)</a> ⇒ <code><a href="#SharingPolicy">SharingPolicy</a></code></dt>
175178
<dd><p>Compute the sharing policy for a File based on its sharing type</p>
176179
</dd>
@@ -268,6 +271,8 @@ not.</p>
268271
<dt><a href="#Rule">Rule</a> : <code>object</code></dt>
269272
<dd><p>A sharing rule</p>
270273
</dd>
274+
<dt><a href="#SharingRulesOptions">SharingRulesOptions</a> : <code>object</code></dt>
275+
<dd></dd>
271276
<dt><a href="#Recipient">Recipient</a> : <code>object</code></dt>
272277
<dd><p>An io.cozy.contact</p>
273278
</dd>
@@ -2345,6 +2350,7 @@ See https://docs.cozy.io/en/cozy-stack/sharing-design/#description-of-a-sharing
23452350
| Param | Type | Description |
23462351
| --- | --- | --- |
23472352
| document | [<code>Sharing</code>](#Sharing) | The document to share. Should have and _id and a name |
2353+
| [sharingRulesOptions] | [<code>SharingRulesOptions</code>](#SharingRulesOptions) | The document to share. Should have and _id and a name |
23482354

23492355
<a name="forceDownload"></a>
23502356

@@ -2482,6 +2488,18 @@ Compute the rules that define how to share a File. See https://docs.cozy.io/en/c
24822488
| --- | --- | --- |
24832489
| document | [<code>Sharing</code>](#Sharing) | The document to share. Should have and _id and a name |
24842490

2491+
<a name="getSharingRulesForSharedDrive"></a>
2492+
2493+
## getSharingRulesForSharedDrive(document) ⇒ [<code>Array.&lt;Rule&gt;</code>](#Rule)
2494+
Compute the rules that define a shared drive.
2495+
2496+
**Kind**: global function
2497+
**Returns**: [<code>Array.&lt;Rule&gt;</code>](#Rule) - The rules that define a shared drive
2498+
2499+
| Param | Type | Description |
2500+
| --- | --- | --- |
2501+
| document | [<code>Sharing</code>](#Sharing) | The document to share. Should have and _id and a name |
2502+
24852503
<a name="getSharingPolicyForFile"></a>
24862504

24872505
## getSharingPolicyForFile(document) ⇒ [<code>SharingPolicy</code>](#SharingPolicy)
@@ -3100,6 +3118,16 @@ A sharing rule
31003118
| [update] | <code>string</code> |
31013119
| [remove] | <code>string</code> |
31023120

3121+
<a name="SharingRulesOptions"></a>
3122+
3123+
## SharingRulesOptions : <code>object</code>
3124+
**Kind**: global typedef
3125+
**Properties**
3126+
3127+
| Name | Type |
3128+
| --- | --- |
3129+
| [sharedDrive] | <code>boolean</code> |
3130+
31033131
<a name="Recipient"></a>
31043132

31053133
## Recipient : <code>object</code>

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

+35-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ const normalizeSharing = normalizeDoctypeJsonApi(SHARING_DOCTYPE)
1919
* @property {string=} remove
2020
*/
2121

22+
/**
23+
* @typedef {object} SharingRulesOptions
24+
* @property {boolean} [sharedDrive]
25+
*/
26+
2227
/**
2328
* @typedef {object} Recipient An io.cozy.contact
2429
*/
@@ -103,7 +108,7 @@ class SharingCollection extends DocumentCollection {
103108
description,
104109
preview_path: previewPath,
105110
open_sharing: openSharing,
106-
rules: rules ? rules : getSharingRules(document)
111+
rules: rules ? rules : getSharingRules(document, { sharedDrive })
107112
}
108113
let optionalAttributes = {}
109114
if (appSlug) {
@@ -241,10 +246,17 @@ SharingCollection.normalizeDoctype = normalizeDoctypeJsonApi
241246
* See https://docs.cozy.io/en/cozy-stack/sharing-design/#description-of-a-sharing
242247
*
243248
* @param {Sharing} document - The document to share. Should have and _id and a name
249+
* @param {SharingRulesOptions} [sharingRulesOptions] - The document to share. Should have and _id and a name
244250
*
245251
* @returns {Array<Rule>=} The rules that define how to share the document
246252
*/
247-
export const getSharingRules = document => {
253+
export const getSharingRules = (document, sharingRulesOptions = {}) => {
254+
const { sharedDrive } = sharingRulesOptions
255+
256+
if (sharedDrive) {
257+
return getSharingRulesForSharedDrive(document)
258+
}
259+
248260
if (isFile(document)) {
249261
return getSharingRulesForFile(document)
250262
}
@@ -319,6 +331,27 @@ const getSharingRulesForFile = document => {
319331
]
320332
}
321333

334+
/**
335+
* Compute the rules that define a shared drive.
336+
*
337+
* @param {Sharing} document - The document to share. Should have and _id and a name
338+
*
339+
* @returns {Array<Rule>=} The rules that define a shared drive
340+
*/
341+
const getSharingRulesForSharedDrive = document => {
342+
const { _id, name } = document
343+
return [
344+
{
345+
title: name,
346+
doctype: 'io.cozy.files',
347+
values: [_id],
348+
add: 'none',
349+
update: 'none',
350+
remove: 'none'
351+
}
352+
]
353+
}
354+
322355
/**
323356
* Compute the sharing policy for a File based on its sharing type
324357
*

0 commit comments

Comments
 (0)
Please sign in to comment.