cozy-sharing 8.0.1 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
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
+ # [8.1.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@8.0.1...cozy-sharing@8.1.0) (2023-07-25)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add a helper to get shared parent path ([1264371](https://github.com/cozy/cozy-libs/commit/1264371b6d29641e55d843c335c4b8d34a03c2d8))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [8.0.1](https://github.com/cozy/cozy-libs/compare/cozy-sharing@8.0.0...cozy-sharing@8.0.1) (2023-07-18)
7
18
 
8
19
 
@@ -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 } 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, 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';
30
30
  var SHARING_DOCTYPE = 'io.cozy.sharings';
31
31
  var PERMISSION_DOCTYPE = 'io.cozy.permissions';
32
32
  export var SharingProvider = /*#__PURE__*/function (_Component) {
@@ -529,6 +529,9 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
529
529
  getRecipients: function getRecipients(docId) {
530
530
  return _getRecipients(_this.state, docId);
531
531
  },
532
+ getSharedParentPath: function getSharedParentPath(documentPath) {
533
+ return _getSharedParentPath(_this.state, documentPath);
534
+ },
532
535
  getDocumentPermissions: function getDocumentPermissions(docId) {
533
536
  return _getDocumentPermissions(_this.state, docId);
534
537
  },
package/dist/state.js CHANGED
@@ -477,6 +477,22 @@ export var hasSharedChild = function hasSharedChild(state, documentPath) {
477
477
  return path.indexOf("".concat(documentPath, "/")) === 0;
478
478
  });
479
479
  return ret;
480
+ };
481
+ /**
482
+ * Returns the path of the shared parent for a given document
483
+ * @param {object} state - Redux state
484
+ * @param {string} documentPath - Path of the given document
485
+ * @returns {string|null} Path of the shared parent
486
+ */
487
+
488
+ export var getSharedParentPath = function getSharedParentPath(state, documentPath) {
489
+ if (hasSharedParent(state, documentPath)) {
490
+ return state.sharedPaths.find(function (path) {
491
+ return documentPath.startsWith(path);
492
+ });
493
+ }
494
+
495
+ return null;
480
496
  }; // helpers
481
497
 
482
498
  export var getSharedDocIds = function getSharedDocIds(doc) {
@@ -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 } from './state';
7
+ import reducer, { receiveSharings, addSharing, addSharingLink, updateSharingLink, revokeSharingLink, getRecipients, revokeRecipient, revokeSelf, matchingInstanceName, getSharingLink, hasSharedParent, hasSharedChild, getSharedDocIdsBySharings, getSharingType, getPermissionDocIds, getDocumentSharingType, getSharedParentPath } 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 () {
@@ -462,4 +462,17 @@ describe('getDocumentSharingType', function () {
462
462
  }
463
463
  }, 'folder_1')).toBe('one-way');
464
464
  });
