cozy-sharing 8.3.0 → 9.0.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,33 @@
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
+ ## [9.0.1](https://github.com/cozy/cozy-libs/compare/cozy-sharing@9.0.0...cozy-sharing@9.0.1) (2023-09-06)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Index only existing document after a realtime update ([f678ef7](https://github.com/cozy/cozy-libs/commit/f678ef71f658583b7c10bf0db853b550e24f15d9))
12
+
13
+
14
+
15
+
16
+
17
+ # 9.0.0 (2023-08-23)
18
+
19
+
20
+ ### Features
21
+
22
+ * **harvest:** Update cozy-client from `38.6.0` to `40.2.0` ([8931b15](https://github.com/cozy/cozy-libs/commit/8931b15ba7b097bf829601d6042d5e522b7f2fd6))
23
+
24
+
25
+ ### BREAKING CHANGES
26
+
27
+ * **harvest:** you must have `cozy-client >= 40.2.0`
28
+
29
+
30
+
31
+
32
+
6
33
  # [8.3.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@8.2.0...cozy-sharing@8.3.0) (2023-07-28)
7
34
 
8
35
 
@@ -26,7 +26,7 @@ import { fetchFilesPaths } from './helpers/files';
26
26
  import { getSharingObject, createSharingInStore, updateSharingInStore } from './helpers/sharings';
27
27
  import { SynchronousJobQueue } from './helpers/synchronousJobQueue';
28
28
  import { fetchApps } from './queries/queries';
29
- import reducer, { receiveSharings, addSharing, updateSharing, addSharingLink, updateSharingLink, revokeSharingLink, revokeRecipient, revokeSelf, receivePaths, isOwner as _isOwner, canReshare as _canReshare, getOwner as _getOwner, getRecipients as _getRecipients, getSharingById, getSharingDocIds, getSharingForSelf as _getSharingForSelf, getSharingType as _getSharingType, getSharingLink as _getSharingLink, getSharedDocIdsBySharings, getDocumentSharing, getDocumentPermissions as _getDocumentPermissions, hasSharedParent as _hasSharedParent, hasSharedChild as _hasSharedChild, getSharedParentPath as _getSharedParentPath } from './state';
29
+ import reducer, { receiveSharings, addSharing, updateSharing, addSharingLink, updateSharingLink, revokeSharingLink, revokeRecipient, revokeSelf, receivePaths, isOwner as _isOwner, canReshare as _canReshare, getOwner as _getOwner, getRecipients as _getRecipients, getSharingById, getExternalSharingIds, getSharingForSelf as _getSharingForSelf, getSharingType as _getSharingType, getSharingLink as _getSharingLink, getSharedDocIdsBySharings, getDocumentSharing, getDocumentPermissions as _getDocumentPermissions, hasSharedParent as _hasSharedParent, hasSharedChild as _hasSharedChild, getSharedParentPath as _getSharedParentPath } from './state';
30
30
  var SHARING_DOCTYPE = 'io.cozy.sharings';
31
31
  var PERMISSION_DOCTYPE = 'io.cozy.permissions';
32
32
  export var SharingProvider = /*#__PURE__*/function (_Component) {
@@ -81,7 +81,7 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
81
81
  if (internalSharing) {
82
82
  updateSharingInStore(_this.dispatch, newSharing);
83
83
  } else {
84
- docsId = getSharingDocIds(newSharing);
84
+ docsId = getExternalSharingIds(newSharing, client.getStackClient().uri);
85
85
 
86
86
  _this.synchronousJobQueue.push({
87
87
  function: createSharingInStore,
@@ -3,6 +3,7 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
3
  import { Q } from 'cozy-client';
4
4
  import { fetchFilesPaths } from './files';
5
5
  import { updateInternalObjectFromRealtime, normalizeDocFromRealtime } from './realtime';
6
+ import logger from '../logger';
6
7
  import { addSharing, updateSharing } from '../state';
7
8
  export var getSharingObject = function getSharingObject(internalSharing, sharing) {
8
9
  if (internalSharing) {
@@ -25,56 +26,65 @@ export var createSharingInStore = /*#__PURE__*/function () {
25
26
  return _regeneratorRuntime.wrap(function _callee$(_context) {
26
27
  while (1) switch (_context.prev = _context.next) {
27
28
  case 0:
29
+ _context.prev = 0;
30
+
28
31
  if (!(doctype === 'io.cozy.files')) {
29
- _context.next = 6;
32
+ _context.next = 7;
30
33
  break;
31
34
  }
32
35
 
33
- _context.next = 3;
36
+ _context.next = 4;
34
37
  return client.query(Q(doctype).getById(id));
35
38
 
36
- case 3:
39
+ case 4:
37
40
  _context.t0 = _context.sent;
38
- _context.next = 7;
41
+ _context.next = 8;
39
42
  break;
40
43
 
41
- case 6:
44
+ case 7:
42
45
  _context.t0 = undefined;
43
46
 
44
- case 7:
47
+ case 8:
45
48
  file = _context.t0;
46
49
  _context.t1 = file;
47
50
 
48
51
  if (!_context.t1) {
49
- _context.next = 16;
52
+ _context.next = 17;
50
53
  break;
51
54
  }
52
55
 
53
56
  _context.t2 = file.data.path;
54
57
 
55
58
  if (_context.t2) {
56
- _context.next = 15;
59
+ _context.next = 16;
57
60
  break;
58
61
  }
59
62
 
60
- _context.next = 14;
63
+ _context.next = 15;
61
64
  return fetchFilesPaths(client, doctype, [file.data]);
62
65
 
63
- case 14:
66
+ case 15:
64
67
  _context.t2 = _context.sent;
65
68
 
66
- case 15:
69
+ case 16:
67
70
  _context.t1 = _context.t2;
68
71
 
69
- case 16:
72
+ case 17:
70
73
  path = _context.t1;
71
74
  dispatch(addSharing(sharing, path));
75
+ _context.next = 24;
76
+ break;
77
+
78
+ case 21:
79
+ _context.prev = 21;
80
+ _context.t3 = _context["catch"](0);
81
+ logger.log(_context.t3);
72
82
 
73
- case 18:
83
+ case 24:
74
84
  case "end":
75
85
  return _context.stop();
76
86
  }
77
- }, _callee);
87
+ }, _callee, null, [[0, 21]]);
78
88
  }));
79
89
 
80
90
  return function (_x2) {
package/dist/state.js CHANGED
@@ -509,6 +509,33 @@ export var getSharingDocIds = function getSharingDocIds(sharing) {
509
509
  docs.push(sharing.attributes.shortcut_id);
510
510
  }
511
511
 
512
+ return docs;
513
+ };
514
+ /**
515
+ * Get ids of shared documents, but only if sharing is ready so files exist
516
+ * @param {object} sharing
517
+ * @param {string} instanceUri
518
+ * @returns {string[]} List of document ids of a sharing
519
+ */
520
+
521
+ export var getExternalSharingIds = function getExternalSharingIds(sharing, instanceUri) {
522
+ var member = sharing.attributes.members.find(function (member) {
523
+ return member.instance === instanceUri;
524
+ });
525
+ var docs = [];
526
+
527
+ if ((member === null || member === void 0 ? void 0 : member.status) === 'ready') {
528
+ docs = sharing.attributes.rules.map(function (r) {
529
+ return r.values;
530
+ }).reduce(function (acc, val) {
531
+ return acc.concat(val);
532
+ }, []);
533
+ }
534
+
535
+ if (sharing.attributes.shortcut_id) {
536
+ docs.push(sharing.attributes.shortcut_id);
537
+ }
538
+
512
539
  return docs;
513
540
  }; // Some permissions can not have values since they can
514
541
  // be on a global doctype. In that case, we can't sort
@@ -4,7 +4,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
4
4
 
5
5
  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; }
6
6
 
7
- import reducer, { receiveSharings, addSharing, addSharingLink, updateSharingLink, revokeSharingLink, getRecipients, revokeRecipient, revokeSelf, matchingInstanceName, getSharingLink, hasSharedParent, hasSharedChild, getSharedDocIdsBySharings, getSharingType, getPermissionDocIds, getDocumentSharingType, getSharedParentPath } from './state';
7
+ import reducer, { receiveSharings, addSharing, addSharingLink, updateSharingLink, revokeSharingLink, getRecipients, revokeRecipient, revokeSelf, matchingInstanceName, getSharingLink, hasSharedParent, hasSharedChild, getSharedDocIdsBySharings, getSharingType, getPermissionDocIds, getDocumentSharingType, getSharedParentPath, getExternalSharingIds } from './state';
8
8
  import { SHARING_1, SHARING_2, SHARING_3, SHARING_READ_ONLY, PERM_1, PERM_2, PERM_WITHOUT_DOC, SHARING_NO_ACTIVE, SHARING_WITH_SHORTCUT, APPS } from '../__tests__/fixtures';
9
9
  describe('Sharing state', function () {
10
10
  it('should have a default state', function () {
@@ -475,4 +475,55 @@ describe('getSharedParentPath', function () {
475
475
  expect(getSharedParentPath(state, '/folder-2/sub-folder-2/file-2')).toBe('/folder-2');
476
476
  expect(getSharedParentPath(state, '/folder-3/sub-folder-4/sub-folder-5/file-4')).toBe('/folder-3/sub-folder-4');
477
477
  });
478
+ });
479
+ /* eslint-disable jest/no-focused-tests */
480
+
481
+ fdescribe('getExternalSharingIds', function () {
482
+ var getAttributes = function getAttributes() {
483
+ var memberStatus = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'mail-not-sent';
484
+ return {
485
+ rules: [{
486
+ title: 'Photos',
487
+ doctype: 'io.cozy.files',
488
+ values: ['5f8c1090afad686a8f7f56cce07e8098'],
489
+ add: 'sync',
490
+ update: 'sync',
491
+ remove: 'sync'
492
+ }],
493
+ members: [{
494
+ status: 'owner',
495
+ name: 'Jane Doe',
496
+ email: 'jane@doe.com',
497
+ instance: 'http://cozy.tools:8080'
498
+ }, {
499
+ status: memberStatus,
500
+ name: 'John Doe',
501
+ email: 'john@doe.com',
502
+ instance: 'http://cozy.local:8080'
503
+ }]
504
+ };
505
+ };
506
+
507
+ it('should add shorcut ', function () {
508
+ var res = getExternalSharingIds({
509
+ attributes: _objectSpread({}, getAttributes('ready'))
510
+ }, 'http://cozy.local:8080');
511
+ expect(res).toStrictEqual(['5f8c1090afad686a8f7f56cce07e8098']);
512
+ });
513
+ it('should get only shorcut if share is not ready', function () {
514
+ var res = getExternalSharingIds({
515
+ attributes: _objectSpread(_objectSpread({}, getAttributes()), {}, {
516
+ shortcut_id: 'c63de58b2c898e457fbdfdc11a24a986'
517
+ })
518
+ }, 'http://cozy.local:8080');
519
+ expect(res).toStrictEqual(['c63de58b2c898e457fbdfdc11a24a986']);
520
+ });
521
+ it('should add shorcut ', function () {
522
+ var res = getExternalSharingIds({
523
+ attributes: _objectSpread(_objectSpread({}, getAttributes('ready')), {}, {
524
+ shortcut_id: 'c63de58b2c898e457fbdfdc11a24a986'
525
+ })
526
+ }, 'http://cozy.local:8080');
527
+ expect(res).toStrictEqual(['5f8c1090afad686a8f7f56cce07e8098', 'c63de58b2c898e457fbdfdc11a24a986']);
528
+ });
478
529
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-sharing",
3
- "version": "8.3.0",
3
+ "version": "9.0.1",
4
4
  "description": "Provides sharing login for React applications.",
5
5
  "main": "dist/index.js",
6
6
  "author": "Cozy",
@@ -28,7 +28,7 @@
28
28
  "@cozy/minilog": "^1.0.0",
29
29
  "classnames": "^2.2.6",
30
30
  "copy-text-to-clipboard": "^2.1.1",
31
- "cozy-device-helper": "^2.7.0",
31
+ "cozy-device-helper": "^3.0.0",
32
32
  "cozy-doctypes": "^1.88.6",
33
33
  "lodash": "^4.17.19",
34
34
  "react-autosuggest": "^10.1.0",
@@ -61,5 +61,5 @@
61
61
  "sideEffects": [
62
62
  "*.css"
63
63
  ],
64
- "gitHead": "fba088d68ddda8b91503ef5ca74e2f7c074b83b7"
64
+ "gitHead": "c867582697ab9df1de763b142cb969d9f1505127"
65
65
  }
@@ -27,7 +27,7 @@ import reducer, {
27
27
  getOwner,
28
28
  getRecipients,
29
29
  getSharingById,
30
- getSharingDocIds,
30
+ getExternalSharingIds,
31
31
  getSharingForSelf,
32
32
  getSharingType,
33
33
  getSharingLink,
@@ -155,7 +155,10 @@ export class SharingProvider extends Component {
155
155
  if (internalSharing) {
156
156
  updateSharingInStore(this.dispatch, newSharing)
157
157
  } else {
158
- const docsId = getSharingDocIds(newSharing)
158
+ const docsId = getExternalSharingIds(
159
+ newSharing,
160
+ client.getStackClient().uri
161
+ )
159
162
  this.synchronousJobQueue.push({
160
163
  function: createSharingInStore,
161
164
  arguments: {
@@ -5,6 +5,7 @@ import {
5
5
  updateInternalObjectFromRealtime,
6
6
  normalizeDocFromRealtime
7
7
  } from './realtime'
8
+ import logger from '../logger'
8
9
  import { addSharing, updateSharing } from '../state'
9
10
 
10
11
  export const getSharingObject = (internalSharing, sharing) => {
@@ -25,17 +26,21 @@ export const createSharingInStore = async ({
25
26
  // TODO Check if we can getByIds to avoid query in map
26
27
  await Promise.all(
27
28
  docsId.map(async id => {
28
- const file =
29
- doctype === 'io.cozy.files'
30
- ? await client.query(Q(doctype).getById(id))
31
- : undefined
29
+ try {
30
+ const file =
31
+ doctype === 'io.cozy.files'
32
+ ? await client.query(Q(doctype).getById(id))
33
+ : undefined
32
34
 
33
- const path =
34
- file &&
35
- (file.data.path ||
36
- (await fetchFilesPaths(client, doctype, [file.data])))
35
+ const path =
36
+ file &&
37
+ (file.data.path ||
38
+ (await fetchFilesPaths(client, doctype, [file.data])))
37
39
 
38
- dispatch(addSharing(sharing, path))
40
+ dispatch(addSharing(sharing, path))
41
+ } catch (e) {
42
+ logger.log(e)
43
+ }
39
44
  })
40
45
  )
41
46
  }
package/src/state.js CHANGED
@@ -395,6 +395,31 @@ export const getSharingDocIds = sharing => {
395
395
  return docs
396
396
  }
397
397
 
398
+ /**
399
+ * Get ids of shared documents, but only if sharing is ready so files exist
400
+ * @param {object} sharing
401
+ * @param {string} instanceUri
402
+ * @returns {string[]} List of document ids of a sharing
403
+ */
404
+ export const getExternalSharingIds = (sharing, instanceUri) => {
405
+ const member = sharing.attributes.members.find(
406
+ member => member.instance === instanceUri
407
+ )
408
+
409
+ let docs = []
410
+ if (member?.status === 'ready') {
411
+ docs = sharing.attributes.rules
412
+ .map(r => r.values)
413
+ .reduce((acc, val) => acc.concat(val), [])
414
+ }
415
+
416
+ if (sharing.attributes.shortcut_id) {
417
+ docs.push(sharing.attributes.shortcut_id)
418
+ }
419
+
420
+ return docs
421
+ }
422
+
398
423
  // Some permissions can not have values since they can
399
424
  // be on a global doctype. In that case, we can't sort
400
425
  // them by id
package/src/state.spec.js CHANGED
@@ -15,7 +15,8 @@ import reducer, {
15
15
  getSharingType,
16
16
  getPermissionDocIds,
17
17
  getDocumentSharingType,
18
- getSharedParentPath
18
+ getSharedParentPath,
19
+ getExternalSharingIds
19
20
  } from './state'
20
21
  import {
21
22
  SHARING_1,
@@ -643,3 +644,74 @@ describe('getSharedParentPath', () => {
643
644
  ).toBe('/folder-3/sub-folder-4')
644
645
  })
645
646
  })
647
+
648
+ /* eslint-disable jest/no-focused-tests */
649
+ fdescribe('getExternalSharingIds', () => {
650
+ const getAttributes = (memberStatus = 'mail-not-sent') => ({
651
+ rules: [
652
+ {
653
+ title: 'Photos',
654
+ doctype: 'io.cozy.files',
655
+ values: ['5f8c1090afad686a8f7f56cce07e8098'],
656
+ add: 'sync',
657
+ update: 'sync',
658
+ remove: 'sync'
659
+ }
660
+ ],
661
+ members: [
662
+ {
663
+ status: 'owner',
664
+ name: 'Jane Doe',
665
+ email: 'jane@doe.com',
666
+ instance: 'http://cozy.tools:8080'
667
+ },
668
+ {
669
+ status: memberStatus,
670
+ name: 'John Doe',
671
+ email: 'john@doe.com',
672
+ instance: 'http://cozy.local:8080'
673
+ }
674
+ ]
675
+ })
676
+
677
+ it('should add shorcut ', () => {
678
+ const res = getExternalSharingIds(
679
+ {
680
+ attributes: {
681
+ ...getAttributes('ready')
682
+ }
683
+ },
684
+ 'http://cozy.local:8080'
685
+ )
686
+ expect(res).toStrictEqual(['5f8c1090afad686a8f7f56cce07e8098'])
687
+ })
688
+
689
+ it('should get only shorcut if share is not ready', () => {
690
+ const res = getExternalSharingIds(
691
+ {
692
+ attributes: {
693
+ ...getAttributes(),
694
+ shortcut_id: 'c63de58b2c898e457fbdfdc11a24a986'
695
+ }
696
+ },
697
+ 'http://cozy.local:8080'
698
+ )
699
+ expect(res).toStrictEqual(['c63de58b2c898e457fbdfdc11a24a986'])
700
+ })
701
+
702
+ it('should add shorcut ', () => {
703
+ const res = getExternalSharingIds(
704
+ {
705
+ attributes: {
706
+ ...getAttributes('ready'),
707
+ shortcut_id: 'c63de58b2c898e457fbdfdc11a24a986'
708
+ }
709
+ },
710
+ 'http://cozy.local:8080'
711
+ )
712
+ expect(res).toStrictEqual([
713
+ '5f8c1090afad686a8f7f56cce07e8098',
714
+ 'c63de58b2c898e457fbdfdc11a24a986'
715
+ ])
716
+ })
717
+ })