cozy-sharing 28.5.0 → 28.6.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.
Files changed (32) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/SharingProvider.js +182 -86
  3. package/dist/SharingProvider.spec.js +152 -0
  4. package/dist/components/Recipient/LinkRecipient.js +6 -3
  5. package/dist/components/Recipient/LinkRecipient.stories.js +0 -1
  6. package/dist/components/Recipient/MemberRecipient.spec.js +13 -0
  7. package/dist/components/Recipient/MemberRecipientPermissions.js +80 -20
  8. package/dist/components/Recipient/MemberRecipientPermissions.spec.js +214 -0
  9. package/dist/components/Recipient/actions/setReadOnlySharedPermission.js +0 -1
  10. package/dist/components/Recipient/actions/setReadOnlySharedPermission.spec.js +72 -0
  11. package/dist/components/Recipient/actions/setReadWriteSharedPermission.js +0 -1
  12. package/dist/components/Recipient/actions/setReadWriteSharedPermission.spec.js +72 -0
  13. package/dist/components/ShareDialogCozyToCozy.spec.js +9 -0
  14. package/dist/components/WhoHasAccess.js +0 -1
  15. package/locales/en.json +4 -1
  16. package/locales/fr.json +4 -1
  17. package/locales/ru.json +4 -1
  18. package/locales/vi.json +4 -1
  19. package/package.json +2 -2
  20. package/src/SharingProvider.jsx +51 -1
  21. package/src/SharingProvider.spec.jsx +94 -0
  22. package/src/components/Recipient/LinkRecipient.jsx +10 -4
  23. package/src/components/Recipient/LinkRecipient.stories.jsx +0 -1
  24. package/src/components/Recipient/MemberRecipient.spec.jsx +11 -0
  25. package/src/components/Recipient/MemberRecipientPermissions.jsx +69 -16
  26. package/src/components/Recipient/MemberRecipientPermissions.spec.jsx +165 -0
  27. package/src/components/Recipient/actions/setReadOnlySharedPermission.js +1 -1
  28. package/src/components/Recipient/actions/setReadOnlySharedPermission.spec.jsx +95 -0
  29. package/src/components/Recipient/actions/setReadWriteSharedPermission.js +1 -1
  30. package/src/components/Recipient/actions/setReadWriteSharedPermission.spec.jsx +95 -0
  31. package/src/components/ShareDialogCozyToCozy.spec.jsx +6 -0
  32. package/src/components/WhoHasAccess.jsx +0 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
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.6.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@28.5.0...cozy-sharing@28.6.0) (2026-03-11)
7
+
8
+ ### Features
9
+
10
+ - Add ability to change member permission type in sharing ([76d0dce](https://github.com/cozy/cozy-libs/commit/76d0dce150d8ea7ac7cb12c6e00b340756b6512a))
11
+ - Hide link text in link recipient ([209857f](https://github.com/cozy/cozy-libs/commit/209857fcf01b71e584e49ef8ab3da4a897d408ed))
12
+ - Remove link prop from LinkRecipient component ([7bbf831](https://github.com/cozy/cozy-libs/commit/7bbf831594d7c33357ade79665f4308fd35e2b8e))
13
+
6
14
  # [28.5.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@28.4.4...cozy-sharing@28.5.0) (2026-03-10)
7
15
 
8
16
  ### Bug Fixes
@@ -463,48 +463,143 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
463
463
  };
464
464
  }());
465
465
 
466
- _defineProperty(_this2, "shareByLink", /*#__PURE__*/function () {
467
- var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(document, options) {
468
- var resp;
466
+ /**
467
+ * Update a sharing member's read_only field to change permission type
468
+ * @param {string} sharingId - The ID of the sharing
469
+ * @param {number} memberIndex - The index of the member in the sharing members array
470
+ * @param {string} newType - 'one-way' for read-only, 'two-way' for read-write
471
+ */
472
+ _defineProperty(_this2, "updateSharingMemberType", /*#__PURE__*/function () {
473
+ var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(sharingId, memberIndex, newType) {
474
+ var sharing, member, matchedContacts, contact, readOnly;
469
475
  return _regeneratorRuntime.wrap(function _callee10$(_context10) {
470
476
  while (1) switch (_context10.prev = _context10.next) {
471
477
  case 0:
472
- if (!document.driveId) {
478
+ sharing = _getSharingById(_this2.state, sharingId);
479
+
480
+ if (sharing) {
481
+ _context10.next = 3;
482
+ break;
483
+ }
484
+
485
+ throw new Error('Sharing not found');
486
+
487
+ case 3:
488
+ member = sharing.attributes.members[memberIndex];
489
+
490
+ if (member) {
473
491
  _context10.next = 6;
474
492
  break;
475
493
  }
476
494
 
477
- _context10.next = 3;
495
+ throw new Error('Member not found');
496
+
497
+ case 6:
498
+ _context10.next = 8;
499
+ return _this2.props.client.collection('io.cozy.contacts').find({
500
+ email: {
501
+ $elemMatch: {
502
+ address: member.email
503
+ }
504
+ },
505
+ _id: {
506
+ $gt: null
507
+ }
508
+ }, {
509
+ indexedFields: ['_id']
510
+ });
511
+
512
+ case 8:
513
+ matchedContacts = _context10.sent;
514
+
515
+ if (matchedContacts.data.length) {
516
+ _context10.next = 11;
517
+ break;
518
+ }
519
+
520
+ throw new Error("Contact not found for member ".concat(member.email));
521
+
522
+ case 11:
523
+ contact = matchedContacts.data[0]; // Revoke (API call only, no state dispatch to avoid UI flickering)
524
+
525
+ _context10.next = 14;
526
+ return _this2.sharingCol.revokeRecipient(sharing, memberIndex);
527
+
528
+ case 14:
529
+ // Re-add with the new permission type
530
+ readOnly = newType === 'one-way';
531
+ _context10.prev = 15;
532
+ _context10.next = 18;
533
+ return _this2.addRecipients({
534
+ document: sharing,
535
+ recipients: readOnly ? [] : [contact],
536
+ readOnlyRecipients: readOnly ? [contact] : []
537
+ });
538
+
539
+ case 18:
540
+ _context10.next = 24;
541
+ break;
542
+
543
+ case 20:
544
+ _context10.prev = 20;
545
+ _context10.t0 = _context10["catch"](15);
546
+ log.error("Failed to re-add member ".concat(member.email, " after revocation. The member has been revoked but could not be re-added with the new permission type."), _context10.t0);
547
+ throw _context10.t0;
548
+
549
+ case 24:
550
+ case "end":
551
+ return _context10.stop();
552
+ }
553
+ }, _callee10, null, [[15, 20]]);
554
+ }));
555
+
556
+ return function (_x16, _x17, _x18) {
557
+ return _ref12.apply(this, arguments);
558
+ };
559
+ }());
560
+
561
+ _defineProperty(_this2, "shareByLink", /*#__PURE__*/function () {
562
+ var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(document, options) {
563
+ var resp;
564
+ return _regeneratorRuntime.wrap(function _callee11$(_context11) {
565
+ while (1) switch (_context11.prev = _context11.next) {
566
+ case 0:
567
+ if (!document.driveId) {
568
+ _context11.next = 6;
569
+ break;
570
+ }
571
+
572
+ _context11.next = 3;
478
573
  return _this2.createSharedDriveSharingLink(document, options);
479
574
 
480
575
  case 3:
481
- _context10.t0 = _context10.sent;
482
- _context10.next = 9;
576
+ _context11.t0 = _context11.sent;
577
+ _context11.next = 9;
483
578
  break;
484
579
 
485
580
  case 6:
486
- _context10.next = 8;
581
+ _context11.next = 8;
487
582
  return _this2.permissionCol.createSharingLink(document, options);
488
583
 
489
584
  case 8:
490
- _context10.t0 = _context10.sent;
585
+ _context11.t0 = _context11.sent;
491
586
 
492
587
  case 9:
493
- resp = _context10.t0;
588
+ resp = _context11.t0;
494
589
 
495
590
  _this2.dispatch(addSharingLink(resp.data));
496
591
 
497
- return _context10.abrupt("return", resp);
592
+ return _context11.abrupt("return", resp);
498
593
 
499
594
  case 12:
500
595
  case "end":
501
- return _context10.stop();
596
+ return _context11.stop();
502
597
  }
503
- }, _callee10);
598
+ }, _callee11);
504
599
  }));
505
600
 
506
- return function (_x16, _x17) {
507
- return _ref12.apply(this, arguments);
601
+ return function (_x19, _x20) {
602
+ return _ref13.apply(this, arguments);
508
603
  };
509
604
  }());
510
605
 
@@ -531,67 +626,67 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
531
626
  });
