cozy-sharing 33.4.2 → 33.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [33.5.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@33.4.3...cozy-sharing@33.5.0) (2026-06-17)
7
+
8
+ ### Features
9
+
10
+ - Add isOrgSharedDrive and canLeave helpers ([f93d4bb](https://github.com/cozy/cozy-libs/commit/f93d4bb37cd748a7e18db3a3ac67e1b84e819440))
11
+
12
+ ## [33.4.3](https://github.com/cozy/cozy-libs/compare/cozy-sharing@33.4.2...cozy-sharing@33.4.3) (2026-06-16)
13
+
14
+ ### Bug Fixes
15
+
16
+ - **cozy-sharing:** Remove revoked sharing after last recipient ([e0f486c](https://github.com/cozy/cozy-libs/commit/e0f486cd9b7805e8214c5586f0d7b2c7aed50491))
17
+
6
18
  ## [33.4.2](https://github.com/cozy/cozy-libs/compare/cozy-sharing@33.4.1...cozy-sharing@33.4.2) (2026-06-16)
7
19
 
8
20
  ### Bug Fixes
@@ -41,7 +41,7 @@ import { getSharingObject, createSharingInStore, updateSharingInStore } from './
41
41
  import { getShortcode } from './helpers/shortcodes';
42
42
  import { SynchronousJobQueue } from './helpers/synchronousJobQueue';
43
43
  import { fetchApps } from './queries/queries';
44
- import reducer, { receiveSharings, addSharing, updateSharing, addSharingLink, updateSharingLink, revokeSharingLink, revokeRecipient, revokeGroup as revokeGroupFromState, revokeSelf, receivePaths, isOwner as _isOwner, isSharedDrive as _isSharedDrive, canReshare as _canReshare, getOwner as _getOwner, getRecipients as _getRecipients, getSharingById as _getSharingById, getExternalSharingIds, getSharingForSelf as _getSharingForSelf, getSharingType as _getSharingType, getSharingLink as _getSharingLink, getSharedDocIdsBySharings, getDocumentSharing, getDocumentPermissions as _getDocumentPermissions, hasSharedParent as _hasSharedParent, hasSharedChild as _hasSharedChild, getSharedParentPath as _getSharedParentPath, getSharedDriveSharingType, SHARING_TYPE } from './state';
44
+ import reducer, { receiveSharings, addSharing, updateSharing, addSharingLink, updateSharingLink, revokeSharingLink, revokeRecipient, revokeGroup as revokeGroupFromState, revokeSelf, receivePaths, isOwner as _isOwner, isSharedDrive as _isSharedDrive, isOrgSharedDrive as _isOrgSharedDrive, canLeave as _canLeave, canReshare as _canReshare, getOwner as _getOwner, getRecipients as _getRecipients, getSharingById as _getSharingById, getExternalSharingIds, getSharingForSelf as _getSharingForSelf, getSharingType as _getSharingType, getSharingLink as _getSharingLink, getSharedDocIdsBySharings, getDocumentSharing, getDocumentPermissions as _getDocumentPermissions, hasSharedParent as _hasSharedParent, hasSharedChild as _hasSharedChild, getSharedParentPath as _getSharedParentPath, getSharedDriveSharingType, SHARING_TYPE } from './state';
45
45
  var log = minilog('SharingProvider');
46
46
  var SHARING_DOCTYPE = 'io.cozy.sharings';
47
47
  var PERMISSION_DOCTYPE = 'io.cozy.permissions';
@@ -997,6 +997,12 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
997
997
  isSharedDrive: function isSharedDrive(docId) {
998
998
  return _isSharedDrive(_this2.state, docId);
999
999
  },
1000
+ isOrgSharedDrive: function isOrgSharedDrive(docId) {
1001
+ return _isOrgSharedDrive(_this2.state, docId);
1002
+ },
1003
+ canLeave: function canLeave(docId) {
1004
+ return _canLeave(_this2.state, docId);
1005
+ },
1000
1006
  canReshare: function canReshare(docId) {
1001
1007
  return _canReshare(_this2.state, docId, _instanceUri);
1002
1008
  },
package/dist/state.js CHANGED
@@ -337,6 +337,12 @@ var sharings = function sharings() {
337
337
  case UPDATE_SHARING:
338
338
  case REVOKE_GROUP:
339
339
  case REVOKE_RECIPIENT:
340
+ if (!isSharingADrive(action.sharing) && areAllRecipientsRevoked(action.sharing)) {
341
+ return state.filter(function (s) {
342
+ return s.id !== action.sharing.id;
343
+ });
344
+ }
345
+
340
346
  return state.map(function (s) {
341
347
  return s.id !== action.sharing.id ? s : action.sharing;
342
348
  });
@@ -409,6 +415,21 @@ export var isSharedDrive = function isSharedDrive(state, docId) {
409
415
 
410
416
  return false;
411
417
  };
418
+ export var isOrgSharedDrive = function isOrgSharedDrive(state, docId) {
419
+ if (state.byDocId[docId] && state.byDocId[docId].sharings.length !== 0) {
420
+ var sharing = getSharingById(state, state.byDocId[docId].sharings[0]);
421
+ return sharing.attributes.drive === true && sharing.attributes.org_drive === true;
422
+ }
423
+
424
+ return false;
425
+ };
426
+ export var canLeave = function canLeave(state, docId) {
427
+ if (isOrgSharedDrive(state, docId)) {
428
+ return false;
429
+ }
430
+
431
+ return true;
432
+ };
412
433
  export var canReshare = function canReshare(state, docId, instanceUri) {
413
434
  var sharing = getDocumentSharing(state, docId);
414
435
  var me = sharing.attributes.members.find(matchingInstanceName(instanceUri));
@@ -254,6 +254,18 @@ describe('Sharing state', function () {
254
254
  expect(state.sharings[0].attributes.members[1].status).toEqual('revoked');
255
255
  expect(state.sharings[0].attributes.members[2].id).toEqual(SHARING_1.attributes.members[2].id);
256
256
  });
257
+ it('should forget a sharing when revoking the last recipient', function () {
258
+ var state = reducer(reducer(undefined, receiveSharings({
259
+ sharings: [SHARING_1, SHARING_2]
260
+ })), revokeRecipient(SHARING_2, 1));
261
+ expect(state.byDocId).toEqual({
262
+ folder_1: {
263
+ sharings: [SHARING_1.id],
264
+ permissions: []
265
+ }
266
+ });
267
+ expect(state.sharings).toEqual([SHARING_1]);
268
+ });
257
269
  it('should revoke self', function () {
258
270
  var state = reducer(reducer(undefined, receiveSharings({
259
271
  sharings: [SHARING_1, SHARING_2]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-sharing",
3
- "version": "33.4.2",
3
+ "version": "33.5.0",
4
4
  "description": "Provides sharing login for React applications.",
5
5
  "main": "dist/index.js",
6
6
  "author": "Cozy",
@@ -83,5 +83,5 @@
83
83
  "sideEffects": [
84
84
  "*.css"
85
85
  ],
86
- "gitHead": "ce6730dfc4d047382e31c566f7e066ad9d7eb195"
86
+ "gitHead": "34a93967119b6820f76f35b01832d1a1627cc58f"
87
87
  }
@@ -28,6 +28,8 @@ import reducer, {
28
28
  receivePaths,
29
29
  isOwner,
30
30
  isSharedDrive,
31
+ isOrgSharedDrive,
32
+ canLeave,
31
33
  canReshare,
32
34
  getOwner,
33
35
  getRecipients,
@@ -66,6 +68,8 @@ export class SharingProvider extends Component {
66
68
  documentType,
67
69
  isOwner: docId => isOwner(this.state, docId),
68
70
  isSharedDrive: docId => isSharedDrive(this.state, docId),
71
+ isOrgSharedDrive: docId => isOrgSharedDrive(this.state, docId),
72
+ canLeave: docId => canLeave(this.state, docId),
69
73
  canReshare: docId => canReshare(this.state, docId, instanceUri),
70
74
  getOwner: docId => getOwner(this.state, docId),
71
75
  getSharingType: docId => getSharingType(this.state, docId, instanceUri),
package/src/state.js CHANGED
@@ -258,6 +258,12 @@ const sharings = (state = [], action) => {
258
258
  case UPDATE_SHARING:
259
259
  case REVOKE_GROUP:
260
260
  case REVOKE_RECIPIENT:
261
+ if (
262
+ !isSharingADrive(action.sharing) &&
263
+ areAllRecipientsRevoked(action.sharing)
264
+ ) {
265
+ return state.filter(s => s.id !== action.sharing.id)
266
+ }
261
267
  return state.map(s => {
262
268
  return s.id !== action.sharing.id ? s : action.sharing
263
269
  })
@@ -323,6 +329,24 @@ export const isSharedDrive = (state, docId) => {
323
329
  return false
324
330
  }
325
331
 
332
+ export const isOrgSharedDrive = (state, docId) => {
333
+ if (state.byDocId[docId] && state.byDocId[docId].sharings.length !== 0) {
334
+ const sharing = getSharingById(state, state.byDocId[docId].sharings[0])
335
+
336
+ return (
337
+ sharing.attributes.drive === true && sharing.attributes.org_drive === true
338
+ )
339
+ }
340
+ return false
341
+ }
342
+
343
+ export const canLeave = (state, docId) => {
344
+ if (isOrgSharedDrive(state, docId)) {
345
+ return false
346
+ }
347
+ return true
348
+ }
349
+
326
350
  export const canReshare = (state, docId, instanceUri) => {
327
351
  const sharing = getDocumentSharing(state, docId)
328
352
  const me = sharing.attributes.members.find(matchingInstanceName(instanceUri))
package/src/state.spec.js CHANGED
@@ -343,6 +343,22 @@ describe('Sharing state', () => {
343
343
  )
344
344
  })
345
345
 
346
+ it('should forget a sharing when revoking the last recipient', () => {
347
+ const state = reducer(
348
+ reducer(
349
+ undefined,
350
+ receiveSharings({
351
+ sharings: [SHARING_1, SHARING_2]
352
+ })
353
+ ),
354
+ revokeRecipient(SHARING_2, 1)
355
+ )
356
+ expect(state.byDocId).toEqual({
357
+ folder_1: { sharings: [SHARING_1.id], permissions: [] }
358
+ })
359
+ expect(state.sharings).toEqual([SHARING_1])
360
+ })
361
+
346
362
  it('should revoke self', () => {
347
363
  const state = reducer(
348
364
  reducer(