cozy-sharing 6.0.6 → 7.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.
Files changed (158) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/ConfirmTrustedRecipientsDialog.js +1 -1
  3. package/dist/RefreshableSharings.spec.js +2 -2
  4. package/dist/ShareButton.js +1 -1
  5. package/dist/ShareButton.spec.js +1 -1
  6. package/dist/ShareButtonWithRecipients.js +3 -3
  7. package/dist/ShareModal.js +2 -2
  8. package/dist/SharedBadge.js +1 -1
  9. package/dist/SharedRecipients.js +1 -1
  10. package/dist/SharedRecipientsList.js +1 -1
  11. package/dist/SharedStatus.js +1 -1
  12. package/dist/SharingBanner/components/PublicBanner.js +1 -1
  13. package/dist/SharingBanner/components/PublicBanner.spec.js +3 -3
  14. package/dist/SharingBanner/components/SharingBanner.js +1 -1
  15. package/dist/SharingBanner/hooks/useSharingInfos.js +1 -1
  16. package/dist/SharingBanner/hooks/useSharingInfos.spec.js +1 -1
  17. package/dist/SharingBanner/index.js +3 -3
  18. package/dist/SharingBanner/test/AppLike.js +6 -6
  19. package/dist/SharingDetailsModal.js +8 -8
  20. package/dist/SharingOwnerAvatar.js +1 -1
  21. package/dist/SharingProvider.js +2 -2
  22. package/dist/SharingProvider.spec.js +4 -4
  23. package/dist/components/ContactSuggestion.js +4 -4
  24. package/dist/components/ContactSuggestion.spec.js +2 -2
  25. package/dist/components/CozyPassFingerprintDialogContent.js +4 -4
  26. package/dist/components/CozyPassFingerprintDialogContent.spec.js +2 -2
  27. package/dist/components/EditLinkPermissionDialog.js +5 -5
  28. package/dist/components/EditLinkPermissionDialog.spec.js +2 -2
  29. package/dist/components/EditableSharingModal.js +3 -3
  30. package/dist/components/EditableSharingModal.spec.js +4 -4
  31. package/dist/components/Recipient/AvatarPlusX.js +2 -2
  32. package/dist/components/Recipient/Identity.js +2 -2
  33. package/dist/components/Recipient/LinkRecipient.js +8 -8
  34. package/dist/components/Recipient/LinkRecipientPermissions.js +5 -5
  35. package/dist/components/Recipient/OwnerIdentity.js +1 -1
  36. package/dist/components/Recipient/OwnerRecipient.js +2 -2
  37. package/dist/components/Recipient/Recipient.js +6 -6
  38. package/dist/components/Recipient/Recipient.spec.js +2 -2
  39. package/dist/components/Recipient/RecipientConfirm.js +2 -2
  40. package/dist/components/Recipient/RecipientPermissions.js +5 -5
  41. package/dist/components/Recipient/RecipientPlusX.js +2 -2
  42. package/dist/components/Recipient/RecipientStatus.js +3 -3
  43. package/dist/components/Recipient/RecipientWithoutStatus.js +1 -1
  44. package/dist/components/Recipient/RecipientsAvatars.js +2 -2
  45. package/dist/components/Recipient/RecipientsAvatars.spec.js +1 -1
  46. package/dist/components/ShareAutosuggest.js +5 -5
  47. package/dist/components/ShareAutosuggest.spec.js +1 -1
  48. package/dist/components/ShareButton.js +3 -3
  49. package/dist/components/ShareByEmail.js +6 -6
  50. package/dist/components/ShareByEmail.spec.js +2 -2
  51. package/dist/components/ShareByLink.js +7 -7
  52. package/dist/components/ShareDialogCozyToCozy.js +3 -3
  53. package/dist/components/ShareDialogCozyToCozy.spec.js +3 -3
  54. package/dist/components/ShareDialogOnlyByLink.js +1 -1
  55. package/dist/components/ShareDialogTwoStepsConfirmationContainer.js +1 -1
  56. package/dist/components/ShareDialogTwoStepsConfirmationContainer.spec.js +3 -3
  57. package/dist/components/ShareModal.js +2 -2
  58. package/dist/components/ShareModal.spec.js +2 -2
  59. package/dist/components/ShareRecipientsInput.js +2 -2
  60. package/dist/components/ShareRecipientsInput.spec.js +1 -1
  61. package/dist/components/SharedBadge.js +3 -3
  62. package/dist/components/SharedDocuments.js +2 -2
  63. package/dist/components/SharedStatus.js +2 -2
  64. package/dist/components/SharedStatus.spec.js +1 -1
  65. package/dist/components/Sharesubmit.js +1 -1
  66. package/dist/components/Sharetypeselect.js +5 -5
  67. package/dist/components/Tooltip.js +1 -1
  68. package/dist/components/WhoHasAccess.js +5 -5
  69. package/dist/components/WhoHasAccessLight.js +2 -2
  70. package/dist/getSharedDocument.js +14 -5
  71. package/dist/getSharedDocument.spec.js +81 -10
  72. package/dist/helpers/sharings.js +1 -1
  73. package/dist/helpers/successMessage.js +1 -1
  74. package/dist/index.js +1 -1
  75. package/dist/state.js +2 -6
  76. package/package.json +2 -2
  77. package/preprocess.js +1 -0
  78. package/src/ConfirmTrustedRecipientsDialog.jsx +1 -1
  79. package/src/RefreshableSharings.spec.jsx +2 -2
  80. package/src/ShareButton.jsx +2 -2
  81. package/src/ShareButton.spec.jsx +2 -1
  82. package/src/ShareButtonWithRecipients.jsx +5 -3
  83. package/src/ShareModal.jsx +2 -2
  84. package/src/SharedBadge.jsx +1 -1
  85. package/src/SharedRecipients.jsx +1 -1
  86. package/src/SharedRecipientsList.jsx +1 -1
  87. package/src/SharedStatus.jsx +1 -1
  88. package/src/SharingBanner/components/PublicBanner.jsx +1 -2
  89. package/src/SharingBanner/components/PublicBanner.spec.jsx +5 -3
  90. package/src/SharingBanner/components/SharingBanner.jsx +1 -1
  91. package/src/SharingBanner/hooks/useSharingInfos.jsx +1 -1
  92. package/src/SharingBanner/hooks/useSharingInfos.spec.js +1 -1
  93. package/src/SharingBanner/index.jsx +3 -3
  94. package/src/SharingBanner/test/AppLike.jsx +7 -7
  95. package/src/SharingDetailsModal.jsx +3 -3
  96. package/src/SharingOwnerAvatar.jsx +1 -1
  97. package/src/SharingProvider.jsx +9 -9
  98. package/src/SharingProvider.spec.jsx +5 -5
  99. package/src/components/ConfirmTrustedRecipientsDialog.jsx +1 -1
  100. package/src/components/ContactSuggestion.jsx +4 -4
  101. package/src/components/ContactSuggestion.spec.jsx +2 -2
  102. package/src/components/CozyPassFingerprintDialogContent.jsx +4 -5
  103. package/src/components/CozyPassFingerprintDialogContent.spec.jsx +2 -2
  104. package/src/components/EditLinkPermissionDialog.jsx +5 -5
  105. package/src/components/EditLinkPermissionDialog.spec.jsx +3 -2
  106. package/src/components/EditableSharingModal.jsx +4 -3
  107. package/src/components/EditableSharingModal.spec.jsx +4 -4
  108. package/src/components/Recipient/AvatarPlusX.jsx +2 -2
  109. package/src/components/Recipient/Identity.jsx +2 -2
  110. package/src/components/Recipient/LinkRecipient.jsx +8 -8
  111. package/src/components/Recipient/LinkRecipientPermissions.jsx +5 -6
  112. package/src/components/Recipient/OwnerIdentity.jsx +1 -1
  113. package/src/components/Recipient/OwnerRecipient.jsx +2 -2
  114. package/src/components/Recipient/Recipient.jsx +6 -6
  115. package/src/components/Recipient/Recipient.spec.jsx +4 -2
  116. package/src/components/Recipient/RecipientAvatar.jsx +1 -1
  117. package/src/components/Recipient/RecipientConfirm.jsx +2 -2
  118. package/src/components/Recipient/RecipientPermissions.jsx +6 -6
  119. package/src/components/Recipient/RecipientPlusX.jsx +2 -2
  120. package/src/components/Recipient/RecipientStatus.jsx +3 -3
  121. package/src/components/Recipient/RecipientWithoutStatus.jsx +1 -1
  122. package/src/components/Recipient/RecipientsAvatars.jsx +3 -3
  123. package/src/components/Recipient/RecipientsAvatars.spec.jsx +2 -1
  124. package/src/components/ShareAutosuggest.jsx +5 -6
  125. package/src/components/ShareAutosuggest.spec.jsx +1 -1
  126. package/src/components/ShareButton.jsx +4 -4
  127. package/src/components/ShareByEmail.jsx +6 -7
  128. package/src/components/ShareByEmail.spec.jsx +3 -2
  129. package/src/components/ShareByLink.jsx +8 -7
  130. package/src/components/ShareDialogCozyToCozy.jsx +4 -5
  131. package/src/components/ShareDialogCozyToCozy.spec.jsx +5 -3
  132. package/src/components/ShareDialogOnlyByLink.jsx +2 -1
  133. package/src/components/ShareDialogTwoStepsConfirmationContainer.jsx +2 -1
  134. package/src/components/ShareDialogTwoStepsConfirmationContainer.spec.jsx +5 -3
  135. package/src/components/ShareModal.jsx +3 -3
  136. package/src/components/ShareModal.spec.js +4 -2
  137. package/src/components/ShareRecipientsInput.jsx +2 -2
  138. package/src/components/ShareRecipientsInput.spec.jsx +1 -1
  139. package/src/components/SharedBadge.jsx +4 -3
  140. package/src/components/SharedDocuments.jsx +3 -2
  141. package/src/components/SharedStatus.jsx +4 -3
  142. package/src/components/SharedStatus.spec.js +2 -1
  143. package/src/components/Sharesubmit.jsx +2 -1
  144. package/src/components/Sharetypeselect.jsx +5 -7
  145. package/src/components/Tooltip.jsx +2 -1
  146. package/src/components/WhoHasAccess.jsx +6 -5
  147. package/src/components/WhoHasAccessLight.jsx +3 -3
  148. package/src/components/useFetchDocumentPath.jsx +1 -0
  149. package/src/getSharedDocument.js +13 -5
  150. package/src/getSharedDocument.spec.js +26 -5
  151. package/src/helpers/permissions.js +1 -0
  152. package/src/helpers/sharings.js +1 -2
  153. package/src/helpers/successMessage.js +2 -1
  154. package/src/index.jsx +1 -1
  155. package/src/state.js +2 -6
  156. package/src/state.spec.js +0 -1
  157. package/src/withLocales.jsx +1 -0
  158. package/test/AppLike.jsx +2 -2
