cozy-sharing 16.9.0 → 16.11.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,28 @@
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
+ # [16.11.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@16.10.0...cozy-sharing@16.11.0) (2024-12-05)
7
+
8
+
9
+ ### Features
10
+
11
+ * **Sharing:** Expose new component to show owner recipient ([bcc6302](https://github.com/cozy/cozy-libs/commit/bcc6302abf0190259e86a9d327aa0d46e39b693b))
12
+
13
+
14
+
15
+
16
+
17
+ # [16.10.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@16.9.0...cozy-sharing@16.10.0) (2024-12-05)
18
+
19
+
20
+ ### Features
21
+
22
+ * **Sharing:** Add isPublic prop to SharingProvider ([d08862d](https://github.com/cozy/cozy-libs/commit/d08862d65fd4caaabfd29f116ade0607528345a9))
23
+
24
+
25
+
26
+
27
+
6
28
  # [16.9.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@16.8.0...cozy-sharing@16.9.0) (2024-12-04)
7
29
 
8
30
 
@@ -32,6 +32,7 @@ function _callSuper(_this, derived, args) {
32
32
 
33
33
  import React, { Component } from 'react';
34
34
  import { withClient } from 'cozy-client';
35
+ import minilog from 'cozy-minilog';
35
36
  import SharingContext from './context';
36
37
  import { fetchNextPermissions } from './fetchNextPermissions';
37
38
  import { fetchFilesPaths } from './helpers/files';
@@ -39,10 +40,13 @@ import { getSharingObject, createSharingInStore, updateSharingInStore } from './
39
40
  import { SynchronousJobQueue } from './helpers/synchronousJobQueue';
40
41
  import { fetchApps } from './queries/queries';
41
42
  import reducer, { receiveSharings, addSharing, updateSharing, addSharingLink, updateSharingLink, revokeSharingLink, revokeRecipient, revokeGroup as revokeGroupFromState, 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';
43
+ var log = minilog('SharingProvider');
42
44
  var SHARING_DOCTYPE = 'io.cozy.sharings';
43
45
  var PERMISSION_DOCTYPE = 'io.cozy.permissions';
44
46
  export var SharingProvider = /*#__PURE__*/function (_Component) {
45
47
  function SharingProvider(props, context) {
48
+ var _props$isPublic;
49
+
46
50
  var _this2;
47
51
 
48
52
  _classCallCheck(this, SharingProvider);
@@ -614,6 +618,7 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
614
618
  refresh: _this2.fetchAllSharings,
615
619
  hasWriteAccess: _this2.hasWriteAccess
616
620
  };
621
+ _this2.isPublic = (_props$isPublic = props.isPublic) !== null && _props$isPublic !== void 0 ? _props$isPublic : false;
617
622
  _this2.realtime = null;
618
623
  _this2.isInitialized = false;
619
624
  _this2.synchronousJobQueue = new SynchronousJobQueue();
@@ -654,11 +659,21 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
654
659
  return _regeneratorRuntime.wrap(function _callee13$(_context13) {
655
660
  while (1) switch (_context13.prev = _context13.next) {
656
661
  case 0:
662
+ if (!this.isPublic) {
663
+ _context13.next = 3;
664
+ break;
665
+ }
666
+
667
+ // In public mode, the promise below fails because the methods do not have the required permissions.
668
+ log.warn('fetchAllSharings is not allowed in public context.');
669
+ return _context13.abrupt("return");
670
+
671
+ case 3:
657
672
  _this$props = this.props, doctype = _this$props.doctype, client = _this$props.client;
658
- _context13.next = 3;
673
+ _context13.next = 6;
659
674
  return Promise.all([this.sharingCol.findByDoctype(doctype), this.permissionCol.findLinksByDoctype(doctype), client.fetchQueryAndGetFromState(fetchApps())]);
660
675
 
661
- case 3:
676
+ case 6:
662
677
  _yield$Promise$all = _context13.sent;
663
678
  _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 3);
664
679
  sharings = _yield$Promise$all2[0];
@@ -674,43 +689,43 @@ export var SharingProvider = /*#__PURE__*/function (_Component) {
674
689
  hasLoadedAtLeastOnePage: true
675
690
  }); // eslint-disable-next-line promise/catch-or-return
676
691
 
677
- _context13.next = 12;
692
+ _context13.next = 15;
678
693
  return fetchNextPermissions(permissions, this.dispatch, this.permissionCol);
679
694
 
680
- case 12:
695
+ case 15:
681
696
  if (!(doctype === 'io.cozy.files')) {
682
- _context13.next = 22;
697
+ _context13.next = 25;
683
698
  break;
684
699
  }
685
700
 
686
701
  sharedDocIds = getSharedDocIdsBySharings(sharings);
687
- _context13.next = 16;
702
+ _context13.next = 19;
688
703
  return client.collection(doctype).all({
689
704
  keys: sharedDocIds
690
705
  });
691
706
 
692
- case 16:
707
+ case 19:
693
708
  resp = _context13.sent;
694
709
  folderPaths = resp.data.filter(function (f) {
695
710
  return f.type === 'directory' && !f.trashed;
696
711
  }).map(function (f) {
697
712
  return f.path;
698
713
  });
699
- _context13.next = 20;
714
+ _context13.next = 23;
700
715
  return fetchFilesPaths(client, doctype, resp.data.filter(function (f) {
701
716
  return f.type !== 'directory' && !f.trashed;
702
717
  }));
703
718
 
704
- case 20:
719
+ case 23:
705
720
  filePaths = _context13.sent;
706
721
  this.dispatch(receivePaths([].concat(_toConsumableArray(folderPaths), _toConsumableArray(filePaths))));
707
722
 
708
- case 22:
723
+ case 25:
709
724
  this.setState({
710
725
  allLoaded: true
711
726
  });
712
727
 
713
- case 23:
728
+ case 26:
714
729
  case "end":
715
730
  return _context13.stop();
716
731
  }
@@ -11,11 +11,13 @@ import AppLike from '../test/AppLike';
11
11
 
12
12
  var AppWrapper = function AppWrapper(_ref) {
13
13
  var children = _ref.children,
14
- client = _ref.client;
14
+ client = _ref.client,
15
+ isPublic = _ref.isPublic;
15
16
  return /*#__PURE__*/React.createElement(AppLike, {
16
17
  client: client
17
18
  }, /*#__PURE__*/React.createElement(SharingProvider, {
18
- client: client
19
+ client: client,
20
+ isPublic: isPublic
19
21
  }, children));
20
22
  };
21
23
 
@@ -83,7 +85,17 @@ describe('SharingProvider', function () {
83
85
  };
84
86
  client.isLogged = true;
85
87
  beforeEach(function () {
86
- jest.spyOn(client, 'collection');
88
+ jest.spyOn(client, 'collection').mockReturnValue({
89
+ findByDoctype: jest.fn().mockResolvedValue({
90
+ data: []
91
+ }),
92
+ findLinksByDoctype: jest.fn().mockResolvedValue({
93
+ data: []
94
+ }),
95
+ findApps: jest.fn().mockResolvedValue({
96
+ data: []
97
+ })
98
+ });
87
99
  jest.spyOn(SharingProvider.prototype, 'fetchAllSharings').mockReturnValue(Promise.resolve());
88
100
  });
89
101
  afterEach(function () {
@@ -107,6 +119,18 @@ describe('SharingProvider', function () {
107
119
  expect(client.plugins.realtime.subscribe).toHaveBeenCalled();
108
120
  expect(SharingProvider.prototype.fetchAllSharings).toHaveBeenCalled();
109
121
  });
122
+ it("should not call collection's methods but always subscribe to the realtime when isPublic is true", function () {
123
+ client.isLogged = true;
124
+ render( /*#__PURE__*/React.createElement(AppWrapper, {
125
+ client: client,
126
+ isPublic: true
127
+ }));
128
+ expect(SharingProvider.prototype.fetchAllSharings).toHaveBeenCalled();
129
+ expect(client.plugins.realtime.subscribe).toHaveBeenCalled();
130
+ expect(client.collection().findByDoctype).not.toHaveBeenCalled();
131
+ expect(client.collection().findLinksByDoctype).not.toHaveBeenCalled();
132
+ expect(client.collection().findApps).not.toHaveBeenCalled();
133
+ });
110
134
  });
111
135
  describe('hasWriteAccess', function () {
112
136
  it('tells if a doc is writtable', function () {
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import { useClient, useQuery, hasQueryBeenLoaded } from 'cozy-client';
3
+ import MemberRecipientLite from './MemberRecipientLite';
4
+ import withLocales from '../../hoc/withLocales';
5
+ import { buildInstanceSettingsQuery } from '../../queries/queries';
6
+
7
+ var OwnerRecipientDefaultLite = function OwnerRecipientDefaultLite() {
8
+ var _instanceSettingsResu;
9
+
10
+ var client = useClient();
11
+ var instanceSettingsQuery = buildInstanceSettingsQuery();
12
+ var instanceSettingsResult = useQuery(instanceSettingsQuery.definition, instanceSettingsQuery.options);
13
+ return hasQueryBeenLoaded(instanceSettingsResult) && /*#__PURE__*/React.createElement(MemberRecipientLite, {
14
+ recipient: {
15
+ status: 'owner',
16
+ instance: client.options.uri,
17
+ 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
18
+ },
19
+ isOwner: true
20
+ });
21
+ };
22
+
23
+ export default withLocales(OwnerRecipientDefaultLite);
package/dist/index.js CHANGED
@@ -12,6 +12,7 @@ export { SharingOwnerAvatar } from './SharingOwnerAvatar';
12
12
  export { SharedRecipients } from './SharedRecipients';
13
13
  export { default as MemberRecipientLite } from './components/Recipient/MemberRecipientLite';
14
14
  export { default as LinkRecipientLite } from './components/Recipient/LinkRecipientLite';
15
+ export { default as OwnerRecipientDefaultLite } from './components/Recipient/OwnerRecipientDefaultLite';
15
16
  export { SharedRecipientsList } from './SharedRecipientsList';
16
17
  export { ShareButton } from './ShareButton';
17
18
  export { ShareModal } from './components/ShareModal/ShareModal';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-sharing",
3
- "version": "16.9.0",
3
+ "version": "16.11.0",
4
4
  "description": "Provides sharing login for React applications.",
5
5
  "main": "dist/index.js",
6
6
  "author": "Cozy",
@@ -71,5 +71,5 @@
71
71
  "sideEffects": [
72
72
  "*.css"
73
73
  ],
74
- "gitHead": "8b0b03c7978ff9bff74635d31a8e4ec259294200"
74
+ "gitHead": "99210fddf08b4701afcf0390c0042d3f7cfb97ec"
75
75
  }
@@ -1,6 +1,7 @@
1
1
  import React, { Component } from 'react'
2
2
 
3
3
  import { withClient } from 'cozy-client'
4
+ import minilog from 'cozy-minilog'
4
5
 
5
6
  import SharingContext from './context'
6
7
  import { fetchNextPermissions } from './fetchNextPermissions'
@@ -40,6 +41,7 @@ import reducer, {
40
41
  getSharedParentPath
41
42
  } from './state'
42
43
 
44
+ const log = minilog('SharingProvider')
43
45
  const SHARING_DOCTYPE = 'io.cozy.sharings'
44
46
  const PERMISSION_DOCTYPE = 'io.cozy.permissions'
45
47
 
@@ -83,6 +85,7 @@ export class SharingProvider extends Component {
83
85
  refresh: this.fetchAllSharings,
84
86
  hasWriteAccess: this.hasWriteAccess
85
87
  }
88
+ this.isPublic = props.isPublic ?? false
86
89
  this.realtime = null
87
90
  this.isInitialized = false
88
91
 
@@ -175,6 +178,11 @@ export class SharingProvider extends Component {
175
178
  }
176
179
 
177
180
  async fetchAllSharings() {
181
+ if (this.isPublic) {
182
+ // In public mode, the promise below fails because the methods do not have the required permissions.
183
+ log.warn('fetchAllSharings is not allowed in public context.')
184
+ return
185
+ }
178
186
  const { doctype, client } = this.props
179
187
  const [sharings, permissions, apps] = await Promise.all([
180
188
  this.sharingCol.findByDoctype(doctype),
@@ -9,10 +9,12 @@ import SharingContext from './context'
9
9
  import { receiveSharings } from './state'
10
10
  import AppLike from '../test/AppLike'
11
11
 
12
- const AppWrapper = ({ children, client }) => {
12
+ const AppWrapper = ({ children, client, isPublic }) => {
13
13
  return (
14
14
  <AppLike client={client}>
15
- <SharingProvider client={client}>{children}</SharingProvider>
15
+ <SharingProvider client={client} isPublic={isPublic}>
16
+ {children}
17
+ </SharingProvider>
16
18
  </AppLike>
17
19
  )
18
20
  }
@@ -62,7 +64,11 @@ describe('SharingProvider', () => {
62
64
  client.isLogged = true
63
65
 
64
66
  beforeEach(() => {
65
- jest.spyOn(client, 'collection')
67
+ jest.spyOn(client, 'collection').mockReturnValue({
68
+ findByDoctype: jest.fn().mockResolvedValue({ data: [] }),
69
+ findLinksByDoctype: jest.fn().mockResolvedValue({ data: [] }),
70
+ findApps: jest.fn().mockResolvedValue({ data: [] })
71
+ })
66
72
  jest
67
73
  .spyOn(SharingProvider.prototype, 'fetchAllSharings')
68
74
  .mockReturnValue(Promise.resolve())
@@ -87,6 +93,17 @@ describe('SharingProvider', () => {
87
93
  expect(client.plugins.realtime.subscribe).toHaveBeenCalled()
88
94
  expect(SharingProvider.prototype.fetchAllSharings).toHaveBeenCalled()
89
95
  })
96
+
97
+ it("should not call collection's methods but always subscribe to the realtime when isPublic is true", () => {
98
+ client.isLogged = true
99
+ render(<AppWrapper client={client} isPublic={true} />)
100
+
101
+ expect(SharingProvider.prototype.fetchAllSharings).toHaveBeenCalled()
102
+ expect(client.plugins.realtime.subscribe).toHaveBeenCalled()
103
+ expect(client.collection().findByDoctype).not.toHaveBeenCalled()
104
+ expect(client.collection().findLinksByDoctype).not.toHaveBeenCalled()
105
+ expect(client.collection().findApps).not.toHaveBeenCalled()
106
+ })
90
107
  })
91
108
 
92
109
  describe('hasWriteAccess', () => {
@@ -0,0 +1,32 @@
1
+ import React from 'react'
2
+
3
+ import { useClient, useQuery, hasQueryBeenLoaded } from 'cozy-client'
4
+
5
+ import MemberRecipientLite from './MemberRecipientLite'
6
+ import withLocales from '../../hoc/withLocales'
7
+ import { buildInstanceSettingsQuery } from '../../queries/queries'
8
+
9
+ const OwnerRecipientDefaultLite = () => {
10
+ const client = useClient()
11
+
12
+ const instanceSettingsQuery = buildInstanceSettingsQuery()
13
+ const instanceSettingsResult = useQuery(
14
+ instanceSettingsQuery.definition,
15
+ instanceSettingsQuery.options
16
+ )
17
+
18
+ return (
19
+ hasQueryBeenLoaded(instanceSettingsResult) && (
20
+ <MemberRecipientLite
21
+ recipient={{
22
+ status: 'owner',
23
+ instance: client.options.uri,
24
+ public_name: instanceSettingsResult?.data?.attributes?.public_name
25
+ }}
26
+ isOwner={true}
27
+ />
28
+ )
29
+ )
30
+ }
31
+
32
+ export default withLocales(OwnerRecipientDefaultLite)
package/src/index.jsx CHANGED
@@ -16,6 +16,7 @@ export { SharingOwnerAvatar } from './SharingOwnerAvatar'
16
16
  export { SharedRecipients } from './SharedRecipients'
17
17
  export { default as MemberRecipientLite } from './components/Recipient/MemberRecipientLite'
18
18
  export { default as LinkRecipientLite } from './components/Recipient/LinkRecipientLite'
19
+ export { default as OwnerRecipientDefaultLite } from './components/Recipient/OwnerRecipientDefaultLite'
19
20
  export { SharedRecipientsList } from './SharedRecipientsList'
20
21
  export { ShareButton } from './ShareButton'
21
22
  export { ShareModal } from './components/ShareModal/ShareModal'