cozy-sharing 33.3.4 → 33.4.1

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.
@@ -2,8 +2,9 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
4
  import PropTypes from 'prop-types';
5
- import React, { useCallback, useState } from 'react';
5
+ import React, { useCallback, useEffect, useState } from 'react';
6
6
  import { useClient } from 'cozy-client';
7
+ import minilog from 'cozy-minilog';
7
8
  import Button from 'cozy-ui/transpiled/react/Buttons';
8
9
  import { FixedDialog } from 'cozy-ui/transpiled/react/CozyDialogs';
9
10
  import Typography from 'cozy-ui/transpiled/react/Typography';
@@ -39,6 +40,7 @@ import AntivirusAlert from '../AntivirusAlert';
39
40
  import { default as DumbShareByEmail } from '../ShareByEmail';
40
41
  import ShareByLink from '../ShareByLink';
41
42
  import WhoHasAccess from '../WhoHasAccess';
43
+ var log = minilog('FederatedFolderModal');
42
44
 
43
45
  var FederatedFolderModalContent = function FederatedFolderModalContent(_ref) {
44
46
  var _sharedDriveSharing$a;
@@ -57,6 +59,8 @@ var FederatedFolderModalContent = function FederatedFolderModalContent(_ref) {
57
59
  getSharingById = _useSharingContext.getSharingById,
58
60
  getSharingLink = _useSharingContext.getSharingLink,
59
61
  getFederatedShareLink = _useSharingContext.getFederatedShareLink,
62
+ getDocumentPermissions = _useSharingContext.getDocumentPermissions,
63
+ fetchSharedDriveSharingLinks = _useSharingContext.fetchSharedDriveSharingLinks,
60
64
  getRecipients = _useSharingContext.getRecipients,
61
65
  hasSharedChild = _useSharingContext.hasSharedChild,
62
66
  hasSharedParent = _useSharingContext.hasSharedParent,
@@ -86,15 +90,25 @@ var FederatedFolderModalContent = function FederatedFolderModalContent(_ref) {
86
90
  isSending = _useState2[0],
87
91
  setIsSending = _useState2[1];
88
92
 
89
- var _useState3 = useState(null),
93
+ var _useState3 = useState(false),
90
94
  _useState4 = _slicedToArray(_useState3, 2),
91
- frozenDoc = _useState4[0],
92
- setFrozenDoc = _useState4[1];
95
+ isFetchingSharingLinks = _useState4[0],
96
+ setIsFetchingSharingLinks = _useState4[1];
93
97
 
94
98
  var _useState5 = useState(null),
95
99
  _useState6 = _slicedToArray(_useState5, 2),
96
- frozenRecipients = _useState6[0],
97
- setFrozenRecipients = _useState6[1];
100
+ fetchedSharingLinksDocumentId = _useState6[0],
101
+ setFetchedSharingLinksDocumentId = _useState6[1];
102
+
103
+ var _useState7 = useState(null),
104
+ _useState8 = _slicedToArray(_useState7, 2),
105
+ frozenDoc = _useState8[0],
106
+ setFrozenDoc = _useState8[1];
107
+
108
+ var _useState9 = useState(null),
109
+ _useState10 = _slicedToArray(_useState9, 2),
110
+ frozenRecipients = _useState10[0],
111
+ setFrozenRecipients = _useState10[1];
98
112
 
99
113
  var handleCloseRequest = useCallback(function () {
100
114
  if (pendingRecipients.length === 0) {
@@ -209,8 +223,57 @@ var FederatedFolderModalContent = function FederatedFolderModalContent(_ref) {
209
223
  };
210
224
  }();
211
225
 
212
- var existingRecipients = existingDocument ? getRecipients(existingDocument._id) : [];
226
+ var documentId = (existingDocument === null || existingDocument === void 0 ? void 0 : existingDocument._id) || (existingDocument === null || existingDocument === void 0 ? void 0 : existingDocument.id);
227
+ var existingRecipients = documentId ? getRecipients(documentId) : [];
228
+ var documentPermissions = documentId ? getDocumentPermissions(documentId) : [];
213
229
  var displayedLink = existingDocument !== null && existingDocument !== void 0 && existingDocument.driveId ? getFederatedShareLink(existingDocument) : getSharingLink(existingDocument === null || existingDocument === void 0 ? void 0 : existingDocument._id);
230
+ useEffect(function () {
231
+ if (!(existingDocument !== null && existingDocument !== void 0 && existingDocument.driveId)) return;
232
+ if (!documentId) return;
233
+ if (!fetchSharedDriveSharingLinks) return;
234
+ if (documentPermissions.length > 0) return;
235
+ if (isFetchingSharingLinks) return;
236
+ if (fetchedSharingLinksDocumentId === documentId) return;
237
+
238
+ var fetchSharingLinks = /*#__PURE__*/function () {
239
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
240
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
241
+ while (1) switch (_context2.prev = _context2.next) {
242
+ case 0:
243
+ setIsFetchingSharingLinks(true);
244
+ _context2.prev = 1;
245
+ _context2.next = 4;
246
+ return fetchSharedDriveSharingLinks(existingDocument);
247
+
248
+ case 4:
249
+ _context2.next = 9;
250
+ break;
251
+
252
+ case 6:
253
+ _context2.prev = 6;
254
+ _context2.t0 = _context2["catch"](1);
255
+ log.error('Failed to fetch shared drive sharing links', _context2.t0);
256
+
257
+ case 9:
258
+ _context2.prev = 9;
259
+ setFetchedSharingLinksDocumentId(documentId);
260
+ setIsFetchingSharingLinks(false);
261
+ return _context2.finish(9);
262
+
263
+ case 13:
264
+ case "end":
265
+ return _context2.stop();
266
+ }
267
+ }, _callee2, null, [[1, 6, 9, 13]]);
268
+ }));
269
+
270
+ return function fetchSharingLinks() {
271
+ return _ref3.apply(this, arguments);
272
+ };
273
+ }();
274
+
275
+ fetchSharingLinks();
276
+ }, [documentId, existingDocument, documentPermissions.length, fetchedSharingLinksDocumentId, fetchSharedDriveSharingLinks, isFetchingSharingLinks]);
214
277
  var modalTitle = t('FederatedFolder.shareTitle', {
215
278
  name: folderName
216
279
  });