@@ -1,13 +1,14 @@
1
- import React from 'react'
2
1
  import PropTypes from 'prop-types'
3
- import Recipient from './Recipient/Recipient'
4
- import LinkRecipient from './Recipient/LinkRecipient'
2
+ import React from 'react'
3
+
5
4
  import { useI18n } from 'cozy-ui/transpiled/react/I18n'
6
5
  import List from 'cozy-ui/transpiled/react/MuiCozyTheme/List'
7
6
 
8
- import { filterAndReworkRecipients } from '../helpers/recipients'
9
- import { usePrevious } from '../helpers/hooks'
7
+ import LinkRecipient from './Recipient/LinkRecipient'
10
8
  import OwnerRecipient from './Recipient/OwnerRecipient'
9
+ import Recipient from './Recipient/Recipient'
10
+ import { usePrevious } from '../helpers/hooks'
11
+ import { filterAndReworkRecipients } from '../helpers/recipients'
11
12
 
12
13
  /**
13
14
  * Displays a warning if some contacts are waiting for confirmation of their sharing
@@ -1,8 +1,8 @@
1
- import React from 'react'
2
1
  import cx from 'classnames'
3
- import RecipientWithoutStatus from './Recipient/RecipientWithoutStatus'
4
- import RecipientPlusX from './Recipient/RecipientPlusX'
2
+ import React from 'react'
5
3
 
4
+ import RecipientPlusX from './Recipient/RecipientPlusX'
5
+ import RecipientWithoutStatus from './Recipient/RecipientWithoutStatus'
6
6
  import styles from './recipient.styl'
7
7
 
8
8
  const MAX_DISPLAYED_RECIPIENTS = 2
@@ -1,4 +1,5 @@
1
1
  import { useState, useEffect } from 'react'
2
+
2
3
  import { fetchFilesPaths } from '../helpers/files'
3
4
 
4
5
  export const useFetchDocumentPath = (client, document) => {
@@ -1,15 +1,23 @@
1
- import get from 'lodash/get'
1
+ import { isReadOnly } from 'cozy-client/dist/models/permission'
2
2
 
3
+ /**
4
+ * Get the first shared document for the current shared token
5
+ *
6
+ * @param {CozyClient} client
7
+ * @returns {{id, isReadOnly}} id of the document and the readOnly status
8
+ */
3
9
  const getSharedDocument = async client => {
4
10
  const { data: permissionsData } = await client
5
11
  .collection('io.cozy.permissions')
6
12
  .getOwnPermissions()
7
13
 
8
- const permissions = permissionsData.attributes.permissions
14
+ const permissions = Object.values(permissionsData.attributes.permissions)
9
15
  // permissions contains several named keys, but the one to use depends on the situation. Using the first one is what we want in all known cases.
10
- const sharedDocumentId = get(Object.values(permissions), '0.values.0')
11
-
12
- return sharedDocumentId
16
+ const perm = permissions[0]
17
+ return {
18
+ id: perm.values[0],
19
+ isReadOnly: isReadOnly(perm)
20
+ }
13
21
  }
