cozy-sharing 37.5.4 → 37.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.
@@ -36,11 +36,12 @@ import minilog from 'cozy-minilog';
36
36
  import { generateShareLinkFromFile, getLinkAccessOptions } from './components/ShareRestrictionModal/helpers';
37
37
  import SharingContext from './context';
38
38
  import { fetchNextPermissions } from './fetchNextPermissions';
39
+ import { mapEffectiveRecipients } from './helpers/effectiveRecipients';
39
40
  import { fetchFilesPaths } from './helpers/files';
40
41
  import { getSharingObject, createSharingInStore, updateSharingInStore } from './helpers/sharings';
41
42
  import { getShortcode } from './helpers/shortcodes';
42
43
  import { SynchronousJobQueue } from './helpers/synchronousJobQueue';
43
- 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, getPermissionDocIds, 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, receiveEffectiveRecipients, updateEffectiveRecipient, invalidateEffectiveRecipients, getEffectiveRecipients as _getEffectiveRecipients, 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, getPermissionDocIds, hasSharedParent as _hasSharedParent, hasSharedChild as _hasSharedChild, getSharedParentPath as _getSharedParentPath, getSharedDriveSharingType, SHARING_TYPE } from './state';
44
45
  var log = minilog('SharingProvider');
45
46
  var SHARING_DOCTYPE = 'io.cozy.sharings';
46
47
  var PERMISSION_DOCTYPE = 'io.cozy.permissions';
@@ -139,7 +140,7 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
139
140
  sharing = getDocumentSharing(_this2.state, document.id);
140
141
 
141
142
  if (!sharing) {
142
- _context2.next = 10;
143
+ _context2.next = 12;
143
144
  break;
144
145
  }
145
146
 
@@ -160,11 +161,15 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
160
161
  });
161
162
 
162
163
  case 9:
164
+ _context2.next = 11;
165
+ return _this2.fetchEffectiveRecipients(getDocumentId(document), document.driveId);
166
+
167
+ case 11:
163
168
  return _context2.abrupt("return", sharingResult);
164
169
 
165
- case 10:
170
+ case 12:
166
171
  previewPath = (_this2$props$previewP = _this2.props.previewPath) !== null && _this2$props$previewP !== void 0 ? _this2$props$previewP : '/preview';
167
- _context2.next = 13;
172
+ _context2.next = 15;
168
173
  return _this2.sharingCol.create({
169
174
  document: document,
170
175
  recipients: recipients,
@@ -175,7 +180,7 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
175
180
  sharedDrive: sharedDrive
176
181
  });
177
182
 
178
- case 13:
183
+ case 15:
179
184
  _yield$_this2$sharing = _context2.sent;
180
185
  data = _yield$_this2$sharing.data;
181
186
  _context2.t0 = _this2;
@@ -184,33 +189,37 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
184
189
  _context2.t3 = document.path;
185
190
 
186
191
  if (_context2.t3) {
187
- _context2.next = 23;
192
+ _context2.next = 25;
188
193
  break;
189
194
  }
190
195
 
191
- _context2.next = 22;
196
+ _context2.next = 24;
192
197
  return fetchFilesPaths(client, doctype, [document]);
193
198
 
194
- case 22:
199
+ case 24:
195
200
  _context2.t3 = _context2.sent;
196
201
 
197
- case 23:
202
+ case 25:
198
203
  _context2.t4 = _context2.t3;
199
204
  _context2.t5 = (0, _context2.t1)(_context2.t2, _context2.t4);
200
205
 
201
206
  _context2.t0.dispatch.call(_context2.t0, _context2.t5);
202
207
 
203
- _context2.next = 28;
208
+ _context2.next = 30;
204
209
  return _this2.state.onShared({
205
210
  document: document,
206
211
  recipients: recipients,
207
212
  readOnlyRecipients: readOnlyRecipients
208
213
  });
209
214
 
210
- case 28:
215
+ case 30:
216
+ _context2.next = 32;
217
+ return _this2.fetchEffectiveRecipients(getDocumentId(document), document.driveId);
218
+
219
+ case 32:
211
220
  return _context2.abrupt("return", data);
212
221
 
213
- case 29:
222
+ case 33:
214
223
  case "end":
215
224
  return _context2.stop();
216
225
  }
@@ -333,8 +342,10 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
333
342
  return _ref8.apply(this, arguments);
334
343
  };
335
344
  }());
345
+ _context6.next = 8;
346
+ return _this2.fetchEffectiveRecipients(getDocumentId(document), document.driveId);
336
347
 
337
- case 6:
348
+ case 8:
338
349
  case "end":
339
350
  return _context6.stop();
340
351
  }
@@ -382,7 +393,10 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
382
393
 
383
394
  _context7.t0.dispatch.call(_context7.t0, _context7.t6);
384
395
 
385
- case 16:
396
+ _context7.next = 18;
397
+ return _this2.fetchEffectiveRecipients(getDocumentId(document), document.driveId);
398
+
399
+ case 18:
386
400
  case "end":
387
401
  return _context7.stop();
388
402
  }
@@ -455,7 +469,10 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
455
469
  case 3:
456
470
  _this2.dispatch(revokeSelf(sharing));
457
471
 