@@ -23,6 +23,8 @@ var mockGetRecipients = jest.fn().mockReturnValue([]);
23
23
  var mockGetSharingById = jest.fn();
24
24
  var mockHasSharedChild = jest.fn();
25
25
  var mockHasSharedParent = jest.fn();
26
+ var mockFetchSharedDriveSharingLinks = jest.fn();
27
+ var mockGetDocumentPermissions = jest.fn().mockReturnValue([]);
26
28
  var mockShowAlert = jest.fn();
27
29
  var mockOnClose = jest.fn();
28
30
  jest.mock('../../hooks/useSharingContext', function () {
@@ -34,7 +36,8 @@ jest.mock('../../hooks/useSharingContext', function () {
34
36
  revoke: mockRevoke,
35
37
  getSharingLink: mockGetSharingLink,
36
38
  getFederatedShareLink: mockGetFederatedShareLink,
37
- getDocumentPermissions: jest.fn().mockReturnValue([]),
39
+ getDocumentPermissions: mockGetDocumentPermissions,
40
+ fetchSharedDriveSharingLinks: mockFetchSharedDriveSharingLinks,
38
41
  getOwner: jest.fn(),
39
42
  getRecipients: mockGetRecipients,
40
43
  getSharingById: mockGetSharingById,
@@ -85,7 +88,8 @@ var createSharingContextValue = function createSharingContextValue() {
85
88
  hasWriteAccess: jest.fn(),
86
89
  getRecipients: jest.fn(),
87
90
  getSharingLink: mockGetSharingLink,
88
- getDocumentPermissions: jest.fn().mockReturnValue([]),
91
+ getDocumentPermissions: mockGetDocumentPermissions,
92
+ fetchSharedDriveSharingLinks: mockFetchSharedDriveSharingLinks,
89
93
  share: mockShare
90
94
  };
91
95
  };
@@ -118,6 +122,8 @@ describe('FederatedFolderModal', function () {
118
122
  var sharingContextValue;
119
123
  beforeEach(function () {
120
124
  jest.clearAllMocks();
125
+ mockGetDocumentPermissions.mockReturnValue([]);
126
+ mockFetchSharedDriveSharingLinks.mockResolvedValue([]);
121
127
  mockGetSharingLink.mockReturnValue('https://example.com/share/abc123');
122
128
  mockGetFederatedShareLink.mockReturnValue('https://example.com/share/federated-abc123');
123
129
  mockGetRecipients.mockReturnValue([]);
@@ -326,26 +332,169 @@ describe('FederatedFolderModal', function () {
326
332
  }, _callee7);
327
333
  })));
328
334
  });
335
+ describe('shared drive link fetch on mount', function () {
336
+ it('should fetch shared drive sharing links when document has a driveId and no permissions yet', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
337
+ return _regeneratorRuntime.wrap(function _callee8$(_context8) {
338
+ while (1) switch (_context8.prev = _context8.next) {
339
+ case 0:
340
+ mockGetDocumentPermissions.mockReturnValue([]);
341
+ setup({
342
+ document: _objectSpread(_objectSpread({}, mockDocument), {}, {
343
+ driveId: 'federated-folder-id'
344
+ })
345
+ });
346
+ _context8.next = 4;
347
+ return waitFor(function () {
348
+ expect(mockFetchSharedDriveSharingLinks).toHaveBeenCalledTimes(1);
349
+ });
350
+
351
+ case 4:
352
+ expect(mockFetchSharedDriveSharingLinks).toHaveBeenCalledWith(expect.objectContaining({
353
+ _id: mockDocument._id,
354
+ driveId: 'federated-folder-id'
355
+ }));
356
+
357
+ case 5:
358
+ case "end":
359
+ return _context8.stop();
360
+ }
361
+ }, _callee8);
362
+ })));
363
+ it('should use document.id when _id is missing', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
364
+ var document;
365
+ return _regeneratorRuntime.wrap(function _callee9$(_context9) {
366
+ while (1) switch (_context9.prev = _context9.next) {
367
+ case 0:
368
+ document = {
369
+ id: 'folder-id-only',
370
+ name: 'My Test Folder',
371
+ path: '/test/folder',
372
+ driveId: 'federated-folder-id'
373
+ };
374
+ setup({
375
+ document: document
376
+ });
377
+ _context9.next = 4;
378
+ return waitFor(function () {
379
+ expect(mockFetchSharedDriveSharingLinks).toHaveBeenCalledWith(document);
380
+ });
381
+
382
+ case 4:
383
+ expect(mockGetDocumentPermissions).toHaveBeenCalledWith('folder-id-only');
384
+
385
+ case 5:
386
+ case "end":
387
+ return _context9.stop();
388
+ }
389
+ }, _callee9);
390
+ })));
391
+ it('should not fetch shared drive sharing links when document has no driveId', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
392
+ var _setup8, findByText;
393
+
394
+ return _regeneratorRuntime.wrap(function _callee10$(_context10) {
395
+ while (1) switch (_context10.prev = _context10.next) {
396
+ case 0:
397
+ _setup8 = setup({
398
+ document: mockDocument
399
+ }), findByText = _setup8.findByText;
400
+ _context10.next = 3;
401
+ return findByText('Copy link');
402
+
403
+ case 3:
404
+ expect(mockFetchSharedDriveSharingLinks).not.toHaveBeenCalled();
405
+
406
+ case 4:
407
+ case "end":
408
+ return _context10.stop();
409
+ }
410
+ }, _callee10);
411
+ })));
412
+ it('should not refetch after one attempt when permissions stay empty', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11() {
413
+ var document, _setup9, rerender;
414
+
415
+ return _regeneratorRuntime.wrap(function _callee11$(_context11) {
416
+ while (1) switch (_context11.prev = _context11.next) {
417
+ case 0:
418
+ document = _objectSpread(_objectSpread({}, mockDocument), {}, {
419
+ driveId: 'federated-folder-id'
420
+ });
421
+ _setup9 = setup({
422
+ document: document
423
+ }), rerender = _setup9.rerender;
424
+ _context11.next = 4;
425
+ return waitFor(function () {
426
+ expect(mockFetchSharedDriveSharingLinks).toHaveBeenCalledTimes(1);
427
+ });
428
+
429
+ case 4:
430
+ rerender( /*#__PURE__*/React.createElement(AppLike, {
431
+ client: client,
432
+ sharingContextValue: sharingContextValue
433
+ }, /*#__PURE__*/React.createElement(FederatedFolderModal, {
434
+ document: document,
435
+ onClose: mockOnClose
436
+ })));
437
+ expect(mockFetchSharedDriveSharingLinks).toHaveBeenCalledTimes(1);
438
+
439
+ case 6:
440
+ case "end":
441
+ return _context11.stop();
442
+ }
443
+ }, _callee11);
444
+ })));
445
+ it('should not fetch shared drive sharing links when permissions are already loaded', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12() {
446
+ var _setup10, findByText;
447
+
448
+ return _regeneratorRuntime.wrap(function _callee12$(_context12) {
449
+ while (1) switch (_context12.prev = _context12.next) {
450
+ case 0:
451
+ mockGetDocumentPermissions.mockReturnValue([{
452
+ id: 'perm-1',
453
+ type: 'io.cozy.permissions',
454
+ attributes: {
455
+ shortcodes: {
456
+ code: 'abc'
457
+ }
458
+ }
459
+ }]);
460
+ _setup10 = setup({
461
+ document: _objectSpread(_objectSpread({}, mockDocument), {}, {
462
+ driveId: 'federated-folder-id'
463
+ })
464
+ }), findByText = _setup10.findByText;
465
+ _context12.next = 4;
466
+ return findByText('Copy link');
467
+
468
+ case 4:
469
+ expect(mockFetchSharedDriveSharingLinks).not.toHaveBeenCalled();
470
+
471
+ case 5:
472
+ case "end":
473
+ return _context12.stop();
474
+ }
475
+ }, _callee12);
476
+ })));
477
+ });
329
478
  describe('onSend callback', function () {
330
479
  var pendingRecipient = {
331
480
  name: 'Alice',
332
481
  email: 'alice@example.com'
333
482
  };
334
- it('should call onClose and skip share when there are no pending recipients', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
335
- var _setup8, findByText, sendButton;
483
+ it('should call onClose and skip share when there are no pending recipients', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13() {
484
+ var _setup11, findByText, sendButton;
336
485
 
337
- return _regeneratorRuntime.wrap(function _callee8$(_context8) {
338
- while (1) switch (_context8.prev = _context8.next) {
486
+ return _regeneratorRuntime.wrap(function _callee13$(_context13) {
487
+ while (1) switch (_context13.prev = _context13.next) {
339
488
  case 0:
340
489
  // pendingRecipients defaults to [] via beforeEach
341
- _setup8 = setup(), findByText = _setup8.findByText;
342
- _context8.next = 3;
490
+ _setup11 = setup(), findByText = _setup11.findByText;
491
+ _context13.next = 3;
343
492
  return findByText('Done');
344
493
 
345
494
  case 3:
346
- sendButton = _context8.sent;
495
+ sendButton = _context13.sent;
347
496
  fireEvent.click(sendButton);
348
- _context8.next = 7;
497
+ _context13.next = 7;
349
498
  return waitFor(function () {
350
499
  expect(mockOnClose).toHaveBeenCalled();
351
500
  expect(mockShare).not.toHaveBeenCalled();
@@ -353,15 +502,15 @@ describe('FederatedFolderModal', function () {
353
502
 
354
503
  case 7:
355
504
  case "end":
356
- return _context8.stop();
505
+ return _context13.stop();
357
506
  }
358
- }, _callee8);
507
+ }, _callee13);
359
508
  })));
360
- it('should call share with correct parameters', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
361
- var _setup9, findByText, sendButton;
509
+ it('should call share with correct parameters', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14() {
510
+ var _setup12, findByText, sendButton;
362
511
 
363
- return _regeneratorRuntime.wrap(function _callee9$(_context9) {
364
- while (1) switch (_context9.prev = _context9.next) {
512
+ return _regeneratorRuntime.wrap(function _callee14$(_context14) {
513
+ while (1) switch (_context14.prev = _context14.next) {
365
514
  case 0:
366
515
  usePendingRecipients.mockReturnValue({
367
516
  pendingRecipients: [pendingRecipient],
@@ -371,14 +520,14 @@ describe('FederatedFolderModal', function () {
371
520
  });
372
521
  getOrCreateFromArray.mockResolvedValue([pendingRecipient]);
373
522
  mockShare.mockResolvedValueOnce({});
374
- _setup9 = setup(), findByText = _setup9.findByText;
375
- _context9.next = 6;
523
+ _setup12 = setup(), findByText = _setup12.findByText;
524
+ _context14.next = 6;
376
525
  return findByText('Done');
377
526
 
378
527
  case 6:
379
- sendButton = _context9.sent;
528
+ sendButton = _context14.sent;
380
529
  fireEvent.click(sendButton);
381
- _context9.next = 10;
530
+ _context14.next = 10;
382
531
  return waitFor(function () {
383
532
  expect(mockShare).toHaveBeenCalledWith({
384
533
  description: 'My Test Folder',
@@ -392,15 +541,15 @@ describe('FederatedFolderModal', function () {
392
541
 
393
542
  case 10:
394
543
  case "end":
395
- return _context9.stop();
544
+ return _context14.stop();
396
545
  }
397
- }, _callee9);
546
+ }, _callee14);
398
547
  })));
399
- it('should show success alert and close modal on successful share', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
400
- var _setup10, findByText, sendButton;
548
+ it('should show success alert and close modal on successful share', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15() {
549
+ var _setup13, findByText, sendButton;
401
550
 
402
- return _regeneratorRuntime.wrap(function _callee10$(_context10) {
403
- while (1) switch (_context10.prev = _context10.next) {
551
+ return _regeneratorRuntime.wrap(function _callee15$(_context15) {
552
+ while (1) switch (_context15.prev = _context15.next) {
404
553
  case 0:
405
554
  usePendingRecipients.mockReturnValue({
406
555
  pendingRecipients: [pendingRecipient],
@@ -410,14 +559,14 @@ describe('FederatedFolderModal', function () {
410
559
  });
411
560
  getOrCreateFromArray.mockResolvedValue([pendingRecipient]);
412
561
  mockShare.mockResolvedValueOnce({});
413
- _setup10 = setup(), findByText = _setup10.findByText;
414
- _context10.next = 6;
562
+ _setup13 = setup(), findByText = _setup13.findByText;
563
+ _context15.next = 6;
415
564
  return findByText('Done');
416
565
 
417
566
  case 6:
418
- sendButton = _context10.sent;
567
+ sendButton = _context15.sent;
419
568
  fireEvent.click(sendButton);
420
- _context10.next = 10;
569
+ _context15.next = 10;
421
570
  return waitFor(function () {
422
571
  expect(mockShowAlert).toHaveBeenCalledWith({
423
572
  message: 'Folder has been shared',
@@ -429,15 +578,15 @@ describe('FederatedFolderModal', function () {
429
578
 
430
579
  case 10:
431
580
  case "end":
432
- return _context10.stop();
581
+ return _context15.stop();
433
582
  }
434
- }, _callee10);
583
+ }, _callee15);
435
584
  })));
436
- it('should show error alert when share fails', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11() {
437
- var _setup11, findByText, sendButton;
585
+ it('should show error alert when share fails', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16() {
586
+ var _setup14, findByText, sendButton;
438
587
 
439
- return _regeneratorRuntime.wrap(function _callee11$(_context11) {
440
- while (1) switch (_context11.prev = _context11.next) {
588
+ return _regeneratorRuntime.wrap(function _callee16$(_context16) {
589
+ while (1) switch (_context16.prev = _context16.next) {
441
590
  case 0:
442
591
  usePendingRecipients.mockReturnValue({
443
592
  pendingRecipients: [pendingRecipient],
@@ -447,14 +596,14 @@ describe('FederatedFolderModal', function () {
447
596
  });
448
597
  getOrCreateFromArray.mockResolvedValue([pendingRecipient]);
449
598
  mockShare.mockRejectedValueOnce(new Error('Share failed'));
450
- _setup11 = setup(), findByText = _setup11.findByText;
451
- _context11.next = 6;
599
+ _setup14 = setup(), findByText = _setup14.findByText;
600
+ _context16.next = 6;
452
601
  return findByText('Done');
453
602
 
454
603
  case 6:
455
- sendButton = _context11.sent;
604
+ sendButton = _context16.sent;
456
605
  fireEvent.click(sendButton);
457
- _context11.next = 10;
606
+ _context16.next = 10;
458
607
  return waitFor(function () {
459
608
  expect(mockShowAlert).toHaveBeenCalledWith({
460
609
  message: 'Error while sharing folder',
@@ -466,15 +615,15 @@ describe('FederatedFolderModal', function () {
466
615
 
467
616
  case 10:
468
617
  case "end":
469
- return _context11.stop();
618
+ return _context16.stop();
470
619
  }
471
- }, _callee11);
620
+ }, _callee16);
472
621
  })));
473
- it('should show progress icon on Done button while share is in progress', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13() {
474
- var resolveShare, _setup12, findByText, getByRole, queryByRole, sendButton;
622
+ it('should show progress icon on Done button while share is in progress', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18() {
623
+ var resolveShare, _setup15, findByText, getByRole, queryByRole, sendButton;
475
624
 
476
- return _regeneratorRuntime.wrap(function _callee13$(_context13) {
477
- while (1) switch (_context13.prev = _context13.next) {
625
+ return _regeneratorRuntime.wrap(function _callee18$(_context18) {
626
+ while (1) switch (_context18.prev = _context18.next) {
478
627
  case 0:
479
628
  usePendingRecipients.mockReturnValue({
480
629
  pendingRecipients: [pendingRecipient],
@@ -486,14 +635,14 @@ describe('FederatedFolderModal', function () {
486
635
  mockShare.mockReturnValueOnce(new Promise(function (resolve) {
487
636
  resolveShare = resolve;
488
637
  }));
489
- _setup12 = setup(), findByText = _setup12.findByText, getByRole = _setup12.getByRole, queryByRole = _setup12.queryByRole;
490
- _context13.next = 6;
638
+ _setup15 = setup(), findByText = _setup15.findByText, getByRole = _setup15.getByRole, queryByRole = _setup15.queryByRole;
639
+ _context18.next = 6;
491
640
  return findByText('Done');
492
641
 
493
642
  case 6:
494
- sendButton = _context13.sent;
643
+ sendButton = _context18.sent;
495
644
  fireEvent.click(sendButton);
496
- _context13.next = 10;
645
+ _context18.next = 10;
497
646
  return waitFor(function () {
498
647
  expect(getByRole('button', {
499
648
  name: 'Done'
@@ -502,56 +651,56 @@ describe('FederatedFolderModal', function () {
502
651
  });
503
652
 
504
653
  case 10:
505
- _context13.next = 12;
506
- return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12() {
507
- return _regeneratorRuntime.wrap(function _callee12$(_context12) {
508
- while (1) switch (_context12.prev = _context12.next) {
654
+ _context18.next = 12;
655
+ return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17() {
656
+ return _regeneratorRuntime.wrap(function _callee17$(_context17) {
657
+ while (1) switch (_context17.prev = _context17.next) {
509
658
  case 0:
510
659
  resolveShare({});
511
660
 
512
661
  case 1:
513
662
  case "end":
514
- return _context12.stop();
663
+ return _context17.stop();
515
664
  }
516
- }, _callee12);
665
+ }, _callee17);
517
666
  })));
518
667
 
519
668
  case 12:
520
669
  case "end":
521
- return _context13.stop();
670
+ return _context18.stop();
522
671
  }
523
- }, _callee13);
672
+ }, _callee18);
524
673
  })));
525
674
  });
526
675
  describe('onClose callback', function () {
527
- it('should call onClose when close button is clicked', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14() {
528
- var _setup13, findByRole, closeButton;
676
+ it('should call onClose when close button is clicked', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19() {
677
+ var _setup16, findByRole, closeButton;
529
678
 
530
- return _regeneratorRuntime.wrap(function _callee14$(_context14) {
531
- while (1) switch (_context14.prev = _context14.next) {
679
+ return _regeneratorRuntime.wrap(function _callee19$(_context19) {
680
+ while (1) switch (_context19.prev = _context19.next) {
532
681
  case 0:
533
- _setup13 = setup(), findByRole = _setup13.findByRole;
534
- _context14.next = 3;
682
+ _setup16 = setup(), findByRole = _setup16.findByRole;
683
+ _context19.next = 3;
535
684
  return findByRole('button', {
536
685
  name: /close/i
537
686
  });
538
687
 
539
688
  case 3:
540
- closeButton = _context14.sent;
689
+ closeButton = _context19.sent;
541
690
  fireEvent.click(closeButton);
542
691
  expect(mockOnClose).toHaveBeenCalled();
543
692
 
544
693
  case 6:
545
694
  case "end":
546
- return _context14.stop();
695
+ return _context19.stop();
547
696
  }
548
- }, _callee14);
697
+ }, _callee19);
549
698
  })));
550
- it('should ask confirmation when close button is clicked with pending recipients', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15() {
551
- var _setup14, getByRole, findByRole, getByText, closeButton;
699
+ it('should ask confirmation when close button is clicked with pending recipients', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20() {
700
+ var _setup17, getByRole, findByRole, getByText, closeButton;
552
701
 
553
- return _regeneratorRuntime.wrap(function _callee15$(_context15) {
554
- while (1) switch (_context15.prev = _context15.next) {
702
+ return _regeneratorRuntime.wrap(function _callee20$(_context20) {
703
+ while (1) switch (_context20.prev = _context20.next) {
555
704
  case 0:
556
705
  usePendingRecipients.mockReturnValue({
557
706
  pendingRecipients: [{
@@ -562,14 +711,14 @@ describe('FederatedFolderModal', function () {
562
711
  selectedOption: 'readWrite',
563
712
  setSelectedOption: jest.fn()
564
713
  });
565
- _setup14 = setup(), getByRole = _setup14.getByRole, findByRole = _setup14.findByRole, getByText = _setup14.getByText;
566
- _context15.next = 4;
714
+ _setup17 = setup(), getByRole = _setup17.getByRole, findByRole = _setup17.findByRole, getByText = _setup17.getByText;
715
+ _context20.next = 4;
567
716
  return findByRole('button', {
568
717
  name: /close/i
569
718
  });
570
719
 
571
720
  case 4:
572
- closeButton = _context15.sent;
721
+ closeButton = _context20.sent;
573
722
  fireEvent.click(closeButton);
574
723
  expect(getByText("Discard the changes you haven't saved?")).toBeTruthy();
575
724
  expect(mockOnClose).not.toHaveBeenCalled();
@@ -580,15 +729,15 @@ describe('FederatedFolderModal', function () {
580
729
 
581
730
  case 10:
582
731
  case "end":
583
- return _context15.stop();
732
+ return _context20.stop();
584
733
  }
585
- }, _callee15);
734
+ }, _callee20);
586
735
  })));
587
- it('should close after discard confirmation', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16() {
588
- var _setup15, getByRole, findByRole, getByText, closeButton;
736
+ it('should close after discard confirmation', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee21() {
737
+ var _setup18, getByRole, findByRole, getByText, closeButton;
589
738
 
590
- return _regeneratorRuntime.wrap(function _callee16$(_context16) {
591
- while (1) switch (_context16.prev = _context16.next) {
739
+ return _regeneratorRuntime.wrap(function _callee21$(_context21) {
740
+ while (1) switch (_context21.prev = _context21.next) {
592
741
  case 0:
593
742
  usePendingRecipients.mockReturnValue({
594
743
  pendingRecipients: [{
@@ -599,14 +748,14 @@ describe('FederatedFolderModal', function () {
599
748
  selectedOption: 'readWrite',
600
749
  setSelectedOption: jest.fn()
601
750
  });
602
- _setup15 = setup(), getByRole = _setup15.getByRole, findByRole = _setup15.findByRole, getByText = _setup15.getByText;
603
- _context16.next = 4;
751
+ _setup18 = setup(), getByRole = _setup18.getByRole, findByRole = _setup18.findByRole, getByText = _setup18.getByText;
752
+ _context21.next = 4;
604
753
  return findByRole('button', {
605
754
  name: /close/i
606
755
  });
607
756
 
608
757
  case 4:
609
- closeButton = _context16.sent;
758
+ closeButton = _context21.sent;
610
759
  fireEvent.click(closeButton);
611
760
  expect(getByText("Discard the changes you haven't saved?")).toBeTruthy();
612
761
  fireEvent.click(getByRole('button', {
@@ -616,9 +765,9 @@ describe('FederatedFolderModal', function () {
616
765
 
617
766
  case 9:
618
767
  case "end":
619
- return _context16.stop();
768
+ return _context21.stop();
620
769
  }
621
- }, _callee16);
770
+ }, _callee21);
622
771
  })));
623
772
  });
624
773
  });
@@ -1,7 +1,13 @@
1
1
  import React from 'react';
2
2
  import { useClient, useQuery, hasQueryBeenLoaded } from 'cozy-client';
3
3
  import MemberRecipient from './MemberRecipient';
4
- import { buildInstanceSettingsQuery } from '../../queries/queries';
4
+ import { buildInstanceSettingsQuery } from '../../queries/queries'; // When the owner is not part of a sharing's members (eg. the folder only has
5
+ // a link), there is no per-sharing avatar to reference. The instance's public
6
+ // avatar still holds the owner's picture. fallback=initials makes the stack
7
+ // serve a generated initials avatar (instead of the app icon) when no picture
8
+ // has been uploaded, matching how avatars are rendered everywhere else.
9
+
10
+ var OWNER_PUBLIC_AVATAR_PATH = '/public/avatar?fallback=initials';
5
11
 
6
12
  var OwnerRecipientDefault = function OwnerRecipientDefault() {
7
13
  var _instanceSettingsResu;
@@ -13,6 +19,7 @@ var OwnerRecipientDefault = function OwnerRecipientDefault() {
13
19
  isOwner: true,
14
20
  status: "owner",
15
21
  instance: client.options.uri,
22
+ avatarPath: OWNER_PUBLIC_AVATAR_PATH,
16
23
  public_name: instanceSettingsResult === null || instanceSettingsResult === void 0 || (_instanceSettingsResu = instanceSettingsResult.data) === null || _instanceSettingsResu === void 0 || (_instanceSettingsResu = _instanceSettingsResu.attributes) === null || _instanceSettingsResu === void 0 ? void 0 : _instanceSettingsResu.public_name
17
24
  });
18
25
  };