14
22
 
15
23
  export default getSharedDocument
@@ -1,7 +1,7 @@
1
1
  import getSharedDocument from './getSharedDocument'
2
2
 
3
- describe('Getting the shared document id', () => {
4
- const mockClient = {
3
+ function setupClient(verbs = []) {
4
+ return {
5
5
  collection: () => ({
6
6
  getOwnPermissions: jest.fn().mockReturnValue({
7
7
  data: {
@@ -9,14 +9,14 @@ describe('Getting the shared document id', () => {
9
9
  permissions: {
10
10
  collection: {
11
11
  type: 'io.cozy.photos.albums',
12
- verbs: ['GET'],
12
+ verbs,
13
13
  values: ['myshareid']
14
14
  },
15
15
  files: {
16
16
  selector: 'referenced_by',
17
17
  type: 'io.cozy.files',
18
18
  values: ['io.cozy.photos.albums/myshareid'],
19
- verbs: ['GET']
19
+ verbs
20
20
  }
21
21
  }
22
22
  }
@@ -24,9 +24,30 @@ describe('Getting the shared document id', () => {
24
24
  })
25
25
  })
26
26
  }
27
+ }
27
28
 
29
+ describe('Getting the shared document', () => {
28
30
  it('should get the id', async () => {
29
- const id = await getSharedDocument(mockClient)
31
+ const client = setupClient(['GET'])
32
+ const { id } = await getSharedDocument(client)
30
33
  expect(id).toEqual('myshareid')
31
34
  })
35
+
36
+ it('should return isReadOnly is true when we have only a GET permission', async () => {
37
+ const client = setupClient(['GET'])
38
+ const { isReadOnly } = await getSharedDocument(client)
39
+ expect(isReadOnly).toBeTruthy()
40
+ })
41
+
42
+ it('should return isReadOnly is false when we have an ALL permission', async () => {
43
+ const client = setupClient(['ALL'])
44
+ const { isReadOnly } = await getSharedDocument(client)
45
+ expect(isReadOnly).toBeFalsy()
46
+ })
47
+
48
+ it('should return isReadOnly is false when we have a PATCH permission', async () => {
49
+ const client = setupClient(['GET', 'PATCH', 'PUT'])
50
+ const { isReadOnly } = await getSharedDocument(client)
51
+ expect(isReadOnly).toBeFalsy()
52
+ })
32
53
  })
@@ -1,4 +1,5 @@
1
1
  import get from 'lodash/get'
2
+
2
3
  import { models } from 'cozy-client'
3
4
 
4
5
  export const checkIsReadOnlyPermissions = permissions => {
@@ -1,12 +1,11 @@
1
1
  import { Q } from 'cozy-client'
2
2
 
3
+ import { fetchFilesPaths } from './files'
3
4
  import {
4
5
  updateInternalObjectFromRealtime,
5
6
  normalizeDocFromRealtime
6
7
  } from './realtime'
7
-
8
8
  import { addSharing, updateSharing } from '../state'
9
- import { fetchFilesPaths } from './files'
10
9
 
11
10
  export const getSharingObject = (internalSharing, sharing) => {
12
11
  if (internalSharing) {
@@ -1,5 +1,6 @@
1
- import { Contact } from '../models'
2
1
  import { models } from 'cozy-client'
2
+
3
+ import { Contact } from '../models'
3
4
  export const countNewRecipients = (currentRecipients, newRecipients) => {
4
5
  return newRecipients.filter(contact => {
5
6
  const email = models.contact.getPrimaryEmail(contact)
package/src/index.jsx CHANGED
@@ -1,6 +1,6 @@
1
+ import SharingProvider from './SharingProvider'
1
2
  import SharingContext from './context'
2
3
  import withLocales from './withLocales'
3
- import SharingProvider from './SharingProvider'
4
4
 
5
5
  export default SharingProvider
6
6
 
package/src/state.js CHANGED
@@ -349,18 +349,14 @@ const getApps = state => state.apps
349
349
 
350
350
  export const hasSharedParent = (state, documentPath) => {
351
351
  if (!state.sharedPaths) {
352
- // eslint-disable-next-line
353
- console.log('hasSharedParent should not occur', state, documentPath)
354
- return false
352
+ return false // hasSharedParent should not occur
355
353
  }
356
354
  return state.sharedPaths.some(path => documentPath.indexOf(`${path}/`) === 0)
357
355
  }
358
356
 
359
357
  export const hasSharedChild = (state, documentPath) => {
360
358
  if (!state.sharedPaths) {
361
- // eslint-disable-next-line
362
- console.log('hasSharedChild should not occur', state, documentPath)
363
- return false
359
+ return false // hasSharedChild should not occur
364
360
  }
365
361
  const ret = state.sharedPaths.some(
366
362
  path => path.indexOf(`${documentPath}/`) === 0
package/src/state.spec.js CHANGED
@@ -16,7 +16,6 @@ import reducer, {
16
16
  getPermissionDocIds,
17
17
  getDocumentSharingType
18
18
  } from './state'
19
-
20
19
  import {
21
20
  SHARING_1,
22
21
  SHARING_2,
@@ -1,4 +1,5 @@
1
1
  import React from 'react'
2
+
2
3
  import { I18n, translate } from 'cozy-ui/transpiled/react/I18n'
3
4
 
4
5
  const locales = {
package/test/AppLike.jsx CHANGED
@@ -1,8 +1,8 @@
1
1
  import React from 'react'
2
2
 
3
- import { BreakpointsProvider } from 'cozy-ui/transpiled/react/hooks/useBreakpoints'
4
- import { I18n } from 'cozy-ui/transpiled/react/I18n'
5
3
  import { CozyProvider, createMockClient } from 'cozy-client'
4
+ import { I18n } from 'cozy-ui/transpiled/react/I18n'
5
+ import { BreakpointsProvider } from 'cozy-ui/transpiled/react/hooks/useBreakpoints'
6
6
 
7
7
  import langEn from '../locales/en.json'
8
8