458
- case 4:
472
+ _context9.next = 6;
473
+ return _this2.fetchEffectiveRecipients(getDocumentId(document), document.driveId);
474
+
475
+ case 6:
459
476
  case "end":
460
477
  return _context9.stop();
461
478
  }
@@ -475,7 +492,7 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
475
492
  */
476
493
  _defineProperty(_this2, "updateSharingMemberType", /*#__PURE__*/function () {
477
494
  var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(sharingId, memberIndex, newType) {
478
- var sharing, member, makeReadOnly, optimisticSharing, currentSharing, rollbackSharing;
495
+ var sharing, member, makeReadOnly, optimisticSharing, currentSharing, rollbackSharing, docId, driveId;
479
496
  return _regeneratorRuntime.wrap(function _callee10$(_context10) {
480
497
  while (1) switch (_context10.prev = _context10.next) {
481
498
  case 0:
@@ -521,31 +538,33 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
521
538
 
522
539
  _this2.dispatch(updateSharing(optimisticSharing));
523
540
 
524
- _context10.prev = 11;
541
+ _this2.dispatch(updateEffectiveRecipient(sharingId, memberIndex, makeReadOnly));
542
+
543
+ _context10.prev = 12;
525
544
 
526
545
  if (!makeReadOnly) {
527
- _context10.next = 17;
546
+ _context10.next = 18;
528
547
  break;
529
548
  }
530
549
 
531
- _context10.next = 15;
550
+ _context10.next = 16;
532
551
  return _this2.sharingCol.setReadOnly(sharing, memberIndex);
533
552
 
534
- case 15:
535
- _context10.next = 19;
553
+ case 16:
554
+ _context10.next = 20;
536
555
  break;
537
556
 
538
- case 17:
539
- _context10.next = 19;
557
+ case 18:
558
+ _context10.next = 20;
540
559
  return _this2.sharingCol.setReadWrite(sharing, memberIndex);
541
560
 
542
- case 19:
543
- _context10.next = 28;
561
+ case 20:
562
+ _context10.next = 30;
544
563
  break;
545
564
 
546
- case 21:
547
- _context10.prev = 21;
548
- _context10.t0 = _context10["catch"](11);
565
+ case 22:
566
+ _context10.prev = 22;
567
+ _context10.t0 = _context10["catch"](12);
549
568
  currentSharing = _getSharingById(_this2.state, sharingId) || sharing;
550
569
  rollbackSharing = _objectSpread(_objectSpread({}, currentSharing), {}, {
551
570
  attributes: _objectSpread(_objectSpread({}, currentSharing.attributes), {}, {
@@ -559,14 +578,32 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
559
578
 
560
579
  _this2.dispatch(updateSharing(rollbackSharing));
561
580
 
581
+ _this2.dispatch(updateEffectiveRecipient(sharingId, memberIndex, !makeReadOnly));
582
+
562
583
  log.error("Failed to change member ".concat(member.email, " permission type to ").concat(newType), _context10.t0);
563
584
  throw _context10.t0;
564
585
 
565
- case 28:
586
+ case 30:
587
+ docId = Object.keys(_this2.state.byDocId).find(function (id) {
588
+ var _this2$state$byDocId$;
589
+
590
+ return (_this2$state$byDocId$ = _this2.state.byDocId[id].sharings) === null || _this2$state$byDocId$ === void 0 ? void 0 : _this2$state$byDocId$.includes(sharingId);
591
+ });
592
+
593
+ if (!docId) {
594
+ _context10.next = 35;
595
+ break;
596
+ }
597
+
598
+ driveId = _this2.state.byDocId[docId].driveId;
599
+ _context10.next = 35;
600
+ return _this2.fetchEffectiveRecipients(docId, driveId);
601
+
602
+ case 35:
566
603
  case "end":
567
604
  return _context10.stop();
568
605
  }
569
- }, _callee10, null, [[11, 21]]);
606
+ }, _callee10, null, [[12, 22]]);
570
607
  }));
571
608
 
572
609
  return function (_x16, _x17, _x18) {
@@ -574,82 +611,114 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
574
611
  };
575
612
  }());
576
613
 
