cozy-sharing 11.0.0 → 11.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 +25 -0
- package/dist/components/Avatar/GroupAvatar.js +13 -0
- package/dist/components/Avatar/GroupAvatar.stories.js +10 -0
- package/dist/components/Avatar/MemberAvatar.js +20 -1
- package/dist/components/Recipient/GroupRecipient.js +49 -0
- package/dist/components/Recipient/GroupRecipient.stories.js +41 -0
- package/dist/components/Recipient/GroupRecipientPermissions.js +71 -0
- package/dist/components/Recipient/GroupRecipientPermissions.stories.js +37 -0
- package/dist/components/Recipient/MemberRecipient.stories.js +11 -1
- package/dist/components/Recipient/MemberRecipientPermissions.js +31 -40
- package/dist/components/Recipient/MemberRecipientPermissions.stories.js +30 -4
- package/dist/components/Recipient/RecipientList.js +16 -1
- package/dist/components/Recipient/RecipientList.stories.js +28 -0
- package/dist/components/Recipient/actions/permission.js +33 -0
- package/dist/components/Recipient/actions/revokeGroup.js +41 -0
- package/dist/components/Recipient/actions/revokeMember.js +41 -0
- package/dist/components/ShareByEmail.js +8 -29
- package/dist/components/ShareByEmail.spec.js +1 -1
- package/dist/components/ShareDialogCozyToCozy.js +2 -2
- package/dist/components/ShareDialogCozyToCozy.spec.js +1 -1
- package/dist/components/ShareDialogTwoStepsConfirmationContainer.js +2 -2
- package/dist/components/ShareDialogTwoStepsConfirmationContainer.spec.js +1 -1
- package/dist/components/ShareModal/EditableSharingModal.js +43 -42
- package/dist/components/ShareModal/EditableSharingModal.spec.js +2 -2
- package/dist/components/ShareModal.js +4 -4
- package/dist/components/ShareRecipientsInput.js +7 -7
- package/dist/components/ShareRecipientsInput.spec.js +2 -2
- package/dist/helpers/recipients.js +38 -0
- package/dist/helpers/successMessage.spec.js +1 -1
- package/dist/propTypes.js +1 -1
- package/dist/queries/queries.js +1 -1
- package/dist/state.js +58 -2
- package/dist/state.spec.js +190 -10
- package/locales/en.json +24 -30
- package/locales/fr.json +24 -30
- package/package.json +2 -2
- package/src/components/Avatar/GroupAvatar.jsx +10 -0
- package/src/components/Avatar/GroupAvatar.stories.jsx +13 -0
- package/src/components/Avatar/MemberAvatar.jsx +11 -0
- package/src/components/Recipient/GroupRecipient.jsx +56 -0
- package/src/components/Recipient/GroupRecipient.stories.jsx +38 -0
- package/src/components/Recipient/GroupRecipientPermissions.jsx +77 -0
- package/src/components/Recipient/GroupRecipientPermissions.stories.jsx +41 -0
- package/src/components/Recipient/MemberRecipient.stories.jsx +12 -1
- package/src/components/Recipient/MemberRecipientPermissions.jsx +37 -53
- package/src/components/Recipient/MemberRecipientPermissions.stories.jsx +31 -4
- package/src/components/Recipient/RecipientList.jsx +18 -1
- package/src/components/Recipient/RecipientList.stories.jsx +34 -0
- package/src/components/Recipient/actions/permission.js +31 -0
- package/src/components/Recipient/actions/revokeGroup.js +39 -0
- package/src/components/Recipient/actions/revokeMember.js +39 -0
- package/src/components/ShareByEmail.jsx +14 -32
- package/src/components/ShareByEmail.spec.jsx +1 -1
- package/src/components/ShareDialogCozyToCozy.jsx +2 -2
- package/src/components/ShareDialogCozyToCozy.spec.jsx +1 -1
- package/src/components/ShareDialogTwoStepsConfirmationContainer.jsx +2 -2
- package/src/components/ShareDialogTwoStepsConfirmationContainer.spec.jsx +1 -1
- package/src/components/ShareModal/EditableSharingModal.jsx +48 -46
- package/src/components/ShareModal/EditableSharingModal.spec.jsx +1 -1
- package/src/components/ShareModal.jsx +4 -4
- package/src/components/ShareRecipientsInput.jsx +9 -9
- package/src/components/ShareRecipientsInput.spec.jsx +2 -2
- package/src/helpers/recipients.js +45 -0
- package/src/helpers/successMessage.spec.js +1 -1
- package/src/propTypes.js +1 -1
- package/src/queries/queries.js +1 -1
- package/src/state.js +53 -2
- package/src/state.spec.js +230 -9
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import React, { forwardRef } from 'react';
|
|
3
|
+
import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem';
|
|
4
|
+
import Icon from 'cozy-ui/transpiled/react/Icon';
|
|
5
|
+
import TrashIcon from 'cozy-ui/transpiled/react/Icons/Trash';
|
|
6
|
+
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
|
|
7
|
+
import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
|
|
8
|
+
import Typography from 'cozy-ui/transpiled/react/Typography';
|
|
9
|
+
|
|
10
|
+
var revokeMember = function revokeMember(_ref) {
|
|
11
|
+
var t = _ref.t,
|
|
12
|
+
isOwner = _ref.isOwner,
|
|
13
|
+
handleRevocation = _ref.handleRevocation;
|
|
14
|
+
var revokeType = isOwner ? 'revoke' : 'revokeSelf';
|
|
15
|
+
var title = t("RevokeMemberItem.".concat(revokeType, ".title"));
|
|
16
|
+
var desc = t("RevokeMemberItem.".concat(revokeType, ".desc"));
|
|
17
|
+
var icon = TrashIcon;
|
|
18
|
+
return {
|
|
19
|
+
name: 'revokeMember',
|
|
20
|
+
label: title,
|
|
21
|
+
icon: icon,
|
|
22
|
+
action: function action() {
|
|
23
|
+
handleRevocation();
|
|
24
|
+
},
|
|
25
|
+
Component: /*#__PURE__*/forwardRef(function RevokeMemberItem(props, ref) {
|
|
26
|
+
return /*#__PURE__*/React.createElement(ActionsMenuItem, _extends({}, props, {
|
|
27
|
+
ref: ref
|
|
28
|
+
}), /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Icon, {
|
|
29
|
+
icon: icon,
|
|
30
|
+
color: "var(--errorColor)"
|
|
31
|
+
})), /*#__PURE__*/React.createElement(ListItemText, {
|
|
32
|
+
primary: /*#__PURE__*/React.createElement(Typography, {
|
|
33
|
+
color: "error"
|
|
34
|
+
}, title),
|
|
35
|
+
secondary: desc
|
|
36
|
+
}));
|
|
37
|
+
})
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export { revokeMember };
|
|
@@ -2,10 +2,10 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
|
2
2
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
3
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
4
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
|
-
import get from 'lodash/get';
|
|
6
5
|
import PropTypes from 'prop-types';
|
|
7
6
|
import React, { useState } from 'react';
|
|
8
7
|
import { useClient } from 'cozy-client';
|
|
8
|
+
import flag from 'cozy-flags';
|
|
9
9
|
import Alerter from 'cozy-ui/transpiled/react/deprecated/Alerter';
|
|
10
10
|
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
|
|
11
11
|
import ShareRecipientsInput from './ShareRecipientsInput';
|
|
@@ -13,10 +13,9 @@ import { ShareRecipientsLimitModal } from './ShareRecipientsLimitModal';
|
|
|
13
13
|
import ShareSubmit from './Sharesubmit';
|
|
14
14
|
import ShareTypeSelect from './Sharetypeselect';
|
|
15
15
|
import { getOrCreateFromArray } from '../helpers/contacts';
|
|
16
|
-
import { hasReachRecipientsLimit } from '../helpers/recipients';
|
|
16
|
+
import { mergeRecipients, spreadGroupAndMergeRecipients, hasReachRecipientsLimit } from '../helpers/recipients';
|
|
17
17
|
import { getSuccessMessage } from '../helpers/successMessage';
|
|
18
|
-
import {
|
|
19
|
-
import { contactsResponseType, groupsResponseType } from '../propTypes';
|
|
18
|
+
import { contactsResponseType, contactGroupsResponseType } from '../propTypes';
|
|
20
19
|
import { isReadOnlySharing } from '../state';
|
|
21
20
|
var styles = {
|
|
22
21
|
"share-modal-content": "share__share-modal-content___1iqEq",
|
|
@@ -43,7 +42,7 @@ var styles = {
|
|
|
43
42
|
};
|
|
44
43
|
export var ShareByEmail = function ShareByEmail(_ref) {
|
|
45
44
|
var contacts = _ref.contacts,
|
|
46
|
-
|
|
45
|
+
contactGroups = _ref.contactGroups,
|
|
47
46
|
document = _ref.document,
|
|
48
47
|
sharingDesc = _ref.sharingDesc,
|
|
49
48
|
onShare = _ref.onShare,
|
|
@@ -86,28 +85,8 @@ export var ShareByEmail = function ShareByEmail(_ref) {
|
|
|
86
85
|
};
|
|
87
86
|
|
|
88
87
|
var onRecipientPick = function onRecipientPick(recipient) {
|
|
89
|
-
var
|
|
90
|
-
|
|
91
|
-
if (recipient._type === Group.doctype) {
|
|
92
|
-
var groupId = recipient.id;
|
|
93
|
-
contactsToAdd = contacts.data.filter(function (contact) {
|
|
94
|
-
var contactGroupIds = get(contact, 'relationships.groups.data', []).map(function (group) {
|
|
95
|
-
return group._id;
|
|
96
|
-
});
|
|
97
|
-
return contactGroupIds.includes(groupId);
|
|
98
|
-
});
|
|
99
|
-
} else {
|
|
100
|
-
contactsToAdd = [recipient];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
var filtered = contactsToAdd.filter(function (contact) {
|
|
104
|
-
return contact.email && contact.email.length > 0 || contact.cozy && contact.cozy.length > 0;
|
|
105
|
-
}).filter(function (contact) {
|
|
106
|
-
return !recipients.find(function (r) {
|
|
107
|
-
return r === contact;
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
setRecipients([].concat(_toConsumableArray(recipients), _toConsumableArray(filtered)));
|
|
88
|
+
var mergedRecipients = flag('sharing.show-recipient-groups') ? mergeRecipients(recipients, recipient) : spreadGroupAndMergeRecipients(recipients, recipient, contacts);
|
|
89
|
+
setRecipients(mergedRecipients);
|
|
111
90
|
};
|
|
112
91
|
|
|
113
92
|
var onRecipientRemove = function onRecipientRemove(recipient) {
|
|
@@ -226,7 +205,7 @@ export var ShareByEmail = function ShareByEmail(_ref) {
|
|
|
226
205
|
return onRecipientRemove(recipient);
|
|
227
206
|
},
|
|
228
207
|
contacts: contacts,
|
|
229
|
-
|
|
208
|
+
contactGroups: contactGroups,
|
|
230
209
|
recipients: recipients
|
|
231
210
|
})), showShareControl && /*#__PURE__*/React.createElement("div", {
|
|
232
211
|
className: styles['share-type-control']
|
|
@@ -248,7 +227,7 @@ export var ShareByEmail = function ShareByEmail(_ref) {
|
|
|
248
227
|
ShareByEmail.propTypes = {
|
|
249
228
|
currentRecipients: PropTypes.arrayOf(PropTypes.object),
|
|
250
229
|
contacts: contactsResponseType.isRequired,
|
|
251
|
-
|
|
230
|
+
contactGroups: contactGroupsResponseType.isRequired,
|
|
252
231
|
document: PropTypes.object.isRequired,
|
|
253
232
|
documentType: PropTypes.string.isRequired,
|
|
254
233
|
sharingDesc: PropTypes.string.isRequired,
|
|
@@ -38,10 +38,10 @@ var styles = {
|
|
|
38
38
|
|
|
39
39
|
var SharingContent = function SharingContent(_ref) {
|
|
40
40
|
var contacts = _ref.contacts,
|
|
41
|
+
contactGroups = _ref.contactGroups,
|
|
41
42
|
createContact = _ref.createContact,
|
|
42
43
|
document = _ref.document,
|
|
43
44
|
documentType = _ref.documentType,
|
|
44
|
-
groups = _ref.groups,
|
|
45
45
|
hasSharedParent = _ref.hasSharedParent,
|
|
46
46
|
isOwner = _ref.isOwner,
|
|
47
47
|
needsContactsPermission = _ref.needsContactsPermission,
|
|
@@ -75,11 +75,11 @@ var SharingContent = function SharingContent(_ref) {
|
|
|
75
75
|
className: "u-mb-1-half"
|
|
76
76
|
}, t('Share.contacts.whoHasAccess')), showShareByEmail && /*#__PURE__*/React.createElement(DumbShareByEmail, {
|
|
77
77
|
contacts: contacts,
|
|
78
|
+
contactGroups: contactGroups,
|
|
78
79
|
createContact: createContact,
|
|
79
80
|
currentRecipients: recipients,
|
|
80
81
|
document: document,
|
|
81
82
|
documentType: documentType,
|
|
82
|
-
groups: groups,
|
|
83
83
|
needsContactsPermission: needsContactsPermission,
|
|
84
84
|
onShare: onShare,
|
|
85
85
|
sharing: sharing,
|
|
@@ -99,10 +99,10 @@ var RejectRecipientActions = function RejectRecipientActions(_ref3) {
|
|
|
99
99
|
|
|
100
100
|
var ShareDialogTwoStepsConfirmationContainer = function ShareDialogTwoStepsConfirmationContainer(_ref4) {
|
|
101
101
|
var contacts = _ref4.contacts,
|
|
102
|
+
contactGroups = _ref4.contactGroups,
|
|
102
103
|
createContact = _ref4.createContact,
|
|
103
104
|
document = _ref4.document,
|
|
104
105
|
documentType = _ref4.documentType,
|
|
105
|
-
groups = _ref4.groups,
|
|
106
106
|
hasSharedParent = _ref4.hasSharedParent,
|
|
107
107
|
isOwner = _ref4.isOwner,
|
|
108
108
|
link = _ref4.link,
|
|
@@ -241,10 +241,10 @@ var ShareDialogTwoStepsConfirmationContainer = function ShareDialogTwoStepsConfi
|
|
|
241
241
|
} else if (status === 'sharing') {
|
|
242
242
|
dialogContent = /*#__PURE__*/React.createElement(DialogContentOnShare, {
|
|
243
243
|
contacts: contacts,
|
|
244
|
+
contactGroups: contactGroups,
|
|
244
245
|
createContact: createContact,
|
|
245
246
|
document: document,
|
|
246
247
|
documentType: documentType,
|
|
247
|
-
groups: groups,
|
|
248
248
|
hasSharedParent: hasSharedParent,
|
|
249
249
|
isOwner: isOwner,
|
|
250
250
|
needsContactsPermission: needsContactsPermission,
|
|
@@ -4,10 +4,10 @@ var _excluded = ["document"];
|
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
5
|
import React from 'react';
|
|
6
6
|
import { useClient, useQueryAll } from 'cozy-client';
|
|
7
|
-
import SharingContext from '../../context';
|
|
8
7
|
import { useFetchDocumentPath } from '../../hooks/useFetchDocumentPath';
|
|
8
|
+
import { useSharingContext } from '../../hooks/useSharingContext';
|
|
9
9
|
import { Contact } from '../../models';
|
|
10
|
-
import { buildContactsQuery,
|
|
10
|
+
import { buildContactsQuery, buildContactGroupsQuery } from '../../queries/queries';
|
|
11
11
|
import { default as DumbShareModal } from '../ShareModal';
|
|
12
12
|
export var EditableSharingModal = function EditableSharingModal(_ref) {
|
|
13
13
|
var document = _ref.document,
|
|
@@ -17,46 +17,47 @@ export var EditableSharingModal = function EditableSharingModal(_ref) {
|
|
|
17
17
|
var documentPath = useFetchDocumentPath(client, document);
|
|
18
18
|
var contactsQuery = buildContactsQuery();
|
|
19
19
|
var contactsResult = useQueryAll(contactsQuery.definition, contactsQuery.options);
|
|
20
|
-
var
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
20
|
+
var contactGroupsQuery = buildContactGroupsQuery();
|
|
21
|
+
var contactGroupsResult = useQueryAll(contactGroupsQuery.definition, contactGroupsQuery.options);
|
|
22
|
+
|
|
23
|
+
var _useSharingContext = useSharingContext(),
|
|
24
|
+
documentType = _useSharingContext.documentType,
|
|
25
|
+
getDocumentPermissions = _useSharingContext.getDocumentPermissions,
|
|
26
|
+
getRecipients = _useSharingContext.getRecipients,
|
|
27
|
+
getSharingForSelf = _useSharingContext.getSharingForSelf,
|
|
28
|
+
getSharingLink = _useSharingContext.getSharingLink,
|
|
29
|
+
hasSharedChild = _useSharingContext.hasSharedChild,
|
|
30
|
+
hasSharedParent = _useSharingContext.hasSharedParent,
|
|
31
|
+
isOwner = _useSharingContext.isOwner,
|
|
32
|
+
revoke = _useSharingContext.revoke,
|
|
33
|
+
revokeSelf = _useSharingContext.revokeSelf,
|
|
34
|
+
revokeSharingLink = _useSharingContext.revokeSharingLink,
|
|
35
|
+
share = _useSharingContext.share,
|
|
36
|
+
shareByLink = _useSharingContext.shareByLink,
|
|
37
|
+
updateDocumentPermissions = _useSharingContext.updateDocumentPermissions;
|
|
38
|
+
|
|
39
|
+
return /*#__PURE__*/React.createElement(DumbShareModal, _extends({
|
|
40
|
+
contacts: contactsResult,
|
|
41
|
+
contactGroups: contactGroupsResult,
|
|
42
|
+
createContact: function createContact(contact) {
|
|
43
|
+
return client.create(Contact.doctype, contact);
|
|
44
|
+
},
|
|
45
|
+
document: document,
|
|
46
|
+
documentType: documentType,
|
|
47
|
+
hasSharedChild: documentPath && hasSharedChild(documentPath),
|
|
48
|
+
hasSharedParent: documentPath && hasSharedParent(documentPath),
|
|
49
|
+
isOwner: isOwner(document.id),
|
|
50
|
+
link: getSharingLink(document.id),
|
|
51
|
+
onRevoke: revoke,
|
|
52
|
+
onRevokeLink: revokeSharingLink,
|
|
53
|
+
onRevokeSelf: revokeSelf,
|
|
54
|
+
onShare: share,
|
|
55
|
+
onShareByLink: shareByLink,
|
|
56
|
+
onUpdateShareLinkPermissions: updateDocumentPermissions,
|
|
57
|
+
permissions: getDocumentPermissions(document.id),
|
|
58
|
+
recipients: getRecipients(document.id),
|
|
59
|
+
sharing: getSharingForSelf(document.id)
|
|
60
|
+
}, rest));
|
|
60
61
|
};
|
|
61
62
|
EditableSharingModal.propTypes = {
|
|
62
63
|
document: PropTypes.object
|
|
@@ -3,14 +3,14 @@ import React from 'react';
|
|
|
3
3
|
import flag from 'cozy-flags';
|
|
4
4
|
import ShareDialogCozyToCozy from './ShareDialogCozyToCozy';
|
|
5
5
|
import ShareDialogOnlyByLink from './ShareDialogOnlyByLink';
|
|
6
|
-
import { contactsResponseType,
|
|
6
|
+
import { contactsResponseType, contactGroupsResponseType } from '../propTypes';
|
|
7
7
|
export var ShareModal = function ShareModal(_ref) {
|
|
8
8
|
var contacts = _ref.contacts,
|
|
9
|
+
contactGroups = _ref.contactGroups,
|
|
9
10
|
createContact = _ref.createContact,
|
|
10
11
|
document = _ref.document,
|
|
11
12
|
_ref$documentType = _ref.documentType,
|
|
12
13
|
documentType = _ref$documentType === void 0 ? 'Document' : _ref$documentType,
|
|
13
|
-
groups = _ref.groups,
|
|
14
14
|
hasSharedChild = _ref.hasSharedChild,
|
|
15
15
|
hasSharedParent = _ref.hasSharedParent,
|
|
16
16
|
isOwner = _ref.isOwner,
|
|
@@ -48,10 +48,10 @@ export var ShareModal = function ShareModal(_ref) {
|
|
|
48
48
|
permissions: permissions
|
|
49
49
|
}) : /*#__PURE__*/React.createElement(ShareDialogCozyToCozy, {
|
|
50
50
|
contacts: contacts,
|
|
51
|
+
contactGroups: contactGroups,
|
|
51
52
|
createContact: createContact,
|
|
52
53
|
document: document,
|
|
53
54
|
documentType: documentType,
|
|
54
|
-
groups: groups,
|
|
55
55
|
hasSharedParent: hasSharedParent,
|
|
56
56
|
isOwner: isOwner,
|
|
57
57
|
link: link,
|
|
@@ -77,10 +77,10 @@ export var ShareModal = function ShareModal(_ref) {
|
|
|
77
77
|
export default ShareModal;
|
|
78
78
|
ShareModal.propTypes = {
|
|
79
79
|
contacts: contactsResponseType.isRequired,
|
|
80
|
+
contactGroups: contactGroupsResponseType.isRequired,
|
|
80
81
|
createContact: PropTypes.func.isRequired,
|
|
81
82
|
document: PropTypes.object.isRequired,
|
|
82
83
|
documentType: PropTypes.string,
|
|
83
|
-
groups: groupsResponseType.isRequired,
|
|
84
84
|
hasSharedChild: PropTypes.bool,
|
|
85
85
|
hasSharedParent: PropTypes.bool,
|
|
86
86
|
isOwner: PropTypes.bool,
|
|
@@ -3,11 +3,11 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import React, { useState, useEffect } from 'react';
|
|
5
5
|
import ShareAutosuggest from './ShareAutosuggest';
|
|
6
|
-
import { contactsResponseType,
|
|
6
|
+
import { contactsResponseType, contactGroupsResponseType } from '../propTypes';
|
|
7
7
|
|
|
8
8
|
var ShareRecipientsInput = function ShareRecipientsInput(_ref) {
|
|
9
9
|
var contacts = _ref.contacts,
|
|
10
|
-
|
|
10
|
+
contactGroups = _ref.contactGroups,
|
|
11
11
|
recipients = _ref.recipients,
|
|
12
12
|
placeholder = _ref.placeholder,
|
|
13
13
|
onPick = _ref.onPick,
|
|
@@ -19,13 +19,13 @@ var ShareRecipientsInput = function ShareRecipientsInput(_ref) {
|
|
|
19
19
|
setLoading = _useState2[1];
|
|
20
20
|
|
|
21
21
|
useEffect(function () {
|
|
22
|
-
if (loading && !contacts.hasMore && contacts.fetchStatus === 'loaded' && !
|
|
22
|
+
if (loading && !contacts.hasMore && contacts.fetchStatus === 'loaded' && !contactGroups.hasMore && contactGroups.fetchStatus === 'loaded') {
|
|
23
23
|
setLoading(false);
|
|
24
24
|
}
|
|
25
|
-
}, [contacts,
|
|
25
|
+
}, [contacts, contactGroups, loading]);
|
|
26
26
|
|
|
27
27
|
var onShareAutosuggestFocus = function onShareAutosuggestFocus() {
|
|
28
|
-
if (contacts.hasMore || contacts.fetchStatus === 'loading' ||
|
|
28
|
+
if (contacts.hasMore || contacts.fetchStatus === 'loading' || contactGroups.hasMore || contactGroups.fetchStatus === 'loading') {
|
|
29
29
|
setLoading(true);
|
|
30
30
|
}
|
|
31
31
|
};
|
|
@@ -35,7 +35,7 @@ var ShareRecipientsInput = function ShareRecipientsInput(_ref) {
|
|
|
35
35
|
if (contacts.hasMore || contacts.fetchStatus === 'loading') {
|
|
36
36
|
return contacts.data;
|
|
37
37
|
} else {
|
|
38
|
-
return [].concat(_toConsumableArray(contacts.data), _toConsumableArray(
|
|
38
|
+
return [].concat(_toConsumableArray(contacts.data), _toConsumableArray(contactGroups.data));
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
|
|
@@ -52,7 +52,7 @@ var ShareRecipientsInput = function ShareRecipientsInput(_ref) {
|
|
|
52
52
|
|
|
53
53
|
ShareRecipientsInput.propTypes = {
|
|
54
54
|
contacts: contactsResponseType.isRequired,
|
|
55
|
-
|
|
55
|
+
contactGroups: contactGroupsResponseType.isRequired,
|
|
56
56
|
recipients: PropTypes.array,
|
|
57
57
|
placeholder: PropTypes.string,
|
|
58
58
|
onPick: PropTypes.func.isRequired,
|
|
@@ -28,7 +28,7 @@ describe('ShareRecipientsInput component', function () {
|
|
|
28
28
|
}
|
|
29
29
|
}]
|
|
30
30
|
},
|
|
31
|
-
|
|
31
|
+
contactGroups: {
|
|
32
32
|
id: 'groups',
|
|
33
33
|
fetchStatus: 'loaded',
|
|
34
34
|
hasMore: false,
|
|
@@ -85,7 +85,7 @@ describe('ShareRecipientsInput component', function () {
|
|
|
85
85
|
}
|
|
86
86
|
}]
|
|
87
87
|
},
|
|
88
|
-
|
|
88
|
+
contactGroups: {
|
|
89
89
|
id: 'groups',
|
|
90
90
|
fetchStatus: 'loaded',
|
|
91
91
|
hasMore: false,
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
1
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
3
|
|
|
3
4
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
5
|
|
|
5
6
|
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
7
|
|
|
8
|
+
import get from 'lodash/get';
|
|
7
9
|
import flag from 'cozy-flags';
|
|
10
|
+
import { Group } from '../models';
|
|
8
11
|
export var filterAndReworkRecipients = function filterAndReworkRecipients(recipients, previousRecipients) {
|
|
9
12
|
return recipients.filter(function (recipient) {
|
|
10
13
|
return recipient.status !== 'owner';
|
|
@@ -50,4 +53,39 @@ export var hasReachRecipientsLimit = function hasReachRecipientsLimit(current, n
|
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
return false;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Merges the recipients list with a new recipient and their associated contacts.
|
|
59
|
+
* @param {object[]} recipients - The list of recipients.
|
|
60
|
+
* @param {object} recipient - The new recipient.
|
|
61
|
+
* @param {object[]} contacts - The list of contacts.
|
|
62
|
+
* @returns {object[]} - The merged recipients list.
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
export var spreadGroupAndMergeRecipients = function spreadGroupAndMergeRecipients(recipients, newRecipient, contacts) {
|
|
66
|
+
var contactsToAdd;
|
|
67
|
+
|
|
68
|
+
if (newRecipient._type === Group.doctype) {
|
|
69
|
+
var groupId = newRecipient.id;
|
|
70
|
+
contactsToAdd = contacts.data.filter(function (contact) {
|
|
71
|
+
var contactGroupIds = get(contact, 'relationships.groups.data', []).map(function (group) {
|
|
72
|
+
return group._id;
|
|
73
|
+
});
|
|
74
|
+
return contactGroupIds.includes(groupId);
|
|
75
|
+
});
|
|
76
|
+
} else {
|
|
77
|
+
contactsToAdd = [newRecipient];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
var filtered = contactsToAdd.filter(function (contact) {
|
|
81
|
+
return contact.email && contact.email.length > 0 || contact.cozy && contact.cozy.length > 0;
|
|
82
|
+
}).filter(function (contact) {
|
|
83
|
+
return !recipients.find(function (r) {
|
|
84
|
+
return r === contact;
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
return [].concat(_toConsumableArray(recipients), _toConsumableArray(filtered));
|
|
88
|
+
};
|
|
89
|
+
export var mergeRecipients = function mergeRecipients(recipients, newRecipient) {
|
|
90
|
+
return [].concat(_toConsumableArray(recipients), [newRecipient]);
|
|
53
91
|
};
|
package/dist/propTypes.js
CHANGED
|
@@ -12,7 +12,7 @@ export var contactsResponseType = PropTypes.shape({
|
|
|
12
12
|
lastFetch: PropTypes.number,
|
|
13
13
|
lastUpdate: PropTypes.number
|
|
14
14
|
});
|
|
15
|
-
export var
|
|
15
|
+
export var contactGroupsResponseType = PropTypes.shape({
|
|
16
16
|
count: PropTypes.number,
|
|
17
17
|
data: PropTypes.arrayOf(Group.propType),
|
|
18
18
|
definition: PropTypes.object,
|
package/dist/queries/queries.js
CHANGED
|
@@ -53,7 +53,7 @@ export var buildContactsQuery = function buildContactsQuery() {
|
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
55
|
};
|
|
56
|
-
export var
|
|
56
|
+
export var buildContactGroupsQuery = function buildContactGroupsQuery() {
|
|
57
57
|
return {
|
|
58
58
|
definition: Q(Group.doctype),
|
|
59
59
|
options: {
|
package/dist/state.js
CHANGED
|
@@ -11,6 +11,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
11
11
|
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; }
|
|
12
12
|
|
|
13
13
|
import get from 'lodash/get';
|
|
14
|
+
import flag from 'cozy-flags';
|
|
14
15
|
var RECEIVE_SHARINGS = 'RECEIVE_SHARINGS';
|
|
15
16
|
var ADD_SHARING = 'ADD_SHARING';
|
|
16
17
|
var UPDATE_SHARING = 'UPDATE_SHARING';
|
|
@@ -380,13 +381,24 @@ export var getOwner = function getOwner(state, docId) {
|
|
|
380
381
|
});
|
|
381
382
|
};
|
|
382
383
|
export var getRecipients = function getRecipients(state, docId) {
|
|
383
|
-
var
|
|
384
|
+
var sharings = getDocumentSharings(state, docId);
|
|
385
|
+
|
|
386
|
+
if (flag('sharing.show-recipient-groups')) {
|
|
387
|
+
return getRecipientsWithGroups(sharings, docId);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
return getRecipientsWithoutGroups(sharings, docId);
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
var getRecipientsWithoutGroups = function getRecipientsWithoutGroups(sharings, docId) {
|
|
394
|
+
var recipients = sharings.map(function (sharing) {
|
|
384
395
|
var type = getDocumentSharingType(sharing, docId);
|
|
385
396
|
return sharing.attributes.members.map(function (m, idx) {
|
|
386
397
|
return _objectSpread(_objectSpread({}, m), {}, {
|
|
398
|
+
index: "sharing-".concat(sharing.id, "-member-").concat(idx),
|
|
387
399
|
type: m.read_only ? 'one-way' : type,
|
|
388
400
|
sharingId: sharing.id,
|
|
389
|
-
|
|
401
|
+
memberIndex: idx,
|
|
390
402
|
avatarPath: "/sharings/".concat(sharing.id, "/recipients/").concat(idx, "/avatar")
|
|
391
403
|
});
|
|
392
404
|
});
|
|
@@ -404,6 +416,50 @@ export var getRecipients = function getRecipients(state, docId) {
|
|
|
404
416
|
|
|
405
417
|
return recipients;
|
|
406
418
|
};
|
|
419
|
+
|
|
420
|
+
export var getRecipientsWithGroups = function getRecipientsWithGroups(sharings, docId) {
|
|
421
|
+
var recipients = sharings.flatMap(function (sharing) {
|
|
422
|
+
var _sharing$attributes$g;
|
|
423
|
+
|
|
424
|
+
var type = getDocumentSharingType(sharing, docId);
|
|
425
|
+
var sharingId = sharing.id;
|
|
426
|
+
var members = sharing.attributes.members.map(function (m, idx) {
|
|
427
|
+
return _objectSpread(_objectSpread({}, m), {}, {
|
|
428
|
+
type: m.read_only ? 'one-way' : type,
|
|
429
|
+
sharingId: sharingId,
|
|
430
|
+
index: "sharing-".concat(sharing.id, "-member-").concat(idx),
|
|
431
|
+
memberIndex: idx,
|
|
432
|
+
avatarPath: "/sharings/".concat(sharingId, "/recipients/").concat(idx, "/avatar")
|
|
433
|
+
});
|
|
434
|
+
});
|
|
435
|
+
var groups = ((_sharing$attributes$g = sharing.attributes.groups) === null || _sharing$attributes$g === void 0 ? void 0 : _sharing$attributes$g.map(function (g, idx) {
|
|
436
|
+
return _objectSpread(_objectSpread({}, g), {}, {
|
|
437
|
+
sharingId: sharingId,
|
|
438
|
+
index: "sharing-".concat(sharing.id, "-group-").concat(idx),
|
|
439
|
+
groupIndex: idx,
|
|
440
|
+
owner: members[g.addedBy],
|
|
441
|
+
members: members.filter(function (member) {
|
|
442
|
+
var _member$groups;
|
|
443
|
+
|
|
444
|
+
return (_member$groups = member.groups) === null || _member$groups === void 0 ? void 0 : _member$groups.includes(idx);
|
|
445
|
+
})
|
|
446
|
+
});
|
|
447
|
+
}).filter(function (g) {
|
|
448
|
+
return !g.revoked;
|
|
449
|
+
})) || [];
|
|
450
|
+
return [].concat(_toConsumableArray(members.filter(function (m) {
|
|
451
|
+
return !m.only_in_groups && m.status !== 'revoked';
|
|
452
|
+
})), _toConsumableArray(groups));
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
if (recipients[0] && recipients[0].status === 'owner') {
|
|
456
|
+
return [recipients[0]].concat(_toConsumableArray(recipients.filter(function (r) {
|
|
457
|
+
return r.status !== 'owner';
|
|
458
|
+
})));
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
return recipients;
|
|
462
|
+
};
|
|
407
463
|
export var getSharingLink = function getSharingLink(state, docId, documentType) {
|
|
408
464
|
// This shouldn't have happened, but unfortunately some duplicate sharing links have been created in the past
|
|
409
465
|
var perms = getDocumentPermissions(state, docId);
|