cozy-sharing 28.4.3 → 28.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,20 @@
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
+ # [28.5.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@28.4.4...cozy-sharing@28.5.0) (2026-03-10)
7
+
8
+ ### Bug Fixes
9
+
10
+ - Make sharingDesc prop optional with default empty string ([538eaa6](https://github.com/cozy/cozy-libs/commit/538eaa61988405be4225a6147fad17805b218e30))
11
+
12
+ ### Features
13
+
14
+ - Allow to share a shared drive file by link ([a78e796](https://github.com/cozy/cozy-libs/commit/a78e7963af05b6815856246a722542acee2d900f))
15
+
16
+ ## [28.4.4](https://github.com/cozy/cozy-libs/compare/cozy-sharing@28.4.3...cozy-sharing@28.4.4) (2026-03-09)
17
+
18
+ **Note:** Version bump only for package cozy-sharing
19
+
6
20
  ## [28.4.3](https://github.com/cozy/cozy-libs/compare/cozy-sharing@28.4.2...cozy-sharing@28.4.3) (2026-03-09)
7
21
 
8
22
  **Note:** Version bump only for package cozy-sharing
@@ -33,13 +33,15 @@ function _callSuper(_this, derived, args) {
33
33
  import React, { Component } from 'react';
34
34
  import { withClient } from 'cozy-client';
35
35
  import minilog from 'cozy-minilog';
36
+ import { generateShareLinkFromFile } from './components/ShareRestrictionModal/helpers';
36
37
  import SharingContext from './context';
37
38
  import { fetchNextPermissions } from './fetchNextPermissions';
38
39
  import { fetchFilesPaths } from './helpers/files';
39
40
  import { getSharingObject, createSharingInStore, updateSharingInStore } from './helpers/sharings';
41
+ import { getShortcode } from './helpers/shortcodes';
40
42
  import { SynchronousJobQueue } from './helpers/synchronousJobQueue';
41
43
  import { fetchApps } from './queries/queries';
42
- 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, 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, 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';
43
45
  var log = minilog('SharingProvider');
44
46
  var SHARING_DOCTYPE = 'io.cozy.sharings';
45
47
  var PERMISSION_DOCTYPE = 'io.cozy.permissions';
@@ -87,7 +89,7 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
87
89
  while (1) switch (_context.prev = _context.next) {
88
90
  case 0:
89
91
  _this2$props = _this2.props, client = _this2$props.client, doctype = _this2$props.doctype;
90
- internalSharing = getSharingById(_this2.state, sharing._id);
92
+ internalSharing = _getSharingById(_this2.state, sharing._id);
91
93
  newSharing = getSharingObject(internalSharing, sharing);
92
94
 
93
95
  if (internalSharing) {
@@ -348,7 +350,7 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
348
350
  while (1) switch (_context7.prev = _context7.next) {
349
351
  case 0:
350
352
  _this2$props4 = _this2.props, client = _this2$props4.client, doctype = _this2$props4.doctype;
351
- sharing = getSharingById(_this2.state, sharingId);
353
+ sharing = _getSharingById(_this2.state, sharingId);
352
354
  _context7.next = 4;
353
355
  return _this2.sharingCol.revokeRecipient(sharing, recipientIndex);
354
356
 
@@ -396,7 +398,7 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
396
398
  while (1) switch (_context8.prev = _context8.next) {
397
399
  case 0:
398
400
  _this2$props5 = _this2.props, client = _this2$props5.client, doctype = _this2$props5.doctype;
399
- sharing = getSharingById(_this2.state, sharingId);
401
+ sharing = _getSharingById(_this2.state, sharingId);
400
402
  _context8.next = 4;
401
403
  return _this2.sharingCol.revokeGroup(sharing, recipientIndex);
402
404
 
@@ -467,17 +469,34 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
467
469
  return _regeneratorRuntime.wrap(function _callee10$(_context10) {
468
470
  while (1) switch (_context10.prev = _context10.next) {
469
471
  case 0:
470
- _context10.next = 2;
472
+ if (!document.driveId) {
473
+ _context10.next = 6;
474
+ break;
475
+ }
476
+
477
+ _context10.next = 3;
478
+ return _this2.createSharedDriveSharingLink(document, options);
479
+
480
+ case 3:
481
+ _context10.t0 = _context10.sent;
482
+ _context10.next = 9;
483
+ break;
484
+
485
+ case 6:
486
+ _context10.next = 8;
471
487
  return _this2.permissionCol.createSharingLink(document, options);
472
488
 
473
- case 2:
474
- resp = _context10.sent;
489
+ case 8:
490
+ _context10.t0 = _context10.sent;
491
+
492
+ case 9:
493
+ resp = _context10.t0;
475
494
 
476
495
  _this2.dispatch(addSharingLink(resp.data));
477
496
 
478
497
  return _context10.abrupt("return", resp);
479
498
 
480
- case 5:
499
+ case 12:
481
500
  case "end":
482
501
  return _context10.stop();
483
502
  }
@@ -489,6 +508,93 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
489
508
  };
490
509
  }());
491
510
 
511
+ _defineProperty(_this2, "getFederatedShareLink", function (document) {
512
+ if (!document.driveId) return null;
513
+
514
+ var permissions = _getDocumentPermissions(_this2.state, document._id);
515
+
516
+ var perm = permissions.find(function (p) {
517
+ return getShortcode(p);
518
+ });
519
+ if (!perm) return null;
520
+ var code = getShortcode(perm);
521
+ if (!code) return null;
522
+ var client = _this2.props.client;
523
+ return generateShareLinkFromFile({
524
+ client: client,
525
+ file: document,
526
+ sharecode: code,
527
+ getOwner: _this2.state.getOwner,
528
+ getSharingById: _this2.state.getSharingById,
529
+ documentType: _this2.state.documentType
530
+ });
531
+ });
532
+
533
+ _defineProperty(_this2, "createSharedDriveSharingLink", /*#__PURE__*/function () {
534
+ var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(document, options) {
535
+ var client, drivePermissionCollection, resp;
536
+ return _regeneratorRuntime.wrap(function _callee11$(_context11) {
537
+ while (1) switch (_context11.prev = _context11.next) {
538
+ case 0:
539
+ client = _this2.props.client;
540
+ drivePermissionCollection = client.collection('io.cozy.permissions', {
541
+ driveId: document.driveId
542
+ });
543
+ _context11.next = 4;
544
+ return drivePermissionCollection.createSharingLink(document, options);
545
+
546
+ case 4:
547
+ resp = _context11.sent;
548
+ return _context11.abrupt("return", resp);
549
+
550
+ case 6:
551
+ case "end":
552
+ return _context11.stop();
553
+ }
554
+ }, _callee11);
555
+ }));
556
+
557
+ return function (_x18, _x19) {
558
+ return _ref13.apply(this, arguments);
559
+ };
560
+ }());
561
+
562
+ _defineProperty(_this2, "updateSharedDrivePermissions", /*#__PURE__*/function () {
563
+ var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(document, permissionDocument, updatedPermissions, options) {
564
+ var client, expiresAt, password, drivePermissionCollection, resp;
565
+ return _regeneratorRuntime.wrap(function _callee12$(_context12) {
566
+ while (1) switch (_context12.prev = _context12.next) {
567
+ case 0:
568
+ client = _this2.props.client;
569
+ expiresAt = options.expiresAt, password = options.password;
570
+ drivePermissionCollection = client.collection('io.cozy.permissions', {
571
+ driveId: document.driveId
572
+ });
573
+ _context12.next = 5;
574
+ return drivePermissionCollection.add(permissionDocument, updatedPermissions, {
575
+ expiresAt: expiresAt,
576
+ password: password
577
+ });
578
+
579
+ case 5:
580
+ resp = _context12.sent;
581
+
582
+ _this2.dispatch(updateSharingLink(resp.data));
583
+
584
+ return _context12.abrupt("return", resp);
585
+
586
+ case 8:
587
+ case "end":
588
+ return _context12.stop();
589
+ }
590
+ }, _callee12);
591
+ }));
592
+
593
+ return function (_x20, _x21, _x22, _x23) {
594
+ return _ref14.apply(this, arguments);
595
+ };
596
+ }());
597
+
492
598
  /**
493
599
  * updateDocumentPermissions - Description
494
600
  *
@@ -501,75 +607,99 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
501
607
  * @return {Array}
502
608
  */
503
609
  _defineProperty(_this2, "updateDocumentPermissions", /*#__PURE__*/function () {
504
- var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(document, options) {
610
+ var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(document, options) {
505
611
  var verbs, expiresAt, password, permissions, responses;
506
- return _regeneratorRuntime.wrap(function _callee12$(_context12) {
507
- while (1) switch (_context12.prev = _context12.next) {
612
+ return _regeneratorRuntime.wrap(function _callee14$(_context14) {
613
+ while (1) switch (_context14.prev = _context14.next) {
508
614
  case 0:
509
615
  verbs = options.verbs, expiresAt = options.expiresAt, password = options.password;
510
616
  permissions = _getDocumentPermissions(_this2.state, document.id);
511
- _context12.next = 4;
617
+
618
+ if (!(!permissions || permissions.length === 0)) {
619
+ _context14.next = 4;
620
+ break;
621
+ }
622
+
623
+ return _context14.abrupt("return", []);
624
+
625
+ case 4:
626
+ _context14.next = 6;
512
627
  return Promise.all(permissions.map( /*#__PURE__*/function () {
513
- var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(permissionDocument) {
628
+ var _ref16 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(permissionDocument) {
514
629
  var updatedPermissions, resp;
515
- return _regeneratorRuntime.wrap(function _callee11$(_context11) {
516
- while (1) switch (_context11.prev = _context11.next) {
630
+ return _regeneratorRuntime.wrap(function _callee13$(_context13) {
631
+ while (1) switch (_context13.prev = _context13.next) {
517
632
  case 0:
518
633
  updatedPermissions = permissionDocument.attributes.permissions;
519
- Object.keys(updatedPermissions).map(function (permType) {
634
+ Object.keys(updatedPermissions).forEach(function (permType) {
520
635
  updatedPermissions[permType].verbs = verbs;
521
636
  });
522
- _context11.next = 4;
637
+
638
+ if (!document.driveId) {
639
+ _context13.next = 8;
640
+ break;
641
+ }
642
+
643
+ _context13.next = 5;
644
+ return _this2.updateSharedDrivePermissions(document, permissionDocument, updatedPermissions, options);
645
+
646
+ case 5:
647
+ _context13.t0 = _context13.sent;
648
+ _context13.next = 11;
649
+ break;
650
+
651
+ case 8:
652
+ _context13.next = 10;
523
653
  return _this2.permissionCol.add(permissionDocument, updatedPermissions, {
524
654
  expiresAt: expiresAt,
525
655
  password: password
526
656
  });
527
657
 
528
- case 4:
529
- resp = _context11.sent;
530
-
531
- _this2.dispatch(updateSharingLink(resp.data));
658
+ case 10:
659
+ _context13.t0 = _context13.sent;
532
660
 
533
- return _context11.abrupt("return", resp);
661
+ case 11:
662
+ resp = _context13.t0;
663
+ return _context13.abrupt("return", resp);
534
664
 
535
- case 7:
665
+ case 13:
536
666
  case "end":
537
- return _context11.stop();
667
+ return _context13.stop();
538
668
  }
539
- }, _callee11);
669
+ }, _callee13);
540
670
  }));
541
671
 
542
- return function (_x20) {
543
- return _ref14.apply(this, arguments);
672
+ return function (_x26) {
673
+ return _ref16.apply(this, arguments);
544
674
  };
545
675
  }()));
546
676
 
547
- case 4:
548
- responses = _context12.sent;
549
- return _context12.abrupt("return", responses);
550
-
551
677
  case 6:
678
+ responses = _context14.sent;
679
+ return _context14.abrupt("return", responses);
680
+
681
+ case 8:
552
682
  case "end":
553
- return _context12.stop();
683
+ return _context14.stop();
554
684
  }
555
- }, _callee12);
685
+ }, _callee14);
556
686
  }));
557
687
 
558
- return function (_x18, _x19) {
559
- return _ref13.apply(this, arguments);
688
+ return function (_x24, _x25) {
689
+ return _ref15.apply(this, arguments);
560
690
  };
561
691
  }());
562
692
 
563
693
  _defineProperty(_this2, "revokeSharingLink", /*#__PURE__*/function () {
564
- var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(document) {
694
+ var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(document) {
565
695
  var perms;
566
- return _regeneratorRuntime.wrap(function _callee13$(_context13) {
567
- while (1) switch (_context13.prev = _context13.next) {
696
+ return _regeneratorRuntime.wrap(function _callee15$(_context15) {
697
+ while (1) switch (_context15.prev = _context15.next) {
568
698
  case 0:
569
699
  // Because some duplicate links have been created in the past, we must ensure
570
700
  // we revoke all of them
571
701
  perms = _getDocumentPermissions(_this2.state, document.id);
572
- _context13.next = 3;
702
+ _context15.next = 3;
573
703
  return Promise.all(perms.map(function (p) {
574
704
  return _this2.permissionCol.destroy(p);
575
705
  }));
@@ -579,13 +709,13 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
579
709
 
580
710
  case 4:
581
711
  case "end":
582
- return _context13.stop();
712
+ return _context15.stop();
583
713
  }
584
- }, _callee13);
714
+ }, _callee15);
585
715
  }));
586
716
 
587
- return function (_x21) {
588
- return _ref15.apply(this, arguments);
717
+ return function (_x27) {
718
+ return _ref17.apply(this, arguments);
589
719
  };
590
720
  }());
591
721
 
@@ -634,6 +764,9 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
634
764
  getSharingType: function getSharingType(docId) {
635
765
  return _getSharingType(_this2.state, docId, _instanceUri);
636
766
  },
767
+ getSharingById: function getSharingById(docId) {
768
+ return _getSharingById(_this2.state, docId);
769
+ },
637
770
  getSharingForSelf: function getSharingForSelf(docId) {
638
771
  return _getSharingForSelf(_this2.state, docId);
639
772
  },
@@ -661,6 +794,7 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
661
794
  revokeGroup: _this2.revokeGroup,
662
795
  revokeSelf: _this2.revokeSelf,
663
796
  shareByLink: _this2.shareByLink,
797
+ getFederatedShareLink: _this2.getFederatedShareLink,
664
798
  updateDocumentPermissions: _this2.updateDocumentPermissions,
665
799
  revokeSharingLink: _this2.revokeSharingLink,
666
800
  hasLoadedAtLeastOnePage: false,
@@ -704,14 +838,14 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
704
838
  }, {
705
839
  key: "fetchAllSharings",
706
840
  value: function () {
707
- var _fetchAllSharings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14() {
841
+ var _fetchAllSharings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16() {
708
842
  var _this$props, doctype, client, _yield$Promise$all, _yield$Promise$all2, sharings, permissions, apps, sharedDocIds, resp, folderPaths, filePaths;
709
843
 
710
- return _regeneratorRuntime.wrap(function _callee14$(_context14) {
711
- while (1) switch (_context14.prev = _context14.next) {
844
+ return _regeneratorRuntime.wrap(function _callee16$(_context16) {
845
+ while (1) switch (_context16.prev = _context16.next) {
712
846
  case 0:
713
847
  if (!this.isPublic) {
714
- _context14.next = 4;
848
+ _context16.next = 4;
715
849
  break;
716
850
  }
717
851
 
@@ -720,17 +854,17 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
720
854
  this.setState({
721
855
  allLoaded: true
722
856
  });
723
- return _context14.abrupt("return");
857
+ return _context16.abrupt("return");
724
858
 
725
859
  case 4:
726
860
  _this$props = this.props, doctype = _this$props.doctype, client = _this$props.client;
727
- _context14.next = 7;
861
+ _context16.next = 7;
728
862
  return Promise.all([this.sharingCol.findByDoctype(doctype, {
729
863
  withSharedDocs: false
730
864
  }), this.permissionCol.findLinksByDoctype(doctype), client.fetchQueryAndGetFromState(fetchApps())]);
731
865
 
732
866
  case 7:
733
- _yield$Promise$all = _context14.sent;
867
+ _yield$Promise$all = _context16.sent;
734
868
  _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 3);
735
869
  sharings = _yield$Promise$all2[0];
736
870
  permissions = _yield$Promise$all2[1];
@@ -745,35 +879,35 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
745
879
  hasLoadedAtLeastOnePage: true
746
880
  }); // eslint-disable-next-line promise/catch-or-return
747
881
 
748
- _context14.next = 16;
882
+ _context16.next = 16;
749
883
  return fetchNextPermissions(permissions, this.dispatch, this.permissionCol);
750
884
 
751
885
  case 16:
752
886
  if (!(doctype === 'io.cozy.files')) {
753
- _context14.next = 26;
887
+ _context16.next = 26;
754
888
  break;
755
889
  }
756
890
 
757
891
  sharedDocIds = getSharedDocIdsBySharings(sharings);
758
- _context14.next = 20;
892
+ _context16.next = 20;
759
893
  return client.collection(doctype).all({
760
894
  keys: sharedDocIds
761
895
  });
762
896
 
763
897
  case 20:
764
- resp = _context14.sent;
898
+ resp = _context16.sent;
765
899
  folderPaths = resp.data.filter(function (f) {
766
900
  return f.type === 'directory' && !f.trashed;
767
901
  }).map(function (f) {
768
902
  return f.path;
769
903
  });
770
- _context14.next = 24;
904
+ _context16.next = 24;
771
905
  return fetchFilesPaths(client, doctype, resp.data.filter(function (f) {
772
906
  return f.type !== 'directory' && !f.trashed;
773
907
  }));
774
908
 
775
909
  case 24:
776
- filePaths = _context14.sent;
910
+ filePaths = _context16.sent;
777
911
  this.dispatch(receivePaths([].concat(_toConsumableArray(folderPaths), _toConsumableArray(filePaths))));
778
912
 
779
913
  case 26:
@@ -783,9 +917,9 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
783
917
 
784
918
  case 27:
785
919
  case "end":
786
- return _context14.stop();
920
+ return _context16.stop();
787
921
  }
788
- }, _callee14, this);
922
+ }, _callee16, this);
789
923
  }));
790
924
 
791
925
  function fetchAllSharings() {
@@ -4,8 +4,8 @@ import { act, render, screen } from '@testing-library/react';
4
4
  import React from 'react';
5
5
  import { createMockClient } from 'cozy-client';
6
6
  import { SharingProvider } from './SharingProvider';
7
- import SharingContext from './context'; // import { receiveSharings } from './state'
8
-
7
+ import SharingContext from './context';
8
+ import reducer, { addSharingLink, getDocumentPermissions } from './state';
9
9
  import AppLike from '../test/AppLike';
10
10
 
11
11
  var AppWrapper = function AppWrapper(_ref) {
@@ -130,6 +130,184 @@ describe('SharingProvider', function () {
130
130
  expect(client.collection().findLinksByDoctype).not.toHaveBeenCalled();
131
131
  expect(client.collection().findApps).not.toHaveBeenCalled();
132
132
  });
133
+ });
134
+ describe('shareByLink', function () {
135
+ var PERM_DRIVE_FILE = {
136
+ type: 'io.cozy.permissions',
137
+ id: 'perm_drive_file',
138
+ attributes: {
139
+ type: 'share',
140
+ permissions: {
141
+ rule0: {
142
+ type: 'io.cozy.files',
143
+ verbs: ['GET'],
144
+ values: ['file_in_drive']
145
+ }
146
+ },
147
+ shortcodes: {
148
+ code: 'shortcode123'
149
+ }
150
+ }
151
+ };
152
+ var driveFile = {
153
+ _id: 'file_in_drive',
154
+ id: 'file_in_drive',
155
+ driveId: 'drive_123'
156
+ };
157
+ it('dispatches addSharingLink exactly once for a shared drive file', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
158
+ var mockCreateSharingLink, mockClient, provider, permissions;
159
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
160
+ while (1) switch (_context3.prev = _context3.next) {
161
+ case 0:
162
+ mockCreateSharingLink = jest.fn().mockResolvedValue({
163
+ data: PERM_DRIVE_FILE
164
+ });
165
+ mockClient = createMockClient({});
166
+ mockClient.collection = jest.fn().mockReturnValue({
167
+ createSharingLink: mockCreateSharingLink
168
+ });
169
+ provider = new SharingProvider({
170
+ client: mockClient
171
+ });
172
+ provider.state = reducer();
173
+ provider.dispatch = jest.fn(function (action) {
174
+ provider.state = reducer(provider.state, action);
175
+ });
176
+ _context3.next = 8;
177
+ return provider.shareByLink(driveFile, {
178
+ verbs: ['GET']
179
+ });
180
+
181
+ case 8:
182
+ expect(provider.dispatch).toHaveBeenCalledTimes(1);
183
+ permissions = getDocumentPermissions(provider.state, driveFile._id);
184
+ expect(permissions).toHaveLength(1);
185
+ expect(permissions[0].id).toBe(PERM_DRIVE_FILE.id);
186
+
187
+ case 12:
188
+ case "end":
189
+ return _context3.stop();
190
+ }
191
+ }, _callee3);
192
+ })));
193
+ it('dispatches addSharingLink once for a regular file (non shared drive)', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
194
+ var PERM_REGULAR_FILE, regularFile, mockCreateSharingLink, mockClient, provider, permissions;
195
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
196
+ while (1) switch (_context4.prev = _context4.next) {
197
+ case 0:
198
+ PERM_REGULAR_FILE = {
199
+ type: 'io.cozy.permissions',
200
+ id: 'perm_regular_file',
201
+ attributes: {
202
+ type: 'share',
203
+ permissions: {
204
+ rule0: {
205
+ type: 'io.cozy.files',
206
+ verbs: ['GET'],
207
+ values: ['regular_file_id']
208
+ }
209
+ },
210
+ shortcodes: {
211
+ code: 'shortcode456'
212
+ }
213
+ }
214
+ };
215
+ regularFile = {
216
+ _id: 'regular_file_id',
217
+ id: 'regular_file_id'
218
+ };
219
+ mockCreateSharingLink = jest.fn().mockResolvedValue({
220
+ data: PERM_REGULAR_FILE
221
+ });
222
+ mockClient = createMockClient({});
223
+ mockClient.collection = jest.fn().mockReturnValue({
224
+ createSharingLink: mockCreateSharingLink
225
+ });
226
+ provider = new SharingProvider({
227
+ client: mockClient
228
+ });
229
+ provider.state = reducer();
230
+ provider.permissionCol = {
231
+ createSharingLink: mockCreateSharingLink
232
+ };
233
+ provider.dispatch = jest.fn(function (action) {
234
+ provider.state = reducer(provider.state, action);
235
+ });
236
+ _context4.next = 11;
237
+ return provider.shareByLink(regularFile, {
238
+ verbs: ['GET']
239
+ });
240
+
241
+ case 11:
242
+ expect(provider.dispatch).toHaveBeenCalledTimes(1);
243
+ permissions = getDocumentPermissions(provider.state, regularFile._id);
244
+ expect(permissions).toHaveLength(1);
245
+ expect(permissions[0].id).toBe(PERM_REGULAR_FILE.id);
246
+
247
+ case 15:
248
+ case "end":
249
+ return _context4.stop();
250
+ }
251
+ }, _callee4);
252
+ })));
253
+ });
254
+ describe('updateDocumentPermissions', function () {
255
+ var PERM_DRIVE_FILE = {
256
+ type: 'io.cozy.permissions',
257
+ id: 'perm_drive_file',
258
+ attributes: {
259
+ type: 'share',
260
+ permissions: {
261
+ rule0: {
262
+ type: 'io.cozy.files',
263
+ verbs: ['GET'],
264
+ values: ['file_in_drive']
265
+ }
266
+ },
267
+ shortcodes: {
268
+ code: 'shortcode123'
269
+ }
270
+ }
271
+ };
272
+ it('sends only one PATCH request for a shared drive file', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
273
+ var driveFile, mockAdd, mockClient, provider;
274
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
275
+ while (1) switch (_context5.prev = _context5.next) {
276
+ case 0:
277
+ driveFile = {
278
+ _id: 'file_in_drive',
279
+ id: 'file_in_drive',
280
+ driveId: 'drive_123'
281
+ };
282
+ mockAdd = jest.fn().mockResolvedValue({
283
+ data: PERM_DRIVE_FILE
284
+ });
285
+ mockClient = createMockClient({});
286
+ mockClient.collection = jest.fn().mockReturnValue({
287
+ add: mockAdd
288
+ });
289
+ provider = new SharingProvider({
290
+ client: mockClient
291
+ }); // Seed the state with exactly one permission (as it would be after a correct shareByLink)
292
+
293
+ provider.state = reducer(undefined, addSharingLink(PERM_DRIVE_FILE));
294
+ provider.dispatch = jest.fn();
295
+ _context5.next = 9;
296
+ return provider.updateDocumentPermissions(driveFile, {
297
+ verbs: ['GET'],
298
+ expiresAt: '',
299
+ password: ''
300
+ });
301
+
302
+ case 9:
303
+ expect(mockAdd).toHaveBeenCalledTimes(1);
304
+
305
+ case 10:
306
+ case "end":
307
+ return _context5.stop();
308
+ }
309
+ }, _callee5);
310
+ })));
133
311
  }); // TODO Convert with react-testing-library
134
312
  // describe('hasWriteAccess', () => {
135
313
  // it('tells if a doc is writtable', () => {