577
- _defineProperty(_this2, "shareByLink", /*#__PURE__*/function () {
578
- var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(document, options) {
579
- var resp, permissions;
614
+ _defineProperty(_this2, "fetchEffectiveRecipients", /*#__PURE__*/function () {
615
+ var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(fileId, driveId) {
616
+ var resp;
580
617
  return _regeneratorRuntime.wrap(function _callee11$(_context11) {
581
618
  while (1) switch (_context11.prev = _context11.next) {
582
619
  case 0:
583
- _context11.prev = 0;
620
+ _context11.next = 2;
621
+ return _this2.sharingCol.fetchEffectiveRecipients(fileId, {
622
+ driveId: driveId
623
+ });
624
+
625
+ case 2:
626
+ resp = _context11.sent;
627
+
628
+ _this2.dispatch(receiveEffectiveRecipients(fileId, mapEffectiveRecipients((resp === null || resp === void 0 ? void 0 : resp.data) || [])));
629
+
630
+ case 4:
631
+ case "end":
632
+ return _context11.stop();
633
+ }
634
+ }, _callee11);
635
+ }));
636
+
637
+ return function (_x19, _x20) {
638
+ return _ref13.apply(this, arguments);
639
+ };
640
+ }());
641
+
642
+ _defineProperty(_this2, "invalidateEffectiveRecipients", function (docId) {
643
+ _this2.dispatch(invalidateEffectiveRecipients(docId));
644
+ });
645
+
646
+ _defineProperty(_this2, "shareByLink", /*#__PURE__*/function () {
647
+ var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(document, options) {
648
+ var resp, permissions;
649
+ return _regeneratorRuntime.wrap(function _callee12$(_context12) {
650
+ while (1) switch (_context12.prev = _context12.next) {
651
+ case 0:
652
+ _context12.prev = 0;
584
653
 
585
654
  if (!document.driveId) {
586
- _context11.next = 7;
655
+ _context12.next = 7;
587
656
  break;
588
657
  }
589
658
 
590
- _context11.next = 4;
659
+ _context12.next = 4;
591
660
  return _this2.createSharedDriveSharingLink(document, options);
592
661
 
593
662
  case 4:
594
- _context11.t0 = _context11.sent;
595
- _context11.next = 10;
663
+ _context12.t0 = _context12.sent;
664
+ _context12.next = 10;
596
665
  break;
597
666
 
598
667
  case 7:
599
- _context11.next = 9;
668
+ _context12.next = 9;
600
669
  return _this2.permissionCol.createSharingLink(document, options);
601
670
 
602
671
  case 9:
603
- _context11.t0 = _context11.sent;
672
+ _context12.t0 = _context12.sent;
604
673
 
605
674
  case 10:
606
- resp = _context11.t0;
675
+ resp = _context12.t0;
607
676
 
608
677
  _this2.dispatch(addSharingLink(resp.data));
609
678
 
610
- return _context11.abrupt("return", resp);
679
+ return _context12.abrupt("return", resp);
611
680
 
612
681
  case 15:
613
- _context11.prev = 15;
614
- _context11.t1 = _context11["catch"](0);
682
+ _context12.prev = 15;
683
+ _context12.t1 = _context12["catch"](0);
615
684
 
616
- if (!(document.driveId && _context11.t1 && _context11.t1.status === 409)) {
617
- _context11.next = 23;
685
+ if (!(document.driveId && _context12.t1 && _context12.t1.status === 409)) {
686
+ _context12.next = 23;
618
687
  break;
619
688
  }
620
689
 
621
- _context11.next = 20;
690
+ _context12.next = 20;
622
691
  return _this2.fetchSharedDriveSharingLinks(document);
623
692
 
624
693
  case 20:
625
- permissions = _context11.sent;
694
+ permissions = _context12.sent;
626
695
 
627
696
  if (!(permissions && permissions.length > 0)) {
628
- _context11.next = 23;
697
+ _context12.next = 23;
629
698
  break;
630
699
  }
631
700
 
632
- return _context11.abrupt("return", {
701
+ return _context12.abrupt("return", {
633
702
  data: permissions[0]
634
703
  });
635
704
 
636
705
  case 23:
637
- throw _context11.t1;
706
+ throw _context12.t1;
638
707
 
639
708
  case 24:
640
709
  case "end":
641
- return _context11.stop();
710
+ return _context12.stop();
642
711
  }
643
- }, _callee11, null, [[0, 15]]);
712
+ }, _callee12, null, [[0, 15]]);
644
713
  }));
645
714
 
646
- return function (_x19, _x20) {
647
- return _ref13.apply(this, arguments);
715
+ return function (_x21, _x22) {
716
+ return _ref14.apply(this, arguments);
648
717
  };
649
718
  }());
650
719
 
651
720
  _defineProperty(_this2, "fetchSharingLinks", /*#__PURE__*/function () {
652
- var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(document) {
721
+ var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(document) {
653
722
  var permissionCol,
654
723
  documentId,
655
724
  response,
@@ -657,43 +726,43 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
657
726
  existingPermissions,
658
727
  existingPermissionIds,
659
728
  newPermissions,
660
- _args12 = arguments;
661
- return _regeneratorRuntime.wrap(function _callee12$(_context12) {
662
- while (1) switch (_context12.prev = _context12.next) {
729
+ _args13 = arguments;
730
+ return _regeneratorRuntime.wrap(function _callee13$(_context13) {
731
+ while (1) switch (_context13.prev = _context13.next) {
663
732
  case 0:
664
- permissionCol = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : _this2.permissionCol;
733
+ permissionCol = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : _this2.permissionCol;
665
734
  documentId = getDocumentId(document);
666
735
 
667
736
  if (documentId) {
668
- _context12.next = 4;
737
+ _context13.next = 4;
669
738
  break;
670
739
  }
671
740
 
672
- return _context12.abrupt("return", []);
741
+ return _context13.abrupt("return", []);
673
742
 
674
743
  case 4:
675
744
  if (!document.driveId) {
676
- _context12.next = 10;
745
+ _context13.next = 10;
677
746
  break;
678
747
  }
679
748
 
680
- _context12.next = 7;
749
+ _context13.next = 7;
681
750
  return permissionCol.findLinksByIds([documentId]);
682
751
 
683
752
  case 7:
684
- _context12.t0 = _context12.sent;
685
- _context12.next = 13;
753
+ _context13.t0 = _context13.sent;
754
+ _context13.next = 13;
686
755
  break;
687
756
 
688
757
  case 10:
689
- _context12.next = 12;
758
+ _context13.next = 12;
690
759
  return permissionCol.findLinksByDoctype(_this2.props.doctype);
691
760
 
692
761
  case 12:
693
- _context12.t0 = _context12.sent;
762
+ _context13.t0 = _context13.sent;
694
763
 
695
764
  case 13:
696
- response = _context12.t0;
765
+ response = _context13.t0;
697
766
  permissions = ((response === null || response === void 0 ? void 0 : response.data) || []).filter(function (permission) {
698
767
  return document.driveId || getPermissionDocIds(permission).includes(documentId);
699
768
  });
@@ -709,31 +778,31 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
709
778
  _this2.dispatch(addSharingLink(newPermissions));
710
779
  }
711
780
 
712
- return _context12.abrupt("return", permissions);
781
+ return _context13.abrupt("return", permissions);
713
782
 
714
783
  case 20:
715
784
  case "end":
716
- return _context12.stop();
785
+ return _context13.stop();
717
786
  }
718
- }, _callee12);
787
+ }, _callee13);
719
788
  }));
720
789
 
721
- return function (_x21) {
722
- return _ref14.apply(this, arguments);
790
+ return function (_x23) {
791
+ return _ref15.apply(this, arguments);
723
792
  };
724
793
  }());
725
794
 
726
795
  _defineProperty(_this2, "ensureSharingLink", /*#__PURE__*/function () {
727
- var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(document, linkAccess) {
796
+ var _ref16 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(document, linkAccess) {
728
797
  var documentId, permissions, _getLinkAccessOptions, verbs, expiresAt, ttl, password, permissionResponse, permission, sharecode;
729
798
 
730
- return _regeneratorRuntime.wrap(function _callee13$(_context13) {
731
- while (1) switch (_context13.prev = _context13.next) {
799
+ return _regeneratorRuntime.wrap(function _callee14$(_context14) {
800
+ while (1) switch (_context14.prev = _context14.next) {
732
801
  case 0:
733
802
  documentId = getDocumentId(document);
734
803
 
735
804
  if (documentId) {
736
- _context13.next = 3;
805
+ _context14.next = 3;
737
806
  break;
738
807
  }
739
808
 
@@ -741,35 +810,35 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
741
810
 
742
811
  case 3:
743
812
  if (!document.driveId) {
744
- _context13.next = 9;
813
+ _context14.next = 9;
745
814
  break;
746
815
  }
747
816
 
748
- _context13.next = 6;
817
+ _context14.next = 6;
749
818
  return _this2.fetchSharedDriveSharingLinks(document);
750
819
 
751
820
  case 6:
752
- _context13.t0 = _context13.sent;
753
- _context13.next = 12;
821
+ _context14.t0 = _context14.sent;
822
+ _context14.next = 12;
754
823
  break;
755
824
 
756
825
  case 9:
757
- _context13.next = 11;
826
+ _context14.next = 11;
758
827
  return _this2.fetchSharingLinks(document);
759
828
 
760
829
  case 11:
761
- _context13.t0 = _context13.sent;
830
+ _context14.t0 = _context14.sent;
762
831
 
763
832
  case 12:
764
- permissions = _context13.t0;
833
+ permissions = _context14.t0;
765
834
  _getLinkAccessOptions = getLinkAccessOptions(linkAccess), verbs = _getLinkAccessOptions.verbs, expiresAt = _getLinkAccessOptions.expiresAt, ttl = _getLinkAccessOptions.ttl, password = _getLinkAccessOptions.password;
766
835
 
767
836
  if (!(permissions.length > 0)) {
768
- _context13.next = 20;
837
+ _context14.next = 20;
769
838
  break;
770
839
  }
771
840
 
772
- _context13.next = 17;
841
+ _context14.next = 17;
773
842
  return _this2.updateDocumentPermissions(_objectSpread(_objectSpread({}, document), {}, {
774
843
  id: documentId
775
844
  }), {
@@ -779,12 +848,12 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
779
848
  }, permissions);
780
849
 
781
850
  case 17:
782
- _context13.t1 = _context13.sent[0];
783
- _context13.next = 23;
851
+ _context14.t1 = _context14.sent[0];
852
+ _context14.next = 23;
784
853
  break;
785
854
 
786
855
  case 20:
787
- _context13.next = 22;
856
+ _context14.next = 22;
788
857
  return _this2.shareByLink(document, {
789
858
  verbs: verbs,
790
859
  ttl: ttl,
@@ -792,22 +861,22 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
792
861
  });
793
862
 
794
863
  case 22:
795
- _context13.t1 = _context13.sent;
864
+ _context14.t1 = _context14.sent;
796
865
 
797
866
  case 23:
798
- permissionResponse = _context13.t1;
867
+ permissionResponse = _context14.t1;
799
868
  permission = permissionResponse === null || permissionResponse === void 0 ? void 0 : permissionResponse.data;
800
869
  sharecode = getShortcode(permission);
801
870
 
802
871
  if (sharecode) {
803
- _context13.next = 28;
872
+ _context14.next = 28;
804
873
  break;
805
874
  }
806
875
 
807
876
  throw new Error('Sharing permission does not contain a shortcode');
808
877
 
809
878
  case 28:
810
- return _context13.abrupt("return", {
879
+ return _context14.abrupt("return", {
811
880
  documentId: documentId,
812
881
  url: generateShareLinkFromFile({
813
882
  client: _this2.props.client,
@@ -821,13 +890,13 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
821
890
 
822
891
  case 29:
823
892
  case "end":
824
- return _context13.stop();
893
+ return _context14.stop();
825
894
  }
826
- }, _callee13);
895
+ }, _callee14);
827
896
  }));
828
897
 
829
- return function (_x22, _x23) {
830
- return _ref15.apply(this, arguments);
898
+ return function (_x24, _x25) {
899
+ return _ref16.apply(this, arguments);
831
900
  };
832
901
  }());
833
902
 
@@ -856,99 +925,99 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
856
925
  });
857
926
 
858
927
  _defineProperty(_this2, "createSharedDriveSharingLink", /*#__PURE__*/function () {
859
- var _ref16 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(document, options) {
928
+ var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(document, options) {
860
929
  var client, drivePermissionCollection, resp;
861
- return _regeneratorRuntime.wrap(function _callee14$(_context14) {
862
- while (1) switch (_context14.prev = _context14.next) {
930
+ return _regeneratorRuntime.wrap(function _callee15$(_context15) {
931
+ while (1) switch (_context15.prev = _context15.next) {
863
932
  case 0:
864
933
  client = _this2.props.client;
865
934
  drivePermissionCollection = client.collection('io.cozy.permissions', {
866
935
  driveId: document.driveId
867
936
  });
868
- _context14.next = 4;
937
+ _context15.next = 4;
869
938
  return drivePermissionCollection.createSharingLink(document, options);
870
939
 
871
940
  case 4:
872
- resp = _context14.sent;
873
- return _context14.abrupt("return", resp);
941
+ resp = _context15.sent;
942
+ return _context15.abrupt("return", resp);
874
943
 
875
944
  case 6:
876
945
  case "end":
877
- return _context14.stop();
946
+ return _context15.stop();
878
947
  }
879
- }, _callee14);
948
+ }, _callee15);
880
949
  }));
881
950
 
882
- return function (_x24, _x25) {
883
- return _ref16.apply(this, arguments);
951
+ return function (_x26, _x27) {
952
+ return _ref17.apply(this, arguments);
884
953
  };
885
954
  }());
886
955
 
887
956
  _defineProperty(_this2, "fetchSharedDriveSharingLinks", /*#__PURE__*/function () {
888
- var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(document) {
957
+ var _ref18 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(document) {
889
958
  var client, drivePermissionCollection;
890
- return _regeneratorRuntime.wrap(function _callee15$(_context15) {
891
- while (1) switch (_context15.prev = _context15.next) {
959
+ return _regeneratorRuntime.wrap(function _callee16$(_context16) {
960
+ while (1) switch (_context16.prev = _context16.next) {
892
961
  case 0:
893
962
  if (!(!document || !document.driveId)) {
894
- _context15.next = 2;
963
+ _context16.next = 2;
895
964
  break;
896
965
  }
897
966
 
898
- return _context15.abrupt("return", []);
967
+ return _context16.abrupt("return", []);
899
968
 
900
969
  case 2:
901
970
  client = _this2.props.client;
902
971
  drivePermissionCollection = client.collection('io.cozy.permissions', {
903
972
  driveId: document.driveId
904
973
  });
905
- return _context15.abrupt("return", _this2.fetchSharingLinks(document, drivePermissionCollection));
974
+ return _context16.abrupt("return", _this2.fetchSharingLinks(document, drivePermissionCollection));
906
975
 
907
976
  case 5:
908
977
  case "end":
909
- return _context15.stop();
978
+ return _context16.stop();
910
979
  }
911
- }, _callee15);
980
+ }, _callee16);
912
981
  }));
913
982
 
914
- return function (_x26) {
915
- return _ref17.apply(this, arguments);
983
+ return function (_x28) {
984
+ return _ref18.apply(this, arguments);
916
985
  };
917
986
  }());
918
987
 
919
988
  _defineProperty(_this2, "updateSharedDrivePermissions", /*#__PURE__*/function () {
920
- var _ref18 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(document, permissionDocument, updatedPermissions, options) {
989
+ var _ref19 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(document, permissionDocument, updatedPermissions, options) {
921
990
  var client, expiresAt, password, drivePermissionCollection, resp;
922
- return _regeneratorRuntime.wrap(function _callee16$(_context16) {
923
- while (1) switch (_context16.prev = _context16.next) {
991
+ return _regeneratorRuntime.wrap(function _callee17$(_context17) {
992
+ while (1) switch (_context17.prev = _context17.next) {
924
993
  case 0:
925
994
  client = _this2.props.client;
926
995
  expiresAt = options.expiresAt, password = options.password;
927
996
  drivePermissionCollection = client.collection('io.cozy.permissions', {
928
997
  driveId: document.driveId
929
998
  });
930
- _context16.next = 5;
999
+ _context17.next = 5;
931
1000
  return drivePermissionCollection.add(permissionDocument, updatedPermissions, {
932
1001
  expiresAt: expiresAt,
933
1002
  password: password
934
1003
  });
935
1004
 
936
1005
  case 5:
937
- resp = _context16.sent;
1006
+ resp = _context17.sent;
938
1007
 
939
1008
  _this2.dispatch(updateSharingLink(resp.data));
940
1009
 
941
- return _context16.abrupt("return", resp);
1010
+ return _context17.abrupt("return", resp);
942
1011
 
943
1012
  case 8:
944
1013
  case "end":
945
- return _context16.stop();
1014
+ return _context17.stop();
946
1015
  }
947
- }, _callee16);
1016
+ }, _callee17);
948
1017
  }));
949
1018
 
950
- return function (_x27, _x28, _x29, _x30) {
951
- return _ref18.apply(this, arguments);
1019
+ return function (_x29, _x30, _x31, _x32) {
1020
+ return _ref19.apply(this, arguments);
952
1021
  };
953
1022
  }());
954
1023
 
@@ -966,7 +1035,7 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
966
1035
  * @return {Array}
967
1036
  */
968
1037
  _defineProperty(_this2, "updateDocumentPermissions", /*#__PURE__*/function () {
969
- var _ref19 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(document, options) {
1038
+ var _ref20 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(document, options) {
970
1039
  var permissionsToUpdate,
971
1040
  verbs,
972
1041
  expiresAt,
@@ -974,34 +1043,34 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
974
1043
  documentId,
975
1044
  permissions,
976
1045
  responses,
977
- _args18 = arguments;
978
- return _regeneratorRuntime.wrap(function _callee18$(_context18) {
979
- while (1) switch (_context18.prev = _context18.next) {
1046
+ _args19 = arguments;
1047
+ return _regeneratorRuntime.wrap(function _callee19$(_context19) {
1048
+ while (1) switch (_context19.prev = _context19.next) {
980
1049
  case 0:
981
- permissionsToUpdate = _args18.length > 2 && _args18[2] !== undefined ? _args18[2] : null;
1050
+ permissionsToUpdate = _args19.length > 2 && _args19[2] !== undefined ? _args19[2] : null;
982
1051
  verbs = options.verbs, expiresAt = options.expiresAt, password = options.password;
983
1052
  documentId = getDocumentId(document);
984
1053
  permissions = permissionsToUpdate || _getDocumentPermissions(_this2.state, documentId);
985
1054
 
986
1055
  if (!(!permissions || permissions.length === 0)) {
987
- _context18.next = 6;
1056
+ _context19.next = 6;
988
1057
  break;
989
1058
  }
990
1059
 
991
- return _context18.abrupt("return", []);
1060
+ return _context19.abrupt("return", []);
992
1061
 
993
1062
  case 6:
994
- _context18.next = 8;
1063
+ _context19.next = 8;
995
1064
  return Promise.all(permissions.map( /*#__PURE__*/function () {
996
- var _ref20 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(permissionDocument) {
1065
+ var _ref21 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(permissionDocument) {
997
1066
  var updatedPermissions, resp;
998
- return _regeneratorRuntime.wrap(function _callee17$(_context17) {
999
- while (1) switch (_context17.prev = _context17.next) {
1067
+ return _regeneratorRuntime.wrap(function _callee18$(_context18) {
1068
+ while (1) switch (_context18.prev = _context18.next) {
1000
1069
  case 0:
1001
- updatedPermissions = Object.fromEntries(Object.entries(permissionDocument.attributes.permissions).map(function (_ref21) {
1002
- var _ref22 = _slicedToArray(_ref21, 2),
1003
- permissionType = _ref22[0],
1004
- rules = _ref22[1];
1070
+ updatedPermissions = Object.fromEntries(Object.entries(permissionDocument.attributes.permissions).map(function (_ref22) {
1071
+ var _ref23 = _slicedToArray(_ref22, 2),
1072
+ permissionType = _ref23[0],
1073
+ rules = _ref23[1];
1005
1074
 
1006
1075
  return [permissionType, _objectSpread(_objectSpread({}, rules), {}, {
1007
1076
  verbs: verbs
@@ -1009,114 +1078,114 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
1009
1078
  }));
1010
1079
 
1011
1080
  if (!document.driveId) {
1012
- _context17.next = 7;
1081
+ _context18.next = 7;
1013
1082
  break;
1014
1083
  }
1015
1084
 
1016
- _context17.next = 4;
1085
+ _context18.next = 4;
1017
1086
  return _this2.updateSharedDrivePermissions(document, permissionDocument, updatedPermissions, options);
1018
1087
 
1019
1088
  case 4:
1020
- _context17.t0 = _context17.sent;
1021
- _context17.next = 10;
1089
+ _context18.t0 = _context18.sent;
1090
+ _context18.next = 10;
1022
1091
  break;
1023
1092
 
1024
1093
  case 7:
1025
- _context17.next = 9;
1094
+ _context18.next = 9;
1026
1095
  return _this2.permissionCol.add(permissionDocument, updatedPermissions, {
1027
1096
  expiresAt: expiresAt,
1028
1097
  password: password
1029
1098
  });
1030
1099
 
1031
1100
  case 9:
1032
- _context17.t0 = _context17.sent;
1101
+ _context18.t0 = _context18.sent;
1033
1102
 
1034
1103
  case 10:
1035
- resp = _context17.t0;
1104
+ resp = _context18.t0;
1036
1105
 
1037
1106
  _this2.dispatch(updateSharingLink(resp.data));
1038
1107
 
1039
- return _context17.abrupt("return", resp);
1108
+ return _context18.abrupt("return", resp);
1040
1109
 
1041
1110
  case 13:
1042
1111
  case "end":
1043
- return _context17.stop();
1112
+ return _context18.stop();
1044
1113
  }
1045
- }, _callee17);
1114
+ }, _callee18);
1046
1115
  }));
1047
1116
 
1048
- return function (_x33) {
1049
- return _ref20.apply(this, arguments);
1117
+ return function (_x35) {
1118
+ return _ref21.apply(this, arguments);
1050
1119
  };
1051
1120
  }()));
1052
1121
 
1053
1122
  case 8:
1054
- responses = _context18.sent;
1055
- return _context18.abrupt("return", responses);
1123
+ responses = _context19.sent;
1124
+ return _context19.abrupt("return", responses);
1056
1125
 
1057
1126
  case 10:
1058
1127
  case "end":
1059
- return _context18.stop();
1128
+ return _context19.stop();
1060
1129
  }
1061
- }, _callee18);
1130
+ }, _callee19);
1062
1131
  }));
1063
1132
 
1064
- return function (_x31, _x32) {
1065
- return _ref19.apply(this, arguments);
1133
+ return function (_x33, _x34) {
1134
+ return _ref20.apply(this, arguments);
1066
1135
  };
1067
1136
  }());
1068
1137
 
1069
1138
  _defineProperty(_this2, "revokeSharedDriveSharingLink", /*#__PURE__*/function () {
1070
- var _ref23 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(document, perms) {
1139
+ var _ref24 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20(document, perms) {
1071
1140
  var client, drivePermissionCollection;
1072
- return _regeneratorRuntime.wrap(function _callee19$(_context19) {
1073
- while (1) switch (_context19.prev = _context19.next) {
1141
+ return _regeneratorRuntime.wrap(function _callee20$(_context20) {
1142
+ while (1) switch (_context20.prev = _context20.next) {
1074
1143
  case 0:
1075
1144
  client = _this2.props.client;
1076
1145
  drivePermissionCollection = client.collection('io.cozy.permissions', {
1077
1146
  driveId: document.driveId
1078
1147
  });
1079
- _context19.next = 4;
1148
+ _context20.next = 4;
1080
1149
  return Promise.all(perms.map(function (p) {
1081
1150
  return drivePermissionCollection.destroy(p);
1082
1151
  }));
1083
1152
 
1084
1153
  case 4:
1085
1154
  case "end":
1086
- return _context19.stop();
1155
+ return _context20.stop();
1087
1156
  }
1088
- }, _callee19);
1157
+ }, _callee20);
1089
1158
  }));
1090
1159
 
1091
- return function (_x34, _x35) {
1092
- return _ref23.apply(this, arguments);
1160
+ return function (_x36, _x37) {
1161
+ return _ref24.apply(this, arguments);
1093
1162
  };
1094
1163
  }());
1095
1164
 
1096
1165
  _defineProperty(_this2, "revokeSharingLink", /*#__PURE__*/function () {
1097
- var _ref24 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20(document) {
1166
+ var _ref25 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee21(document) {
1098
1167
  var perms;
1099
- return _regeneratorRuntime.wrap(function _callee20$(_context20) {
1100
- while (1) switch (_context20.prev = _context20.next) {
1168
+ return _regeneratorRuntime.wrap(function _callee21$(_context21) {
1169
+ while (1) switch (_context21.prev = _context21.next) {
1101
1170
  case 0:
1102
1171
  // Because some duplicate links have been created in the past, we must ensure
1103
1172
  // we revoke all of them
1104
1173
  perms = _getDocumentPermissions(_this2.state, document.id);
1105
1174
 
1106
1175
  if (!document.driveId) {
1107
- _context20.next = 6;
1176
+ _context21.next = 6;
1108
1177
  break;
1109
1178
  }
1110
1179
 
1111
- _context20.next = 4;
1180
+ _context21.next = 4;
1112
1181
  return _this2.revokeSharedDriveSharingLink(document, perms);
1113
1182
 
1114
1183
  case 4:
1115
- _context20.next = 8;
1184
+ _context21.next = 8;
1116
1185
  break;
1117
1186
 
1118
1187
  case 6:
1119
- _context20.next = 8;
1188
+ _context21.next = 8;
1120
1189
  return Promise.all(perms.map(function (p) {
1121
1190
  return _this2.permissionCol.destroy(p);
1122
1191
  }));
@@ -1126,13 +1195,13 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
1126
1195
 
1127
1196
  case 9:
1128
1197
  case "end":
1129
- return _context20.stop();
1198
+ return _context21.stop();
1130
1199
  }
1131
- }, _callee20);
1200
+ }, _callee21);
1132
1201
  }));
1133
1202
 
1134
- return function (_x36) {
1135
- return _ref24.apply(this, arguments);
1203
+ return function (_x38) {
1204
+ return _ref25.apply(this, arguments);
1136
1205
  };
1137
1206
  }());
1138
1207
 
@@ -1231,7 +1300,12 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
1231
1300
  refresh: _this2.fetchAllSharings,
1232
1301
  hasWriteAccess: _this2.hasWriteAccess,
1233
1302
  renameSharedDrive: _this2.renameSharedDrive,
1234
- updateSharingMemberType: _this2.updateSharingMemberType
1303
+ updateSharingMemberType: _this2.updateSharingMemberType,
1304
+ getEffectiveRecipients: function getEffectiveRecipients(docId) {
1305
+ return _getEffectiveRecipients(_this2.state, docId);
1306
+ },
1307
+ fetchEffectiveRecipients: _this2.fetchEffectiveRecipients,
1308
+ invalidateEffectiveRecipients: _this2.invalidateEffectiveRecipients
1235
1309
  };
1236
1310
  _this2.isPublic = (_props$isPublic = props.isPublic) !== null && _props$isPublic !== void 0 ? _props$isPublic : false;
1237
1311
  _this2.realtime = null;
@@ -1267,14 +1341,14 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
1267
1341
  }, {
1268
1342
  key: "fetchAllSharings",
1269
1343
  value: function () {
1270
- var _fetchAllSharings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee21() {
1344
+ var _fetchAllSharings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22() {
1271
1345
  var _this$props, doctype, client, _yield$Promise$all, _yield$Promise$all2, sharings, permissions, sharedDocIds, resp, folderPaths, filePaths;
1272
1346
 
1273
- return _regeneratorRuntime.wrap(function _callee21$(_context21) {
1274
- while (1) switch (_context21.prev = _context21.next) {
1347
+ return _regeneratorRuntime.wrap(function _callee22$(_context22) {
1348
+ while (1) switch (_context22.prev = _context22.next) {
1275
1349
  case 0:
1276
1350
  if (!this.isPublic) {
1277
- _context21.next = 4;
1351
+ _context22.next = 4;
1278
1352
  break;
1279
1353
  }
1280
1354
 
@@ -1283,17 +1357,17 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
1283
1357
  this.setState({
1284
1358
  allLoaded: true
1285
1359
  });
1286
- return _context21.abrupt("return");
1360
+ return _context22.abrupt("return");
1287
1361
 
1288
1362
  case 4:
1289
1363
  _this$props = this.props, doctype = _this$props.doctype, client = _this$props.client;
1290
- _context21.next = 7;
1364
+ _context22.next = 7;
1291
1365
  return Promise.all([this.sharingCol.findByDoctype(doctype, {
1292
1366
  withSharedDocs: false
1293
1367
  }), this.permissionCol.findLinksByDoctype(doctype)]);
1294
1368
 
1295
1369
  case 7:
1296
- _yield$Promise$all = _context21.sent;
1370
+ _yield$Promise$all = _context22.sent;
1297
1371
  _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
1298
1372
  sharings = _yield$Promise$all2[0];
1299
1373
  permissions = _yield$Promise$all2[1];
@@ -1305,35 +1379,35 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
1305
1379
  this.setState({
1306
1380
  hasLoadedAtLeastOnePage: true
1307
1381
  });
1308
- _context21.next = 15;
1382
+ _context22.next = 15;
1309
1383
  return fetchNextPermissions(permissions, this.dispatch, this.permissionCol);
1310
1384
 
1311
1385
  case 15:
1312
1386
  if (!(doctype === 'io.cozy.files')) {
1313
- _context21.next = 25;
1387
+ _context22.next = 25;
1314
1388
  break;
1315
1389
  }
1316
1390
 
1317
1391
  sharedDocIds = getSharedDocIdsBySharings(sharings);
1318
- _context21.next = 19;
1392
+ _context22.next = 19;
1319
1393
  return client.collection(doctype).all({
1320
1394
  keys: sharedDocIds
1321
1395
  });
1322
1396
 
1323
1397
  case 19:
1324
- resp = _context21.sent;
1398
+ resp = _context22.sent;
1325
1399
  folderPaths = resp.data.filter(function (f) {
1326
1400
  return f.type === 'directory' && !f.trashed;
1327
1401
  }).map(function (f) {
1328
1402
  return f.path;
1329
1403
  });
1330
- _context21.next = 23;
1404
+ _context22.next = 23;
1331
1405
  return fetchFilesPaths(client, doctype, resp.data.filter(function (f) {
1332
1406
  return f.type !== 'directory' && !f.trashed;
1333
1407
  }));
1334
1408
 
1335
1409
  case 23:
1336
- filePaths = _context21.sent;
1410
+ filePaths = _context22.sent;
1337
1411
  this.dispatch(receivePaths([].concat(_toConsumableArray(folderPaths), _toConsumableArray(filePaths))));
1338
1412
 
1339
1413
  case 25:
@@ -1343,9 +1417,9 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
1343
1417
 
1344
1418
  case 26:
1345
1419
  case "end":
1346
- return _context21.stop();
1420
+ return _context22.stop();
1347
1421
  }
1348
- }, _callee21, this);
1422
+ }, _callee22, this);
1349
1423
  }));
1350
1424
 
1351
1425
  function fetchAllSharings() {