cozy-sharing 6.0.4 → 6.0.5

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,18 @@
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
+ ## [6.0.5](https://github.com/cozy/cozy-libs/compare/cozy-sharing@6.0.4...cozy-sharing@6.0.5) (2023-03-07)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Display always instance address as secondary text for owner ([f6c89cf](https://github.com/cozy/cozy-libs/commit/f6c89cf54d723d695f0afe0a9fe9ab44f236376e))
12
+ * Display correctly owner recipient when receiving sharing ([49a1c5a](https://github.com/cozy/cozy-libs/commit/49a1c5ac6aa029be3217fef93ce3f7bce6e21019))
13
+
14
+
15
+
16
+
17
+
6
18
  ## [6.0.4](https://github.com/cozy/cozy-libs/compare/cozy-sharing@6.0.3...cozy-sharing@6.0.4) (2023-03-01)
7
19
 
8
20
 
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import Recipient from './Recipient';
4
+ import OwnerRecipientDefault from './OwnerRecipientDefault';
5
+
6
+ var OwnerRecipient = function OwnerRecipient(_ref) {
7
+ var recipients = _ref.recipients;
8
+ var ownerRecipient = recipients.find(function (recipient) {
9
+ return recipient.status === 'owner';
10
+ });
11
+
12
+ if (ownerRecipient) {
13
+ return /*#__PURE__*/React.createElement(Recipient, ownerRecipient);
14
+ }
15
+
16
+ return /*#__PURE__*/React.createElement(OwnerRecipientDefault, null);
17
+ };
18
+
19
+ OwnerRecipient.propTypes = {
20
+ recipients: PropTypes.array.isRequired
21
+ };
22
+ export default OwnerRecipient;
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import { useClient, useQuery, hasQueryBeenLoaded } from 'cozy-client';
3
+ import Recipient from './Recipient';
4
+ import { buildInstanceSettingsQuery } from '../../queries/queries';
5
+
6
+ var OwnerRecipientDefault = function OwnerRecipientDefault() {
7
+ var _instanceSettingsResu, _instanceSettingsResu2;
8
+
9
+ var client = useClient();
10
+ var instanceSettingsQuery = buildInstanceSettingsQuery();
11
+ var instanceSettingsResult = useQuery(instanceSettingsQuery.definition, instanceSettingsQuery.options);
12
+ return hasQueryBeenLoaded(instanceSettingsResult) && /*#__PURE__*/React.createElement(Recipient, {
13
+ isOwner: true,
14
+ status: "owner",
15
+ instance: client.options.uri,
16
+ public_name: instanceSettingsResult === null || instanceSettingsResult === void 0 ? void 0 : (_instanceSettingsResu = instanceSettingsResult.data) === null || _instanceSettingsResu === void 0 ? void 0 : (_instanceSettingsResu2 = _instanceSettingsResu.attributes) === null || _instanceSettingsResu2 === void 0 ? void 0 : _instanceSettingsResu2.public_name
17
+ });
18
+ };
19
+
20
+ export default OwnerRecipientDefault;
@@ -35,7 +35,7 @@ var RecipientStatus = function RecipientStatus(_ref) {
35
35
  t = _useI18n.t;
36
36
 
37
37
  var isSendingEmail = !isMe && status === 'mail-not-sent';
38
- var isReady = isMe || status === 'ready';
38
+ var isReady = isMe || status === 'ready' || status === 'owner';
39
39
  var text, icon;
40
40
 
41
41
  if (isReady) {
@@ -19,7 +19,14 @@ jest.mock('cozy-client', function () {
19
19
  public_name: 'Alice'
20
20
  }
21
21
  }),
22
- hasQueryBeenLoaded: jest.fn().mockReturnValue(true)
22
+ hasQueryBeenLoaded: jest.fn().mockReturnValue(true),
23
+ useClient: function useClient() {
24
+ return {
25
+ options: {
26
+ uri: mockRecipientAlice.instance
27
+ }
28
+ };
29
+ }
23
30
  });
24
31
  });