532
627
 
533
628
  _defineProperty(_this2, "createSharedDriveSharingLink", /*#__PURE__*/function () {
534
- var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(document, options) {
629
+ var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(document, options) {
535
630
  var client, drivePermissionCollection, resp;
536
- return _regeneratorRuntime.wrap(function _callee11$(_context11) {
537
- while (1) switch (_context11.prev = _context11.next) {
631
+ return _regeneratorRuntime.wrap(function _callee12$(_context12) {
632
+ while (1) switch (_context12.prev = _context12.next) {
538
633
  case 0:
539
634
  client = _this2.props.client;
540
635
  drivePermissionCollection = client.collection('io.cozy.permissions', {
541
636
  driveId: document.driveId
542
637
  });
543
- _context11.next = 4;
638
+ _context12.next = 4;
544
639
  return drivePermissionCollection.createSharingLink(document, options);
545
640
 
546
641
  case 4:
547
- resp = _context11.sent;
548
- return _context11.abrupt("return", resp);
642
+ resp = _context12.sent;
643
+ return _context12.abrupt("return", resp);
549
644
 
550
645
  case 6:
551
646
  case "end":
552
- return _context11.stop();
647
+ return _context12.stop();
553
648
  }
554
- }, _callee11);
649
+ }, _callee12);
555
650
  }));
556
651
 
557
- return function (_x18, _x19) {
558
- return _ref13.apply(this, arguments);
652
+ return function (_x21, _x22) {
653
+ return _ref14.apply(this, arguments);
559
654
  };
560
655
  }());
561
656
 
562
657
  _defineProperty(_this2, "updateSharedDrivePermissions", /*#__PURE__*/function () {
563
- var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(document, permissionDocument, updatedPermissions, options) {
658
+ var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(document, permissionDocument, updatedPermissions, options) {
564
659
  var client, expiresAt, password, drivePermissionCollection, resp;
565
- return _regeneratorRuntime.wrap(function _callee12$(_context12) {
566
- while (1) switch (_context12.prev = _context12.next) {
660
+ return _regeneratorRuntime.wrap(function _callee13$(_context13) {
661
+ while (1) switch (_context13.prev = _context13.next) {
567
662
  case 0:
568
663
  client = _this2.props.client;
569
664
  expiresAt = options.expiresAt, password = options.password;
570
665
  drivePermissionCollection = client.collection('io.cozy.permissions', {
571
666
  driveId: document.driveId
572
667
  });
573
- _context12.next = 5;
668
+ _context13.next = 5;
574
669
  return drivePermissionCollection.add(permissionDocument, updatedPermissions, {
575
670
  expiresAt: expiresAt,
576
671
  password: password
577
672
  });
578
673
 
579
674
  case 5:
580
- resp = _context12.sent;
675
+ resp = _context13.sent;
581
676
 
582
677
  _this2.dispatch(updateSharingLink(resp.data));
583
678
 
584
- return _context12.abrupt("return", resp);
679
+ return _context13.abrupt("return", resp);
585
680
 
586
681
  case 8:
587
682
  case "end":
588
- return _context12.stop();
683
+ return _context13.stop();
589
684
  }
590
- }, _callee12);
685
+ }, _callee13);
591
686
  }));
592
687
 
593
- return function (_x20, _x21, _x22, _x23) {
594
- return _ref14.apply(this, arguments);
688
+ return function (_x23, _x24, _x25, _x26) {
689
+ return _ref15.apply(this, arguments);
595
690
  };
596
691
  }());
597
692
 
@@ -607,28 +702,28 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
607
702
  * @return {Array}
608
703
  */
609
704
  _defineProperty(_this2, "updateDocumentPermissions", /*#__PURE__*/function () {
610
- var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(document, options) {
705
+ var _ref16 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(document, options) {
611
706
  var verbs, expiresAt, password, permissions, responses;
612
- return _regeneratorRuntime.wrap(function _callee14$(_context14) {
613
- while (1) switch (_context14.prev = _context14.next) {
707
+ return _regeneratorRuntime.wrap(function _callee15$(_context15) {
708
+ while (1) switch (_context15.prev = _context15.next) {
614
709
  case 0:
615
710
  verbs = options.verbs, expiresAt = options.expiresAt, password = options.password;
616
711
  permissions = _getDocumentPermissions(_this2.state, document.id);
617
712
 
618
713
  if (!(!permissions || permissions.length === 0)) {
619
- _context14.next = 4;
714
+ _context15.next = 4;
620
715
  break;
621
716
  }
622
717
 
623
- return _context14.abrupt("return", []);
718
+ return _context15.abrupt("return", []);
624
719
 
625
720
  case 4:
626
- _context14.next = 6;
721
+ _context15.next = 6;
627
722
  return Promise.all(permissions.map( /*#__PURE__*/function () {
628
- var _ref16 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(permissionDocument) {
723
+ var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(permissionDocument) {
629
724
  var updatedPermissions, resp;
630
- return _regeneratorRuntime.wrap(function _callee13$(_context13) {
631
- while (1) switch (_context13.prev = _context13.next) {
725
+ return _regeneratorRuntime.wrap(function _callee14$(_context14) {
726
+ while (1) switch (_context14.prev = _context14.next) {
632
727
  case 0:
633
728
  updatedPermissions = permissionDocument.attributes.permissions;
634
729
  Object.keys(updatedPermissions).forEach(function (permType) {
@@ -636,70 +731,70 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
636
731
  });
637
732
 
638
733
  if (!document.driveId) {
639
- _context13.next = 8;
734
+ _context14.next = 8;
640
735
  break;
641
736
  }
642
737
 
643
- _context13.next = 5;
738
+ _context14.next = 5;
644
739
  return _this2.updateSharedDrivePermissions(document, permissionDocument, updatedPermissions, options);
645
740
 
646
741
  case 5:
647
- _context13.t0 = _context13.sent;
648
- _context13.next = 11;
742
+ _context14.t0 = _context14.sent;
743
+ _context14.next = 11;
649
744
  break;
650
745
 
651
746
  case 8:
652
- _context13.next = 10;
747
+ _context14.next = 10;
653
748
  return _this2.permissionCol.add(permissionDocument, updatedPermissions, {
654
749
  expiresAt: expiresAt,
655
750
  password: password
656
751
  });
657
752
 
658
753
  case 10:
659
- _context13.t0 = _context13.sent;
754
+ _context14.t0 = _context14.sent;
660
755
 
661
756
  case 11:
662
- resp = _context13.t0;
663
- return _context13.abrupt("return", resp);
757
+ resp = _context14.t0;
758
+ return _context14.abrupt("return", resp);
664
759
 
665
760
  case 13:
666
761
  case "end":
667
- return _context13.stop();
762
+ return _context14.stop();
668
763
  }
669
- }, _callee13);
764
+ }, _callee14);
670
765
  }));
671
766
 
672
- return function (_x26) {
673
- return _ref16.apply(this, arguments);
767
+ return function (_x29) {
768
+ return _ref17.apply(this, arguments);
674
769
  };
675
770
  }()));
676
771
 
677
772
  case 6:
678
- responses = _context14.sent;
679
- return _context14.abrupt("return", responses);
773
+ responses = _context15.sent;
774
+ return _context15.abrupt("return", responses);
680
775
 
681
776
  case 8:
682
777
  case "end":
683
- return _context14.stop();
778
+ return _context15.stop();
684
779
  }
685
- }, _callee14);
780
+ }, _callee15);
686
781
  }));
687
782
 
688
- return function (_x24, _x25) {
689
- return _ref15.apply(this, arguments);
783
+ return function (_x27, _x28) {
784
+ return _ref16.apply(this, arguments);
690
785
  };
691
786
  }());
692
787
 
693
788
  _defineProperty(_this2, "revokeSharingLink", /*#__PURE__*/function () {
694
- var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(document) {
789
+ var _ref18 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(document) {
695
790
  var perms;
696
- return _regeneratorRuntime.wrap(function _callee15$(_context15) {
697
- while (1) switch (_context15.prev = _context15.next) {
791
+ return _regeneratorRuntime.wrap(function _callee16$(_context16) {
792
+ while (1) switch (_context16.prev = _context16.next) {
698
793
  case 0:
699
794
  // Because some duplicate links have been created in the past, we must ensure
700
795
  // we revoke all of them
701
796
  perms = _getDocumentPermissions(_this2.state, document.id);
702
- _context15.next = 3;
797
+ _context16.next = 3;
703
798
  return Promise.all(perms.map(function (p) {
704
799
  return _this2.permissionCol.destroy(p);
705
800
  }));
@@ -709,13 +804,13 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
709
804
 
710
805
  case 4:
711
806
  case "end":
712
- return _context15.stop();
807
+ return _context16.stop();
713
808
  }
714
- }, _callee15);
809
+ }, _callee16);
715
810
  }));
716
811
 
717
- return function (_x27) {
718
- return _ref17.apply(this, arguments);
812
+ return function (_x30) {
813
+ return _ref18.apply(this, arguments);
719
814
  };
720
815
  }());
721
816
 
@@ -802,7 +897,8 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
802
897
  revokeAllRecipients: _this2.revokeAllRecipients,
803
898
  refresh: _this2.fetchAllSharings,
804
899
  hasWriteAccess: _this2.hasWriteAccess,
805
- renameSharedDrive: _this2.renameSharedDrive
900
+ renameSharedDrive: _this2.renameSharedDrive,
901
+ updateSharingMemberType: _this2.updateSharingMemberType
806
902
  };
807
903
  _this2.isPublic = (_props$isPublic = props.isPublic) !== null && _props$isPublic !== void 0 ? _props$isPublic : false;
808
904
  _this2.realtime = null;
@@ -838,14 +934,14 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
838
934
  }, {
839
935
  key: "fetchAllSharings",
840
936
  value: function () {
841
- var _fetchAllSharings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16() {
937
+ var _fetchAllSharings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17() {
842
938
  var _this$props, doctype, client, _yield$Promise$all, _yield$Promise$all2, sharings, permissions, apps, sharedDocIds, resp, folderPaths, filePaths;
843
939
 
844
- return _regeneratorRuntime.wrap(function _callee16$(_context16) {
845
- while (1) switch (_context16.prev = _context16.next) {
940
+ return _regeneratorRuntime.wrap(function _callee17$(_context17) {
941
+ while (1) switch (_context17.prev = _context17.next) {
846
942
  case 0:
847
943
  if (!this.isPublic) {
848
- _context16.next = 4;
944
+ _context17.next = 4;
849
945
  break;
850
946
  }
851
947
 
@@ -854,17 +950,17 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
854
950
  this.setState({
855
951
  allLoaded: true
856
952
  });
857
- return _context16.abrupt("return");
953
+ return _context17.abrupt("return");
858
954
 
859
955
  case 4:
860
956
  _this$props = this.props, doctype = _this$props.doctype, client = _this$props.client;
861
- _context16.next = 7;
957
+ _context17.next = 7;
862
958
  return Promise.all([this.sharingCol.findByDoctype(doctype, {
863
959
  withSharedDocs: false
864
960
  }), this.permissionCol.findLinksByDoctype(doctype), client.fetchQueryAndGetFromState(fetchApps())]);
865
961
 
866
962
  case 7:
867
- _yield$Promise$all = _context16.sent;
963
+ _yield$Promise$all = _context17.sent;
868
964
  _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 3);
869
965
  sharings = _yield$Promise$all2[0];
870
966
  permissions = _yield$Promise$all2[1];
@@ -879,35 +975,35 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
879
975
  hasLoadedAtLeastOnePage: true
880
976
  }); // eslint-disable-next-line promise/catch-or-return
881
977
 
882
- _context16.next = 16;
978
+ _context17.next = 16;
883
979
  return fetchNextPermissions(permissions, this.dispatch, this.permissionCol);
884
980
 
885
981
  case 16:
886
982
  if (!(doctype === 'io.cozy.files')) {
887
- _context16.next = 26;
983
+ _context17.next = 26;
888
984
  break;
889
985
  }
890
986
 
891
987
  sharedDocIds = getSharedDocIdsBySharings(sharings);
892
- _context16.next = 20;
988
+ _context17.next = 20;
893
989
  return client.collection(doctype).all({
894
990
  keys: sharedDocIds
895
991
  });
896
992
 
897
993
  case 20:
898
- resp = _context16.sent;
994
+ resp = _context17.sent;
899
995
  folderPaths = resp.data.filter(function (f) {
900
996
  return f.type === 'directory' && !f.trashed;
901
997
  }).map(function (f) {
902
998
  return f.path;
903
999
  });
904
- _context16.next = 24;
1000
+ _context17.next = 24;
905
1001
  return fetchFilesPaths(client, doctype, resp.data.filter(function (f) {
906
1002
  return f.type !== 'directory' && !f.trashed;
907
1003
  }));
908
1004
 
909
1005
  case 24:
910
- filePaths = _context16.sent;
1006
+ filePaths = _context17.sent;
911
1007
  this.dispatch(receivePaths([].concat(_toConsumableArray(folderPaths), _toConsumableArray(filePaths))));
912
1008
 
913
1009
  case 26:
@@ -917,9 +1013,9 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
917
1013
 
918
1014
  case 27:
919
1015
  case "end":
920
- return _context16.stop();
1016
+ return _context17.stop();
921
1017
  }
922
- }, _callee16, this);
1018
+ }, _callee17, this);
923
1019
  }));
924
1020
 
925
1021
  function fetchAllSharings() {
@@ -1,4 +1,10 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
1
2
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
+
4
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
+
6
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
+
2
8
  import _regeneratorRuntime from "@babel/runtime/regenerator";
3
9
  import { act, render, screen } from '@testing-library/react';
4
10
  import React from 'react';
@@ -308,6 +314,152 @@ describe('updateDocumentPermissions', function () {
308
314
  }
309
315
  }, _callee5);
310
316
  })));