465
+ });
466
+ describe('getSharedParentPath', function () {
467
+ var state = {
468
+ sharedPaths: ['/folder-1/sub-folder-1', '/folder-2', '/folder-3/sub-folder-3', '/folder-3/sub-folder-4']
469
+ };
470
+ it('should return null if no shared parent', function () {
471
+ expect(getSharedParentPath(state, '/file-1')).toBeNull();
472
+ });
473
+ it('should return shared parent path', function () {
474
+ expect(getSharedParentPath(state, '/folder-1/sub-folder-1/file-2')).toBe('/folder-1/sub-folder-1');
475
+ expect(getSharedParentPath(state, '/folder-2/sub-folder-2/file-2')).toBe('/folder-2');
476
+ expect(getSharedParentPath(state, '/folder-3/sub-folder-4/sub-folder-5/file-4')).toBe('/folder-3/sub-folder-4');
477
+ });
465
478
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-sharing",
3
- "version": "8.0.1",
3
+ "version": "8.1.0",
4
4
  "description": "Provides sharing login for React applications.",
5
5
  "main": "dist/index.js",
6
6
  "author": "Cozy",
@@ -61,5 +61,5 @@
61
61
  "sideEffects": [
62
62
  "*.css"
63
63
  ],
64
- "gitHead": "c76e5865434a3bb2051f9a28a9cb76e3e5cf1b1e"
64
+ "gitHead": "96da95e604fb54d72ce03b220cf91e112f8fb5f1"
65
65
  }
@@ -35,7 +35,8 @@ import reducer, {
35
35
  getDocumentSharing,
36
36
  getDocumentPermissions,
37
37
  hasSharedParent,
38
- hasSharedChild
38
+ hasSharedChild,
39
+ getSharedParentPath
39
40
  } from './state'
40
41
 
41
42
  const SHARING_DOCTYPE = 'io.cozy.sharings'
@@ -59,6 +60,8 @@ export class SharingProvider extends Component {
59
60
  getSharingType: docId => getSharingType(this.state, docId, instanceUri),
60
61
  getSharingForSelf: docId => getSharingForSelf(this.state, docId),
61
62
  getRecipients: docId => getRecipients(this.state, docId),
63
+ getSharedParentPath: documentPath =>
64
+ getSharedParentPath(this.state, documentPath),
62
65
  getDocumentPermissions: docId =>
63
66
  getDocumentPermissions(this.state, docId),
64
67
  getSharingLink: docId => getSharingLink(this.state, docId, documentType),
package/src/state.js CHANGED
@@ -364,6 +364,19 @@ export const hasSharedChild = (state, documentPath) => {
364
364
  return ret
365
365
  }
366
366
 
367
+ /**
368
+ * Returns the path of the shared parent for a given document
369
+ * @param {object} state - Redux state
370
+ * @param {string} documentPath - Path of the given document
371
+ * @returns {string|null} Path of the shared parent
372
+ */
373
+ export const getSharedParentPath = (state, documentPath) => {
374
+ if (hasSharedParent(state, documentPath)) {
375
+ return state.sharedPaths.find(path => documentPath.startsWith(path))
376
+ }
377
+ return null
378
+ }
379
+
367
380
  // helpers
368
381
  export const getSharedDocIds = doc =>
369
382
  doc.type === 'io.cozy.sharings'
package/src/state.spec.js CHANGED
@@ -14,7 +14,8 @@ import reducer, {
14
14
  getSharedDocIdsBySharings,
15
15
  getSharingType,
16
16
  getPermissionDocIds,
17
- getDocumentSharingType
17
+ getDocumentSharingType,
18
+ getSharedParentPath
18
19
  } from './state'
19
20
  import {
20
21
  SHARING_1,
@@ -613,3 +614,32 @@ describe('getDocumentSharingType', () => {
613
614
  ).toBe('one-way')
614
615
  })
615
616
  })
617
+
618
+ describe('getSharedParentPath', () => {
619
+ const state = {
620
+ sharedPaths: [
621
+ '/folder-1/sub-folder-1',
622
+ '/folder-2',
623
+ '/folder-3/sub-folder-3',
624
+ '/folder-3/sub-folder-4'
625
+ ]
626
+ }
627
+
628
+ it('should return null if no shared parent', () => {
629
+ expect(getSharedParentPath(state, '/file-1')).toBeNull()
630
+ })
631
+
632
+ it('should return shared parent path', () => {
633
+ expect(getSharedParentPath(state, '/folder-1/sub-folder-1/file-2')).toBe(
634
+ '/folder-1/sub-folder-1'
635
+ )
636
+
637
+ expect(getSharedParentPath(state, '/folder-2/sub-folder-2/file-2')).toBe(
638
+ '/folder-2'
639
+ )
640
+
641
+ expect(
642
+ getSharedParentPath(state, '/folder-3/sub-folder-4/sub-folder-5/file-4')
643
+ ).toBe('/folder-3/sub-folder-4')
644
+ })
645
+ })