25
32
  describe('ShareDialogCozyToCozy', function () {
@@ -66,9 +73,9 @@ describe('ShareDialogCozyToCozy', function () {
66
73
  while (1) switch (_context.prev = _context.next) {
67
74
  case 0:
68
75
  resolve([{
69
- name: recipientBob.public_name,
76
+ name: mockRecipientBob.public_name,
70
77
  id: 'SOME_ID',
71
- email: recipientBob.email
78
+ email: mockRecipientBob.email
72
79
  }]);
73
80
  _context.next = 3;
74
81
  return promise;
@@ -111,9 +118,9 @@ describe('ShareDialogCozyToCozy', function () {
111
118
  while (1) switch (_context3.prev = _context3.next) {
112
119
  case 0:
113
120
  resolve([{
114
- name: recipientBob.public_name,
121
+ name: mockRecipientBob.public_name,
115
122
  id: 'SOME_ID',
116
- email: recipientBob.email
123
+ email: mockRecipientBob.email
117
124
  }]);
118
125
  _context3.next = 3;
119
126
  return promise;
@@ -157,13 +164,13 @@ describe('ShareDialogCozyToCozy', function () {
157
164
  while (1) switch (_context5.prev = _context5.next) {
158
165
  case 0:
159
166
  resolve([{
160
- name: recipientBob.public_name,
167
+ name: mockRecipientBob.public_name,
161
168
  id: 'SOME_ID',
162
- email: recipientBob.email
169
+ email: mockRecipientBob.email
163
170
  }, {
164
- name: recipientClaude.public_name,
171
+ name: mockRecipientClaude.public_name,
165
172
  id: 'SOME_OTHER_ID',
166
- email: recipientClaude.email
173
+ email: mockRecipientClaude.email
167
174
  }]);
168
175
  _context5.next = 3;
169
176
  return promise;
@@ -253,9 +260,9 @@ describe('ShareDialogCozyToCozy', function () {
253
260
  while (1) switch (_context9.prev = _context9.next) {
254
261
  case 0:
255
262
  resolve([{
256
- name: recipientBob.public_name,
263
+ name: mockRecipientBob.public_name,
257
264
  id: 'SOME_ID',
258
- email: recipientBob.email,
265
+ email: mockRecipientBob.email,
259
266
  fingerprintPhrase: 'SOME_FINGERPRINT_PHRASE'
260
267
  }]);
261
268
  _context9.next = 3;
@@ -301,7 +308,7 @@ describe('ShareDialogCozyToCozy', function () {
301
308
  })));
302
309
 
303
310
  case 12:
304
- expect(getByText("Do you really want to reject contact ".concat(recipientBob.public_name, " (").concat(recipientBob.email, ")?"))).toBeTruthy();
311
+ expect(getByText("Do you really want to reject contact ".concat(mockRecipientBob.public_name, " (").concat(mockRecipientBob.email, ")?"))).toBeTruthy();
305
312
  confirmRejectButton = getByText('Reject');
306
313
  _context13.next = 16;
307
314
  return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12() {
@@ -327,7 +334,7 @@ describe('ShareDialogCozyToCozy', function () {
327
334
  }, _callee13);
328
335
  })));
329
336
  });
330
- var recipientAlice = {
337
+ var mockRecipientAlice = {
331
338
  status: 'owner',
332
339
  public_name: 'Alice',
333
340
  email: 'me@alice.cozy.localhost',
@@ -337,7 +344,7 @@ var recipientAlice = {
337
344
  index: 0,
338
345
  avatarPath: '/sharings/SOME_SHARING_ID/recipients/0/avatar'
339
346
  };
340
- var recipientBob = {
347
+ var mockRecipientBob = {
341
348
  status: 'ready',
342
349
  public_name: 'Claude',
343
350
  email: 'me@claude.cozy.localhost',
@@ -347,7 +354,7 @@ var recipientBob = {
347
354
  index: 1,
348
355
  avatarPath: '/sharings/SOME_SHARING_ID/recipients/1/avatar'
349
356
  };
350
- var recipientClaude = {
357
+ var mockRecipientClaude = {
351
358
  status: 'ready',
352
359
  public_name: 'Bob',
353
360
  email: 'me@bob.cozy.localhost',
@@ -446,7 +453,7 @@ var getMockProps = function getMockProps() {
446
453
  isOwner: true,
447
454
  link: null,
448
455
  permissions: [],
449
- recipients: [recipientAlice, recipientBob, recipientClaude, {
456
+ recipients: [mockRecipientAlice, mockRecipientBob, mockRecipientClaude, {
450
457
  status: 'pending',
451
458
  email: 'me@ben.cozy.localhost',
452
459
  type: 'two-way',
@@ -1,14 +1,13 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import React from 'react';
3
3
  import PropTypes from 'prop-types';
4
- import { useClient, useQuery, hasQueryBeenLoaded } from 'cozy-client';
5
4
  import Recipient from './Recipient/Recipient';
6
5
  import LinkRecipient from './Recipient/LinkRecipient';
7
6
  import { useI18n } from 'cozy-ui/transpiled/react/I18n';
8
7
  import List from 'cozy-ui/transpiled/react/MuiCozyTheme/List';
9
- import { buildInstanceSettingsQuery } from '../queries/queries';
10
8
  import { filterAndReworkRecipients } from '../helpers/recipients';
11
9
  import { usePrevious } from '../helpers/hooks';
10
+ import OwnerRecipient from './Recipient/OwnerRecipient';
12
11
  /**
13
12
  * Displays a warning if some contacts are waiting for confirmation of their sharing
14
13
  *
@@ -31,8 +30,6 @@ var RecipientWaitingForConfirmationAlert = function RecipientWaitingForConfirmat
31
30
  };
32
31
 
33
32
  var WhoHasAccess = function WhoHasAccess(_ref2) {
34
- var _instanceSettingsResu, _instanceSettingsResu2;
35
-
36
33
  var _ref2$isOwner = _ref2.isOwner,
37
34
  isOwner = _ref2$isOwner === void 0 ? false : _ref2$isOwner,
38
35
  recipients = _ref2.recipients,
@@ -48,14 +45,10 @@ var WhoHasAccess = function WhoHasAccess(_ref2) {
48
45
  permissions = _ref2.permissions,
49
46
  onUpdateShareLinkPermissions = _ref2.onUpdateShareLinkPermissions,
50
47
  onRevokeLink = _ref2.onRevokeLink;
51
- var client = useClient();
52
- var instanceSettingsQuery = buildInstanceSettingsQuery();
53
- var instanceSettingsResult = useQuery(instanceSettingsQuery.definition, instanceSettingsQuery.options);
54
48
  var previousLink = usePrevious(link);
55
49
  var previousRecipients = usePrevious(recipients);
56
50
  var linkHasBeenJustCreated = link && previousLink === null;
57
51
  var recipientsToDisplay = filterAndReworkRecipients(recipients, previousRecipients);
58
- var public_name = instanceSettingsResult === null || instanceSettingsResult === void 0 ? void 0 : (_instanceSettingsResu = instanceSettingsResult.data) === null || _instanceSettingsResu === void 0 ? void 0 : (_instanceSettingsResu2 = _instanceSettingsResu.attributes) === null || _instanceSettingsResu2 === void 0 ? void 0 : _instanceSettingsResu2.public_name;
59
52
  return /*#__PURE__*/React.createElement("div", {
60
53
  className: className
61
54
  }, /*#__PURE__*/React.createElement(RecipientWaitingForConfirmationAlert, {
@@ -72,11 +65,8 @@ var WhoHasAccess = function WhoHasAccess(_ref2) {
72
65
  onChangePermissions: onUpdateShareLinkPermissions,
73
66
  onDisable: onRevokeLink,
74
67
  fadeIn: linkHasBeenJustCreated
75
- }), hasQueryBeenLoaded(instanceSettingsResult) && /*#__PURE__*/React.createElement(Recipient, {
76
- isOwner: true,
77
- status: "owner",
78
- instance: client.options.uri,
79
- public_name: public_name
68
+ }), /*#__PURE__*/React.createElement(OwnerRecipient, {
69
+ recipients: recipients
80
70
  }), recipientsToDisplay.map(function (recipient) {
81
71
  var recipientConfirmationData = recipientsToBeConfirmed.find(function (user) {
82
72
  return user.email === recipient.email;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-sharing",
3
- "version": "6.0.4",
3
+ "version": "6.0.5",
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": "cb40ff1333287ec2f4e7c8409247eaeb6b8f9ade"
64
+ "gitHead": "5198837dbb9f5ee395cbb67746b749ecd1121e45"
65
65
  }
@@ -0,0 +1,23 @@
1
+ import React from 'react'
2
+ import PropTypes from 'prop-types'
3
+
4
+ import Recipient from './Recipient'
5
+ import OwnerRecipientDefault from './OwnerRecipientDefault'
6
+
7
+ const OwnerRecipient = ({ recipients }) => {
8
+ const ownerRecipient = recipients.find(
9
+ recipient => recipient.status === 'owner'
10
+ )
11
+
12
+ if (ownerRecipient) {
13
+ return <Recipient {...ownerRecipient} />
14
+ }
15
+
16
+ return <OwnerRecipientDefault />
17
+ }
18
+
19
+ OwnerRecipient.propTypes = {
20
+ recipients: PropTypes.array.isRequired
21
+ }
22
+
23
+ export default OwnerRecipient
@@ -0,0 +1,29 @@
1
+ import React from 'react'
2
+
3
+ import { useClient, useQuery, hasQueryBeenLoaded } from 'cozy-client'
4
+
5
+ import Recipient from './Recipient'
6
+ import { buildInstanceSettingsQuery } from '../../queries/queries'
7
+
8
+ const OwnerRecipientDefault = () => {
9
+ const client = useClient()
10
+
11
+ const instanceSettingsQuery = buildInstanceSettingsQuery()
12
+ const instanceSettingsResult = useQuery(
13
+ instanceSettingsQuery.definition,
14
+ instanceSettingsQuery.options
15
+ )
16
+
17
+ return (
18
+ hasQueryBeenLoaded(instanceSettingsResult) && (
19
+ <Recipient
20
+ isOwner={true}
21
+ status="owner"
22
+ instance={client.options.uri}
23
+ public_name={instanceSettingsResult?.data?.attributes?.public_name}
24
+ />
25
+ )
26
+ )
27
+ }
28
+
29
+ export default OwnerRecipientDefault
@@ -14,7 +14,7 @@ const RecipientStatus = ({ status, isMe, instance }) => {
14
14
  const { t } = useI18n()
15
15
 
16
16
  const isSendingEmail = !isMe && status === 'mail-not-sent'
17
- const isReady = isMe || status === 'ready'
17
+ const isReady = isMe || status === 'ready' || status === 'owner'
18
18
  let text, icon
19
19
  if (isReady) {
20
20
  text = instance
@@ -8,7 +8,8 @@ import { act, render, fireEvent } from '@testing-library/react'
8
8
  jest.mock('cozy-client', () => ({
9
9
  ...jest.requireActual('cozy-client'),
10
10
  useQuery: jest.fn().mockReturnValue({ data: { public_name: 'Alice' } }),
11
- hasQueryBeenLoaded: jest.fn().mockReturnValue(true)
11
+ hasQueryBeenLoaded: jest.fn().mockReturnValue(true),
12
+ useClient: () => ({ options: { uri: mockRecipientAlice.instance } })
12
13
  }))
13
14
 
14
15
  describe('ShareDialogCozyToCozy', () => {
@@ -54,9 +55,9 @@ describe('ShareDialogCozyToCozy', () => {
54
55
  await act(async () => {
55
56
  resolve([
56
57
  {
57
- name: recipientBob.public_name,
58
+ name: mockRecipientBob.public_name,
58
59
  id: 'SOME_ID',
59
- email: recipientBob.email
60
+ email: mockRecipientBob.email
60
61
  }
61
62
  ])
62
63
  await promise
@@ -81,9 +82,9 @@ describe('ShareDialogCozyToCozy', () => {
81
82
  await act(async () => {
82
83
  resolve([
83
84
  {
84
- name: recipientBob.public_name,
85
+ name: mockRecipientBob.public_name,
85
86
  id: 'SOME_ID',
86
- email: recipientBob.email
87
+ email: mockRecipientBob.email
87
88
  }
88
89
  ])
89
90
  await promise
@@ -111,14 +112,14 @@ describe('ShareDialogCozyToCozy', () => {
111
112
  await act(async () => {
112
113
  resolve([
113
114
  {
114
- name: recipientBob.public_name,
115
+ name: mockRecipientBob.public_name,
115
116
  id: 'SOME_ID',
116
- email: recipientBob.email
117
+ email: mockRecipientBob.email
117
118
  },
118
119
  {
119
- name: recipientClaude.public_name,
120
+ name: mockRecipientClaude.public_name,
120
121
  id: 'SOME_OTHER_ID',
121
- email: recipientClaude.email
122
+ email: mockRecipientClaude.email
122
123
  }
123
124
  ])
124
125
  await promise
@@ -173,9 +174,9 @@ describe('ShareDialogCozyToCozy', () => {
173
174
  await act(async () => {
174
175
  resolve([
175
176
  {
176
- name: recipientBob.public_name,
177
+ name: mockRecipientBob.public_name,
177
178
  id: 'SOME_ID',
178
- email: recipientBob.email,
179
+ email: mockRecipientBob.email,
179
180
  fingerprintPhrase: 'SOME_FINGERPRINT_PHRASE'
180
181
  }
181
182
  ])
@@ -192,7 +193,7 @@ describe('ShareDialogCozyToCozy', () => {
192
193
 
193
194
  expect(
194
195
  getByText(
195
- `Do you really want to reject contact ${recipientBob.public_name} (${recipientBob.email})?`
196
+ `Do you really want to reject contact ${mockRecipientBob.public_name} (${mockRecipientBob.email})?`
196
197
  )
197
198
  ).toBeTruthy()
198
199
 
@@ -203,7 +204,7 @@ describe('ShareDialogCozyToCozy', () => {
203
204
  })
204
205
  })
205
206
 
206
- const recipientAlice = {
207
+ const mockRecipientAlice = {
207
208
  status: 'owner',
208
209
  public_name: 'Alice',
209
210
  email: 'me@alice.cozy.localhost',
@@ -214,7 +215,7 @@ const recipientAlice = {
214
215
  avatarPath: '/sharings/SOME_SHARING_ID/recipients/0/avatar'
215
216
  }
216
217
 
217
- const recipientBob = {
218
+ const mockRecipientBob = {
218
219
  status: 'ready',
219
220
  public_name: 'Claude',
220
221
  email: 'me@claude.cozy.localhost',
@@ -225,7 +226,7 @@ const recipientBob = {
225
226
  avatarPath: '/sharings/SOME_SHARING_ID/recipients/1/avatar'
226
227
  }
227
228
 
228
- const recipientClaude = {
229
+ const mockRecipientClaude = {
229
230
  status: 'ready',
230
231
  public_name: 'Bob',
231
232
  email: 'me@bob.cozy.localhost',
@@ -333,9 +334,9 @@ const getMockProps = () => {
333
334
  link: null,
334
335
  permissions: [],
335
336
  recipients: [
336
- recipientAlice,
337
- recipientBob,
338
- recipientClaude,
337
+ mockRecipientAlice,
338
+ mockRecipientBob,
339
+ mockRecipientClaude,
339
340
  {
340
341
  status: 'pending',
341
342
  email: 'me@ben.cozy.localhost',
@@ -1,14 +1,13 @@
1
1
  import React from 'react'
2
2
  import PropTypes from 'prop-types'
3
- import { useClient, useQuery, hasQueryBeenLoaded } from 'cozy-client'
4
3
  import Recipient from './Recipient/Recipient'
5
4
  import LinkRecipient from './Recipient/LinkRecipient'
6
5
  import { useI18n } from 'cozy-ui/transpiled/react/I18n'
7
6
  import List from 'cozy-ui/transpiled/react/MuiCozyTheme/List'
8
7
 
9
- import { buildInstanceSettingsQuery } from '../queries/queries'
10
8
  import { filterAndReworkRecipients } from '../helpers/recipients'
11
9
  import { usePrevious } from '../helpers/hooks'
10
+ import OwnerRecipient from './Recipient/OwnerRecipient'
12
11
 
13
12
  /**
14
13
  * Displays a warning if some contacts are waiting for confirmation of their sharing
@@ -42,14 +41,6 @@ const WhoHasAccess = ({
42
41
  onUpdateShareLinkPermissions,
43
42
  onRevokeLink
44
43
  }) => {
45
- const client = useClient()
46
-
47
- const instanceSettingsQuery = buildInstanceSettingsQuery()
48
- const instanceSettingsResult = useQuery(
49
- instanceSettingsQuery.definition,
50
- instanceSettingsQuery.options
51
- )
52
-
53
44
  const previousLink = usePrevious(link)
54
45
  const previousRecipients = usePrevious(recipients)
55
46
 
@@ -60,8 +51,6 @@ const WhoHasAccess = ({
60
51
  previousRecipients
61
52
  )
62
53
 
63
- const public_name = instanceSettingsResult?.data?.attributes?.public_name
64
-
65
54
  return (
66
55
  <div className={className}>
67
56
  <RecipientWaitingForConfirmationAlert
@@ -82,14 +71,7 @@ const WhoHasAccess = ({
82
71
  />
83
72
  )}
84
73
 
85
- {hasQueryBeenLoaded(instanceSettingsResult) && (
86
- <Recipient
87
- isOwner={true}
88
- status="owner"
89
- instance={client.options.uri}
90
- public_name={public_name}
91
- />
92
- )}
74
+ <OwnerRecipient recipients={recipients} />
93
75
 
94
76
  {recipientsToDisplay.map(recipient => {
95
77
  const recipientConfirmationData = recipientsToBeConfirmed.find(