317
+ });
318
+ describe('updateSharingMemberType', function () {
319
+ var mockContact = {
320
+ _id: 'contact-1',
321
+ email: [{
322
+ address: 'bob@bob.cozy'
323
+ }]
324
+ };
325
+ var mockSharing = {
326
+ id: 'sharing-123',
327
+ type: 'io.cozy.sharings',
328
+ attributes: {
329
+ members: [{
330
+ status: 'owner',
331
+ email: 'owner@cozy.local'
332
+ }, {
333
+ status: 'ready',
334
+ email: 'bob@bob.cozy'
335
+ }]
336
+ }
337
+ };
338
+ var instance;
339
+ var mockContactsCollection;
340
+ beforeEach(function () {
341
+ mockContactsCollection = {
342
+ find: jest.fn().mockResolvedValue({
343
+ data: [mockContact]
344
+ })
345
+ };
346
+ var mockClient = {
347
+ getStackClient: function getStackClient() {
348
+ return {
349
+ uri: 'http://cozy.local'
350
+ };
351
+ },
352
+ collection: jest.fn().mockReturnValue(mockContactsCollection)
353
+ };
354
+ instance = new SharingProvider({
355
+ client: mockClient
356
+ });
357
+ instance.state = _objectSpread(_objectSpread({}, instance.state), {}, {
358
+ sharings: [mockSharing]
359
+ });
360
+ instance.sharingCol = {
361
+ revokeRecipient: jest.fn().mockResolvedValue({})
362
+ };
363
+ jest.spyOn(instance, 'addRecipients').mockResolvedValue({});
364
+ });
365
+ it('should throw when sharing is not found', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
366
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
367
+ while (1) switch (_context6.prev = _context6.next) {
368
+ case 0:
369
+ _context6.next = 2;
370
+ return expect(instance.updateSharingMemberType('unknown-id', 1, 'one-way')).rejects.toThrow('Sharing not found');
371
+
372
+ case 2:
373
+ case "end":
374
+ return _context6.stop();
375
+ }
376
+ }, _callee6);
377
+ })));
378
+ it('should throw when member is not found', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
379
+ return _regeneratorRuntime.wrap(function _callee7$(_context7) {
380
+ while (1) switch (_context7.prev = _context7.next) {
381
+ case 0:
382
+ _context7.next = 2;
383
+ return expect(instance.updateSharingMemberType('sharing-123', 99, 'one-way')).rejects.toThrow('Member not found');
384
+
385
+ case 2:
386
+ case "end":
387
+ return _context7.stop();
388
+ }
389
+ }, _callee7);
390
+ })));
391
+ it('should throw when contact is not found', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
392
+ return _regeneratorRuntime.wrap(function _callee8$(_context8) {
393
+ while (1) switch (_context8.prev = _context8.next) {
394
+ case 0:
395
+ mockContactsCollection.find.mockResolvedValue({
396
+ data: []
397
+ });
398
+ _context8.next = 3;
399
+ return expect(instance.updateSharingMemberType('sharing-123', 1, 'one-way')).rejects.toThrow('Contact not found');
400
+
401
+ case 3:
402
+ case "end":
403
+ return _context8.stop();
404
+ }
405
+ }, _callee8);
406
+ })));
407
+ it('should revoke and re-add with readOnly when switching to one-way', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
408
+ return _regeneratorRuntime.wrap(function _callee9$(_context9) {
409
+ while (1) switch (_context9.prev = _context9.next) {
410
+ case 0:
411
+ _context9.next = 2;
412
+ return instance.updateSharingMemberType('sharing-123', 1, 'one-way');
413
+
414
+ case 2:
415
+ expect(instance.sharingCol.revokeRecipient).toHaveBeenCalledWith(mockSharing, 1);
416
+ expect(instance.addRecipients).toHaveBeenCalledWith({
417
+ document: mockSharing,
418
+ recipients: [],
419
+ readOnlyRecipients: [mockContact]
420
+ });
421
+
422
+ case 4:
423
+ case "end":
424
+ return _context9.stop();
425
+ }
426
+ }, _callee9);
427
+ })));
428
+ it('should revoke and re-add as read-write when switching to two-way', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
429
+ return _regeneratorRuntime.wrap(function _callee10$(_context10) {
430
+ while (1) switch (_context10.prev = _context10.next) {
431
+ case 0:
432
+ _context10.next = 2;
433
+ return instance.updateSharingMemberType('sharing-123', 1, 'two-way');
434
+
435
+ case 2:
436
+ expect(instance.sharingCol.revokeRecipient).toHaveBeenCalledWith(mockSharing, 1);
437
+ expect(instance.addRecipients).toHaveBeenCalledWith({
438
+ document: mockSharing,
439
+ recipients: [mockContact],
440
+ readOnlyRecipients: []
441
+ });
442
+
443
+ case 4:
444
+ case "end":
445
+ return _context10.stop();
446
+ }
447
+ }, _callee10);
448
+ })));
449
+ it('should rethrow error if addRecipients fails after revocation', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11() {
450
+ return _regeneratorRuntime.wrap(function _callee11$(_context11) {
451
+ while (1) switch (_context11.prev = _context11.next) {
452
+ case 0:
453
+ instance.addRecipients.mockRejectedValue(new Error('Network error'));
454
+ _context11.next = 3;
455
+ return expect(instance.updateSharingMemberType('sharing-123', 1, 'one-way')).rejects.toThrow('Network error');
456
+
457
+ case 3:
458
+ case "end":
459
+ return _context11.stop();
460
+ }
461
+ }, _callee11);
462
+ })));
311
463
  }); // TODO Convert with react-testing-library
312
464
  // describe('hasWriteAccess', () => {
313
465
  // it('tells if a doc is writtable', () => {