cozy-sharing 32.3.1 → 33.0.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 +22 -0
- package/dist/components/FederatedFolder/FederatedFolderModal.js +56 -19
- package/dist/components/FederatedFolder/FederatedFolderModal.spec.js +101 -254
- package/dist/components/Recipient/RecipientList.js +0 -15
- package/dist/components/ShareModal/ShareModal.js +8 -8
- package/dist/components/SharedDrive/EditSharedDriveModal.js +32 -55
- package/dist/components/SharedDrive/SharedDriveForm.js +23 -5
- package/dist/components/SharedDrive/useSharedDrive.js +8 -37
- package/dist/components/SharedDrive/useSharedDrive.spec.js +8 -81
- package/dist/components/WhoHasAccess.js +4 -1
- package/dist/state.js +6 -1
- package/package.json +4 -4
- package/src/components/FederatedFolder/FederatedFolderModal.jsx +65 -19
- package/src/components/FederatedFolder/FederatedFolderModal.spec.jsx +28 -150
- package/src/components/Recipient/RecipientList.jsx +0 -18
- package/src/components/ShareModal/ShareModal.jsx +5 -5
- package/src/components/SharedDrive/EditSharedDriveModal.jsx +42 -47
- package/src/components/SharedDrive/SharedDriveForm.jsx +18 -2
- package/src/components/SharedDrive/useSharedDrive.js +15 -35
- package/src/components/SharedDrive/useSharedDrive.spec.js +4 -39
- package/src/components/WhoHasAccess.jsx +3 -1
- package/src/state.js +5 -1
- package/.claude/settings.local.json +0 -27
- package/AGENTS.md +0 -7
- package/dist/RefreshableSharings.spec.js +0 -40
- package/dist/assets/illustrations/illustration-shared-drives.svg +0 -1
- package/dist/components/EditLinkPermissionDialog.js +0 -72
- package/dist/components/EditLinkPermissionDialog.spec.js +0 -48
- package/dist/components/FederatedFolder/DumbFederatedFolderModal.js +0 -65
- package/dist/components/FederatedFolder/DumbFederatedFolderModal.spec.js +0 -107
- package/dist/components/FederatedFolder/FederatedFolderModal.jsx.tmp.179197.1773939270471 +0 -172
- package/dist/components/Recipient/actions/revokeGroup.js +0 -42
- package/dist/components/Recipient/actions/revokeMember.js +0 -42
- package/dist/components/Recipient/actions/revokeSharedDriveMember.js +0 -41
- package/dist/components/ShareModal/ShareModal copy.js +0 -43
- package/dist/components/ShareModal/ShareModal.spec.js +0 -197
- package/dist/components/ShareModal/ShareModalBatchContainer.js +0 -276
- package/dist/components/ShareModal/ShareModalBatchContainer.spec.js +0 -131
- package/dist/components/ShareModal/SharedDriveEditModal.js +0 -59
- package/dist/components/SharedDrive/DumbSharedDriveModal.js +0 -78
- package/dist/components/SharedDrive/DumbSharedDriveModal.spec.js +0 -126
- package/dist/components/SharedDrive/SharedDriveEditModal.js +0 -110
- package/dist/components/SharedDrive/SharedDriveModal copy.js +0 -356
- package/dist/components/SharedDrive/SharedDriveRecipient.js +0 -61
- package/dist/components/SharedDrive/SharedDriveRecipientPermissions.js +0 -109
- package/dist/components/SharedDrive/SharedDriveRecipientStatus.js +0 -22
- package/dist/components/SharedDrive/helpers.js +0 -102
- package/dist/components/SharedDrive/helpers.spec.js +0 -208
- package/dist/components/SharedDriveEditModal.js +0 -43
- package/dist/components/SharedFolder/DumbBatchSharedFolderModal.js +0 -145
- package/dist/components/SharedFolder/DumbBatchSharedFolderModal.spec.js +0 -321
- package/dist/components/SharedStatus.js +0 -61
- package/dist/components/SharedStatus.spec.js +0 -44
- package/dist/components/Sharesubmit.js +0 -28
- package/dist/components/__snapshots__/SharedStatus.spec.js.snap +0 -94
- package/dist/helpers/owner.js +0 -14
- package/dist/helpers/owner.spec.js +0 -34
- package/dist/hooks/useConfirmDiscardChanges.js +0 -33
- package/dist/hooks/useContactsAndGroups.js +0 -65
- package/dist/hooks/useSharedDrive.js +0 -130
- package/dist/hooks/useSharedDriveContactsAndGroups.js +0 -65
- package/dist/propTypes.js +0 -26
- package/dist/styles/shareddrive.styl +0 -8
- package/src/components/SharedDrive/SharedDriveRecipient.jsx +0 -62
- package/src/components/SharedDrive/SharedDriveRecipientPermissions.jsx +0 -78
- package/src/components/SharedDrive/SharedDriveRecipientStatus.jsx +0 -23
- package/src/components/SharedFolder/DumbBatchSharedFolderModal.jsx +0 -161
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
|
-
import PropTypes from 'prop-types';
|
|
6
|
-
import React, { useState } from 'react';
|
|
7
|
-
import { useI18n } from 'twake-i18n';
|
|
8
|
-
import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert';
|
|
9
|
-
import withLocales from '../../hoc/withLocales';
|
|
10
|
-
import { Contact } from '../../models';
|
|
11
|
-
import { ShareModal } from '../ShareModal';
|
|
12
|
-
/**
|
|
13
|
-
* Merge and deduplicate recipients arrays
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
var mergeAndDeduplicateRecipients = function mergeAndDeduplicateRecipients(arrays) {
|
|
17
|
-
var combinedArray = arrays.flat();
|
|
18
|
-
var seenIds = new Set();
|
|
19
|
-
return combinedArray.filter(function (item) {
|
|
20
|
-
if (!seenIds.has(item.id || item._id)) {
|
|
21
|
-
seenIds.add(item.id || item._id);
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return false;
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Container component that manages sharing recipients in batch mode.
|
|
30
|
-
* Instead of sharing immediately when adding recipients, it accumulates them
|
|
31
|
-
* and sends all at once when clicking the submit button.
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
export var ShareModalBatchContainer = withLocales(function (_ref) {
|
|
36
|
-
var document = _ref.document,
|
|
37
|
-
documentType = _ref.documentType,
|
|
38
|
-
isOwner = _ref.isOwner,
|
|
39
|
-
link = _ref.link,
|
|
40
|
-
permissions = _ref.permissions,
|
|
41
|
-
existingRecipients = _ref.recipients,
|
|
42
|
-
sharing = _ref.sharing,
|
|
43
|
-
sharingDesc = _ref.sharingDesc,
|
|
44
|
-
onClose = _ref.onClose,
|
|
45
|
-
onRevoke = _ref.onRevoke,
|
|
46
|
-
onRevokeSelf = _ref.onRevokeSelf,
|
|
47
|
-
share = _ref.share,
|
|
48
|
-
createContact = _ref.createContact,
|
|
49
|
-
hasSharedChild = _ref.hasSharedChild,
|
|
50
|
-
hasSharedParent = _ref.hasSharedParent,
|
|
51
|
-
twoStepsConfirmationMethods = _ref.twoStepsConfirmationMethods;
|
|
52
|
-
|
|
53
|
-
var _useI18n = useI18n(),
|
|
54
|
-
t = _useI18n.t;
|
|
55
|
-
|
|
56
|
-
var _useAlert = useAlert(),
|
|
57
|
-
showAlert = _useAlert.showAlert; // State for pending recipients (not yet shared)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
var _useState = useState({
|
|
61
|
-
recipients: [],
|
|
62
|
-
readOnlyRecipients: []
|
|
63
|
-
}),
|
|
64
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
65
|
-
pendingRecipients = _useState2[0],
|
|
66
|
-
setPendingRecipients = _useState2[1]; // Accumulate recipients when added via ShareByEmail
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
var onShare = function onShare(params) {
|
|
70
|
-
setPendingRecipients(function (prev) {
|
|
71
|
-
return {
|
|
72
|
-
recipients: mergeAndDeduplicateRecipients([prev.recipients, params.recipients || []]),
|
|
73
|
-
readOnlyRecipients: mergeAndDeduplicateRecipients([prev.readOnlyRecipients, params.readOnlyRecipients || []])
|
|
74
|
-
};
|
|
75
|
-
});
|
|
76
|
-
}; // Handle changing a recipient's permission type
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
var onSetType = function onSetType(index, newType) {
|
|
80
|
-
var recipientId = index;
|
|
81
|
-
|
|
82
|
-
if (newType === 'two-way') {
|
|
83
|
-
setPendingRecipients(function (prev) {
|
|
84
|
-
var recipientToMove = prev.readOnlyRecipients.find(function (r) {
|
|
85
|
-
return (r.id || r._id) === recipientId;
|
|
86
|
-
});
|
|
87
|
-
if (!recipientToMove) return prev;
|
|
88
|
-
return {
|
|
89
|
-
recipients: [].concat(_toConsumableArray(prev.recipients), [recipientToMove]),
|
|
90
|
-
readOnlyRecipients: prev.readOnlyRecipients.filter(function (r) {
|
|
91
|
-
return (r.id || r._id) !== recipientId;
|
|
92
|
-
})
|
|
93
|
-
};
|
|
94
|
-
});
|
|
95
|
-
} else {
|
|
96
|
-
setPendingRecipients(function (prev) {
|
|
97
|
-
var recipientToMove = prev.recipients.find(function (r) {
|
|
98
|
-
return (r.id || r._id) === recipientId;
|
|
99
|
-
});
|
|
100
|
-
if (!recipientToMove) return prev;
|
|
101
|
-
return {
|
|
102
|
-
recipients: prev.recipients.filter(function (r) {
|
|
103
|
-
return (r.id || r._id) !== recipientId;
|
|
104
|
-
}),
|
|
105
|
-
readOnlyRecipients: [].concat(_toConsumableArray(prev.readOnlyRecipients), [recipientToMove])
|
|
106
|
-
};
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
}; // Remove a pending recipient
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
var onRevokePending = function onRevokePending(index) {
|
|
113
|
-
var recipientId = index;
|
|
114
|
-
setPendingRecipients(function (prev) {
|
|
115
|
-
return {
|
|
116
|
-
recipients: prev.recipients.filter(function (r) {
|
|
117
|
-
return (r.id || r._id) !== recipientId;
|
|
118
|
-
}),
|
|
119
|
-
readOnlyRecipients: prev.readOnlyRecipients.filter(function (r) {
|
|
120
|
-
return (r.id || r._id) !== recipientId;
|
|
121
|
-
})
|
|
122
|
-
};
|
|
123
|
-
});
|
|
124
|
-
}; // Submit all pending recipients at once
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
var onSubmit = /*#__PURE__*/function () {
|
|
128
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
129
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
130
|
-
while (1) switch (_context.prev = _context.next) {
|
|
131
|
-
case 0:
|
|
132
|
-
if (!(pendingRecipients.recipients.length === 0 && pendingRecipients.readOnlyRecipients.length === 0)) {
|
|
133
|
-
_context.next = 2;
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return _context.abrupt("return");
|
|
138
|
-
|
|
139
|
-
case 2:
|
|
140
|
-
_context.prev = 2;
|
|
141
|
-
_context.next = 5;
|
|
142
|
-
return share({
|
|
143
|
-
document: document,
|
|
144
|
-
recipients: pendingRecipients.recipients,
|
|
145
|
-
readOnlyRecipients: pendingRecipients.readOnlyRecipients,
|
|
146
|
-
description: sharingDesc,
|
|
147
|
-
openSharing: pendingRecipients.recipients.length > 0
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
case 5:
|
|
151
|
-
showAlert({
|
|
152
|
-
message: t('Share.successNotification'),
|
|
153
|
-
severity: 'success',
|
|
154
|
-
variant: 'filled'
|
|
155
|
-
}); // Clear pending recipients after successful share
|
|
156
|
-
|
|
157
|
-
setPendingRecipients({
|
|
158
|
-
recipients: [],
|
|
159
|
-
readOnlyRecipients: []
|
|
160
|
-
});
|
|
161
|
-
_context.next = 12;
|
|
162
|
-
break;
|
|
163
|
-
|
|
164
|
-
case 9:
|
|
165
|
-
_context.prev = 9;
|
|
166
|
-
_context.t0 = _context["catch"](2);
|
|
167
|
-
showAlert({
|
|
168
|
-
message: t('Share.errorNotification'),
|
|
169
|
-
severity: 'error',
|
|
170
|
-
variant: 'filled'
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
case 12:
|
|
174
|
-
case "end":
|
|
175
|
-
return _context.stop();
|
|
176
|
-
}
|
|
177
|
-
}, _callee, null, [[2, 9]]);
|
|
178
|
-
}));
|
|
179
|
-
|
|
180
|
-
return function onSubmit() {
|
|
181
|
-
return _ref2.apply(this, arguments);
|
|
182
|
-
};
|
|
183
|
-
}(); // Combine existing and pending recipients for display
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
var allRecipients = [].concat(_toConsumableArray(existingRecipients), _toConsumableArray(pendingRecipients.recipients.map(function (r) {
|
|
187
|
-
var _Contact$getPrimaryEm;
|
|
188
|
-
|
|
189
|
-
return {
|
|
190
|
-
index: r._id || r.id,
|
|
191
|
-
email: r.email || ((_Contact$getPrimaryEm = Contact.getPrimaryEmail) === null || _Contact$getPrimaryEm === void 0 ? void 0 : _Contact$getPrimaryEm.call(Contact, r)) || r.displayName,
|
|
192
|
-
public_name: r.displayName || r.name,
|
|
193
|
-
sharingId: null,
|
|
194
|
-
memberIndex: r._id || r.id,
|
|
195
|
-
type: 'two-way',
|
|
196
|
-
isPending: true
|
|
197
|
-
};
|
|
198
|
-
})), _toConsumableArray(pendingRecipients.readOnlyRecipients.map(function (r) {
|
|
199
|
-
var _Contact$getPrimaryEm2;
|
|
200
|
-
|
|
201
|
-
return {
|
|
202
|
-
index: r._id || r.id,
|
|
203
|
-
email: r.email || ((_Contact$getPrimaryEm2 = Contact.getPrimaryEmail) === null || _Contact$getPrimaryEm2 === void 0 ? void 0 : _Contact$getPrimaryEm2.call(Contact, r)) || r.displayName,
|
|
204
|
-
public_name: r.displayName || r.name,
|
|
205
|
-
sharingId: null,
|
|
206
|
-
memberIndex: r._id || r.id,
|
|
207
|
-
type: 'one-way',
|
|
208
|
-
isPending: true
|
|
209
|
-
};
|
|
210
|
-
})));
|
|
211
|
-
var hasPendingRecipients = pendingRecipients.recipients.length > 0 || pendingRecipients.readOnlyRecipients.length > 0; // Wrapper functions that handle both pending and existing recipients
|
|
212
|
-
|
|
213
|
-
var handleRevoke = function handleRevoke(document, sharingId, memberIndex) {
|
|
214
|
-
var recipient = allRecipients.find(function (r) {
|
|
215
|
-
return r.memberIndex === memberIndex;
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
if (recipient !== null && recipient !== void 0 && recipient.isPending) {
|
|
219
|
-
onRevokePending(memberIndex);
|
|
220
|
-
} else {
|
|
221
|
-
onRevoke(document, sharingId, memberIndex);
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
var handleSetType = function handleSetType(index, newType) {
|
|
226
|
-
var recipient = allRecipients.find(function (r) {
|
|
227
|
-
return r.index === index;
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
if (recipient !== null && recipient !== void 0 && recipient.isPending) {
|
|
231
|
-
onSetType(index, newType);
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
return /*#__PURE__*/React.createElement(ShareModal, {
|
|
236
|
-
createContact: createContact,
|
|
237
|
-
document: document,
|
|
238
|
-
documentType: documentType,
|
|
239
|
-
hasSharedChild: hasSharedChild,
|
|
240
|
-
hasSharedParent: hasSharedParent,
|
|
241
|
-
isOwner: isOwner,
|
|
242
|
-
link: link,
|
|
243
|
-
onClose: onClose,
|
|
244
|
-
onRevoke: handleRevoke,
|
|
245
|
-
onRevokeSelf: onRevokeSelf,
|
|
246
|
-
onShare: onShare,
|
|
247
|
-
onSubmit: onSubmit,
|
|
248
|
-
onSetType: handleSetType,
|
|
249
|
-
permissions: permissions,
|
|
250
|
-
recipients: allRecipients,
|
|
251
|
-
sharing: sharing,
|
|
252
|
-
sharingDesc: sharingDesc,
|
|
253
|
-
twoStepsConfirmationMethods: twoStepsConfirmationMethods,
|
|
254
|
-
batchMode: true,
|
|
255
|
-
hasPendingRecipients: hasPendingRecipients
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
ShareModalBatchContainer.propTypes = {
|
|
259
|
-
document: PropTypes.object.isRequired,
|
|
260
|
-
documentType: PropTypes.string,
|
|
261
|
-
isOwner: PropTypes.bool,
|
|
262
|
-
link: PropTypes.string,
|
|
263
|
-
permissions: PropTypes.array,
|
|
264
|
-
recipients: PropTypes.array,
|
|
265
|
-
sharing: PropTypes.object,
|
|
266
|
-
sharingDesc: PropTypes.string,
|
|
267
|
-
onClose: PropTypes.func.isRequired,
|
|
268
|
-
onRevoke: PropTypes.func.isRequired,
|
|
269
|
-
onRevokeSelf: PropTypes.func.isRequired,
|
|
270
|
-
share: PropTypes.func.isRequired,
|
|
271
|
-
createContact: PropTypes.func.isRequired,
|
|
272
|
-
hasSharedChild: PropTypes.bool,
|
|
273
|
-
hasSharedParent: PropTypes.bool,
|
|
274
|
-
twoStepsConfirmationMethods: PropTypes.object
|
|
275
|
-
};
|
|
276
|
-
export default ShareModalBatchContainer;
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
-
import { render, fireEvent, waitFor, screen } from '@testing-library/react';
|
|
5
|
-
import React from 'react';
|
|
6
|
-
import { act } from 'react-dom/test-utils';
|
|
7
|
-
import { ShareModalBatchContainer } from './ShareModalBatchContainer';
|
|
8
|
-
import AppLike from '../../../test/AppLike'; // Mock ShareModal to avoid rendering the whole sub-tree
|
|
9
|
-
|
|
10
|
-
jest.mock('../ShareModal', function () {
|
|
11
|
-
return {
|
|
12
|
-
ShareModal: function ShareModal(_ref) {
|
|
13
|
-
var onShare = _ref.onShare,
|
|
14
|
-
onSubmit = _ref.onSubmit,
|
|
15
|
-
recipients = _ref.recipients;
|
|
16
|
-
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
17
|
-
"data-testid": "recipients-count"
|
|
18
|
-
}, recipients.length), /*#__PURE__*/React.createElement("button", {
|
|
19
|
-
onClick: function onClick() {
|
|
20
|
-
return onShare({
|
|
21
|
-
recipients: [{
|
|
22
|
-
id: 'new',
|
|
23
|
-
email: 'new@cozy.cc'
|
|
24
|
-
}]
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}, "Add Recipient"), /*#__PURE__*/React.createElement("button", {
|
|
28
|
-
onClick: onSubmit
|
|
29
|
-
}, "Submit"));
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
});
|
|
33
|
-
describe('ShareModalBatchContainer', function () {
|
|
34
|
-
var defaultProps = {
|
|
35
|
-
document: {
|
|
36
|
-
_id: 'doc1',
|
|
37
|
-
name: 'Doc 1'
|
|
38
|
-
},
|
|
39
|
-
documentType: 'Files',
|
|
40
|
-
onClose: jest.fn(),
|
|
41
|
-
onRevoke: jest.fn(),
|
|
42
|
-
onRevokeSelf: jest.fn(),
|
|
43
|
-
share: jest.fn(),
|
|
44
|
-
createContact: jest.fn(),
|
|
45
|
-
recipients: []
|
|
46
|
-
};
|
|
47
|
-
beforeEach(function () {
|
|
48
|
-
jest.clearAllMocks();
|
|
49
|
-
});
|
|
50
|
-
it('should accumulate recipients and call share on submit', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
51
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
52
|
-
while (1) switch (_context.prev = _context.next) {
|
|
53
|
-
case 0:
|
|
54
|
-
render( /*#__PURE__*/React.createElement(AppLike, null, /*#__PURE__*/React.createElement(ShareModalBatchContainer, defaultProps))); // Add a recipient
|
|
55
|
-
|
|
56
|
-
act(function () {
|
|
57
|
-
fireEvent.click(screen.getByText('Add Recipient'));
|
|
58
|
-
});
|
|
59
|
-
expect(screen.getByTestId('recipients-count').textContent).toBe('1'); // Submit
|
|
60
|
-
|
|
61
|
-
act(function () {
|
|
62
|
-
fireEvent.click(screen.getByText('Submit'));
|
|
63
|
-
});
|
|
64
|
-
_context.next = 6;
|
|
65
|
-
return waitFor(function () {
|
|
66
|
-
expect(defaultProps.share).toHaveBeenCalledWith(expect.objectContaining({
|
|
67
|
-
recipients: [{
|
|
68
|
-
id: 'new',
|
|
69
|
-
email: 'new@cozy.cc'
|
|
70
|
-
}],
|
|
71
|
-
readOnlyRecipients: []
|
|
72
|
-
}));
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
case 6:
|
|
76
|
-
_context.next = 8;
|
|
77
|
-
return waitFor(function () {
|
|
78
|
-
expect(screen.getByTestId('recipients-count').textContent).toBe('0');
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
case 8:
|
|
82
|
-
case "end":
|
|
83
|
-
return _context.stop();
|
|
84
|
-
}
|
|
85
|
-
}, _callee);
|
|
86
|
-
})));
|
|
87
|
-
it('should not call share if no pending recipients', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
88
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
89
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
90
|
-
case 0:
|
|
91
|
-
render( /*#__PURE__*/React.createElement(AppLike, null, /*#__PURE__*/React.createElement(ShareModalBatchContainer, defaultProps)));
|
|
92
|
-
act(function () {
|
|
93
|
-
fireEvent.click(screen.getByText('Submit'));
|
|
94
|
-
});
|
|
95
|
-
expect(defaultProps.share).not.toHaveBeenCalled();
|
|
96
|
-
|
|
97
|
-
case 3:
|
|
98
|
-
case "end":
|
|
99
|
-
return _context2.stop();
|
|
100
|
-
}
|
|
101
|
-
}, _callee2);
|
|
102
|
-
})));
|
|
103
|
-
it('should combine existing and pending recipients correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
104
|
-
var existingRecipients;
|
|
105
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
106
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
107
|
-
case 0:
|
|
108
|
-
existingRecipients = [{
|
|
109
|
-
index: 'old1',
|
|
110
|
-
email: 'old1@cozy.cc',
|
|
111
|
-
public_name: 'Old 1'
|
|
112
|
-
}];
|
|
113
|
-
render( /*#__PURE__*/React.createElement(AppLike, null, /*#__PURE__*/React.createElement(ShareModalBatchContainer, _extends({}, defaultProps, {
|
|
114
|
-
recipients: existingRecipients
|
|
115
|
-
})))); // Initial count should be 1 (the existing one)
|
|
116
|
-
|
|
117
|
-
expect(screen.getByTestId('recipients-count').textContent).toBe('1'); // Add a recipient
|
|
118
|
-
|
|
119
|
-
act(function () {
|
|
120
|
-
fireEvent.click(screen.getByText('Add Recipient'));
|
|
121
|
-
}); // Count should be 2
|
|
122
|
-
|
|
123
|
-
expect(screen.getByTestId('recipients-count').textContent).toBe('2');
|
|
124
|
-
|
|
125
|
-
case 5:
|
|
126
|
-
case "end":
|
|
127
|
-
return _context3.stop();
|
|
128
|
-
}
|
|
129
|
-
}, _callee3);
|
|
130
|
-
})));
|
|
131
|
-
});
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["document"];
|
|
4
|
-
import PropTypes from "prop-types";
|
|
5
|
-
import React from "react";
|
|
6
|
-
import { useClient } from "cozy-client";
|
|
7
|
-
import flag from "cozy-flags";
|
|
8
|
-
import withLocales from "../../hoc/withLocales";
|
|
9
|
-
import { useFetchDocumentPath } from "../../hooks/useFetchDocumentPath";
|
|
10
|
-
import { useSharingContext } from "../../hooks/useSharingContext";
|
|
11
|
-
import { Contact } from "../../models";
|
|
12
|
-
import { ShareModal } from "../ShareModal";
|
|
13
|
-
export var SharedDriveEditModal = withLocales(function (_ref) {
|
|
14
|
-
var document = _ref.document,
|
|
15
|
-
rest = _objectWithoutProperties(_ref, _excluded);
|
|
16
|
-
|
|
17
|
-
var client = useClient();
|
|
18
|
-
var documentPath = useFetchDocumentPath(client, document);
|
|
19
|
-
|
|
20
|
-
var _useSharingContext = useSharingContext(),
|
|
21
|
-
documentType = _useSharingContext.documentType,
|
|
22
|
-
getDocumentPermissions = _useSharingContext.getDocumentPermissions,
|
|
23
|
-
getRecipients = _useSharingContext.getRecipients,
|
|
24
|
-
getSharingForSelf = _useSharingContext.getSharingForSelf,
|
|
25
|
-
getSharingLink = _useSharingContext.getSharingLink,
|
|
26
|
-
hasSharedChild = _useSharingContext.hasSharedChild,
|
|
27
|
-
hasSharedParent = _useSharingContext.hasSharedParent,
|
|
28
|
-
isOwner = _useSharingContext.isOwner,
|
|
29
|
-
revoke = _useSharingContext.revoke,
|
|
30
|
-
revokeSelf = _useSharingContext.revokeSelf,
|
|
31
|
-
share = _useSharingContext.share; // TODO get sharing from document
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var sharingDoc = getSharingForSelf(document._id);
|
|
35
|
-
var sharingDesc = sharingDoc.rules[0].title;
|
|
36
|
-
return /*#__PURE__*/React.createElement(ShareModal, _extends({
|
|
37
|
-
createContact: function createContact(contact) {
|
|
38
|
-
return client.create(Contact.doctype, contact);
|
|
39
|
-
},
|
|
40
|
-
document: document,
|
|
41
|
-
documentType: documentType,
|
|
42
|
-
hasSharedChild: documentPath && hasSharedChild(documentPath),
|
|
43
|
-
hasSharedParent: documentPath && hasSharedParent(documentPath),
|
|
44
|
-
isOwner: isOwner(document._id),
|
|
45
|
-
link: getSharingLink(document._id),
|
|
46
|
-
onRevoke: revoke,
|
|
47
|
-
onRevokeSelf: revokeSelf,
|
|
48
|
-
onShare: share,
|
|
49
|
-
showShareByLink: false,
|
|
50
|
-
permissions: getDocumentPermissions(document._id),
|
|
51
|
-
recipients: getRecipients(document._id),
|
|
52
|
-
sharing: getSharingForSelf(document._id),
|
|
53
|
-
sharingDesc: sharingDesc
|
|
54
|
-
}, rest));
|
|
55
|
-
});
|
|
56
|
-
SharedDriveEditModal.propTypes = {
|
|
57
|
-
document: PropTypes.object
|
|
58
|
-
};
|
|
59
|
-
export default SharedDriveEditModal;
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import PropTypes from 'prop-types';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { useI18n } from 'twake-i18n';
|
|
4
|
-
import withLocales from '../../hoc/withLocales';
|
|
5
|
-
import { DumbBatchSharedFolderModal } from '../SharedFolder/DumbBatchSharedFolderModal';
|
|
6
|
-
export var DumbSharedDriveModal = withLocales(function (_ref) {
|
|
7
|
-
var title = _ref.title,
|
|
8
|
-
document = _ref.document,
|
|
9
|
-
sharedDriveName = _ref.sharedDriveName,
|
|
10
|
-
handleSharedDriveNameChange = _ref.handleSharedDriveNameChange,
|
|
11
|
-
createContact = _ref.createContact,
|
|
12
|
-
recipients = _ref.recipients,
|
|
13
|
-
currentRecipients = _ref.currentRecipients,
|
|
14
|
-
onRevoke = _ref.onRevoke,
|
|
15
|
-
onSetType = _ref.onSetType,
|
|
16
|
-
onCreate = _ref.onCreate,
|
|
17
|
-
onSend = _ref.onSend,
|
|
18
|
-
onClose = _ref.onClose,
|
|
19
|
-
onShare = _ref.onShare,
|
|
20
|
-
onRename = _ref.onRename,
|
|
21
|
-
_ref$showNameField = _ref.showNameField,
|
|
22
|
-
showNameField = _ref$showNameField === void 0 ? true : _ref$showNameField,
|
|
23
|
-
sharingLink = _ref.sharingLink,
|
|
24
|
-
autoOpenShareRestriction = _ref.autoOpenShareRestriction,
|
|
25
|
-
showGenerateLinkButton = _ref.showGenerateLinkButton;
|
|
26
|
-
|
|
27
|
-
var _useI18n = useI18n(),
|
|
28
|
-
t = _useI18n.t;
|
|
29
|
-
|
|
30
|
-
return /*#__PURE__*/React.createElement(DumbBatchSharedFolderModal, {
|
|
31
|
-
title: title,
|
|
32
|
-
document: document,
|
|
33
|
-
folderName: sharedDriveName,
|
|
34
|
-
handleFolderNameChange: handleSharedDriveNameChange,
|
|
35
|
-
createContact: createContact,
|
|
36
|
-
recipients: recipients,
|
|
37
|
-
currentRecipients: currentRecipients,
|
|
38
|
-
onRevoke: onRevoke,
|
|
39
|
-
onSetType: onSetType,
|
|
40
|
-
onCreate: onCreate,
|
|
41
|
-
onSend: onSend,
|
|
42
|
-
onClose: onClose,
|
|
43
|
-
onShare: onShare,
|
|
44
|
-
onRename: onRename,
|
|
45
|
-
showNameField: showNameField,
|
|
46
|
-
sharingLink: sharingLink,
|
|
47
|
-
nameLabel: t('SharedDrive.sharedDriveModal.nameLabel'),
|
|
48
|
-
addPeopleLabel: t('SharedDrive.sharedDriveModal.addPeople'),
|
|
49
|
-
addButtonLabel: t('SharedDrive.sharedDriveModal.add'),
|
|
50
|
-
cancelLabel: t('SharedDrive.sharedDriveModal.cancel'),
|
|
51
|
-
createLabel: t('SharedDrive.sharedDriveModal.create'),
|
|
52
|
-
shareLabel: t('FederatedFolder.share'),
|
|
53
|
-
saveLabel: t('SharedDrive.sharedDriveModal.save'),
|
|
54
|
-
autoOpenShareRestriction: autoOpenShareRestriction,
|
|
55
|
-
showGenerateLinkButton: showGenerateLinkButton
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
DumbSharedDriveModal.propTypes = {
|
|
59
|
-
title: PropTypes.string,
|
|
60
|
-
document: PropTypes.object,
|
|
61
|
-
sharedDriveName: PropTypes.string,
|
|
62
|
-
handleSharedDriveNameChange: PropTypes.func,
|
|
63
|
-
createContact: PropTypes.func.isRequired,
|
|
64
|
-
recipients: PropTypes.array,
|
|
65
|
-
currentRecipients: PropTypes.array,
|
|
66
|
-
onRevoke: PropTypes.func.isRequired,
|
|
67
|
-
onSetType: PropTypes.func.isRequired,
|
|
68
|
-
onCreate: PropTypes.func,
|
|
69
|
-
onSend: PropTypes.func,
|
|
70
|
-
onClose: PropTypes.func.isRequired,
|
|
71
|
-
onShare: PropTypes.func.isRequired,
|
|
72
|
-
onRename: PropTypes.func,
|
|
73
|
-
showNameField: PropTypes.bool,
|
|
74
|
-
sharingLink: PropTypes.string,
|
|
75
|
-
autoOpenShareRestriction: PropTypes.bool,
|
|
76
|
-
showGenerateLinkButton: PropTypes.bool
|
|
77
|
-
};
|
|
78
|
-
export default DumbSharedDriveModal;
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { DumbSharedDriveModal } from './DumbSharedDriveModal';
|
|
5
|
-
var mockDumbBatchSharedFolderModal = jest.fn();
|
|
6
|
-
jest.mock('../SharedFolder/DumbBatchSharedFolderModal', function () {
|
|
7
|
-
return {
|
|
8
|
-
__esModule: true,
|
|
9
|
-
default: function _default(props) {
|
|
10
|
-
mockDumbBatchSharedFolderModal(props);
|
|
11
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
12
|
-
"data-testid": "dumb-batch-shared-folder-modal"
|
|
13
|
-
}, "DumbBatchSharedFolderModal");
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
jest.mock('../../hoc/withLocales', function () {
|
|
18
|
-
return {
|
|
19
|
-
__esModule: true,
|
|
20
|
-
default: function _default(Component) {
|
|
21
|
-
return Component;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
});
|
|
25
|
-
jest.mock('twake-i18n', function () {
|
|
26
|
-
return {
|
|
27
|
-
useI18n: jest.fn().mockReturnValue({
|
|
28
|
-
t: jest.fn(function (key) {
|
|
29
|
-
return key;
|
|
30
|
-
})
|
|
31
|
-
})
|
|
32
|
-
};
|
|
33
|
-
});
|
|
34
|
-
describe('DumbSharedDriveModal', function () {
|
|
35
|
-
var defaultProps = {
|
|
36
|
-
title: 'Test Shared Drive',
|
|
37
|
-
document: {
|
|
38
|
-
_id: 'doc-123',
|
|
39
|
-
name: 'Test'
|
|
40
|
-
},
|
|
41
|
-
sharedDriveName: 'My Drive',
|
|
42
|
-
handleSharedDriveNameChange: jest.fn(),
|
|
43
|
-
createContact: jest.fn(),
|
|
44
|
-
recipients: [{
|
|
45
|
-
_id: 'r1',
|
|
46
|
-
email: 'test@test.com'
|
|
47
|
-
}],
|
|
48
|
-
currentRecipients: [],
|
|
49
|
-
onRevoke: jest.fn(),
|
|
50
|
-
onSetType: jest.fn(),
|
|
51
|
-
onCreate: jest.fn(),
|
|
52
|
-
onSend: jest.fn(),
|
|
53
|
-
onClose: jest.fn(),
|
|
54
|
-
onShare: jest.fn(),
|
|
55
|
-
onRename: jest.fn(),
|
|
56
|
-
showNameField: true,
|
|
57
|
-
sharingLink: 'https://share.link/123',
|
|
58
|
-
hasRecipientsInitially: false
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
var setup = function setup() {
|
|
62
|
-
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
63
|
-
mockDumbBatchSharedFolderModal.mockClear();
|
|
64
|
-
return render( /*#__PURE__*/React.createElement(DumbSharedDriveModal, _extends({}, defaultProps, props)));
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
it('should render DumbBatchSharedFolderModal with correct props', function () {
|
|
68
|
-
setup();
|
|
69
|
-
expect(mockDumbBatchSharedFolderModal).toHaveBeenCalledWith(expect.objectContaining({
|
|
70
|
-
title: 'Test Shared Drive',
|
|
71
|
-
document: defaultProps.document,
|
|
72
|
-
folderName: 'My Drive',
|
|
73
|
-
handleFolderNameChange: defaultProps.handleSharedDriveNameChange,
|
|
74
|
-
createContact: defaultProps.createContact,
|
|
75
|
-
recipients: defaultProps.recipients,
|
|
76
|
-
currentRecipients: defaultProps.currentRecipients,
|
|
77
|
-
onRevoke: defaultProps.onRevoke,
|
|
78
|
-
onSetType: defaultProps.onSetType,
|
|
79
|
-
onCreate: defaultProps.onCreate,
|
|
80
|
-
onSend: defaultProps.onSend,
|
|
81
|
-
onClose: defaultProps.onClose,
|
|
82
|
-
onShare: defaultProps.onShare,
|
|
83
|
-
onRename: defaultProps.onRename,
|
|
84
|
-
showNameField: true,
|
|
85
|
-
sharingLink: 'https://share.link/123',
|
|
86
|
-
hasRecipientsInitially: false
|
|
87
|
-
}));
|
|
88
|
-
});
|
|
89
|
-
it('should pass correct i18n labels to DumbBatchSharedFolderModal', function () {
|
|
90
|
-
setup();
|
|
91
|
-
var passedProps = mockDumbBatchSharedFolderModal.mock.calls[0][0];
|
|
92
|
-
expect(passedProps.nameLabel).toBe('SharedDrive.sharedDriveModal.nameLabel');
|
|
93
|
-
expect(passedProps.addPeopleLabel).toBe('SharedDrive.sharedDriveModal.addPeople');
|
|
94
|
-
expect(passedProps.addButtonLabel).toBe('SharedDrive.sharedDriveModal.add');
|
|
95
|
-
expect(passedProps.cancelLabel).toBe('SharedDrive.sharedDriveModal.cancel');
|
|
96
|
-
expect(passedProps.createLabel).toBe('SharedDrive.sharedDriveModal.create');
|
|
97
|
-
expect(passedProps.shareLabel).toBe('SharedDrive.sharedDriveModal.share');
|
|
98
|
-
expect(passedProps.saveLabel).toBe('SharedDrive.sharedDriveModal.save');
|
|
99
|
-
});
|
|
100
|
-
it('should default showNameField to true', function () {
|
|
101
|
-
var _setup = setup({
|
|
102
|
-
showNameField: undefined
|
|
103
|
-
}),
|
|
104
|
-
rerender = _setup.rerender; // Re-render without showNameField
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
rerender( /*#__PURE__*/React.createElement(DumbSharedDriveModal, _extends({}, defaultProps, {
|
|
108
|
-
showNameField: undefined
|
|
109
|
-
})));
|
|
110
|
-
var passedProps = mockDumbBatchSharedFolderModal.mock.calls[mockDumbBatchSharedFolderModal.mock.calls.length - 1][0];
|
|
111
|
-
expect(passedProps.showNameField).toBe(true);
|
|
112
|
-
});
|
|
113
|
-
it('should handle hasRecipientsInitially correctly', function () {
|
|
114
|
-
setup({
|
|
115
|
-
hasRecipientsInitially: true
|
|
116
|
-
});
|
|
117
|
-
var passedProps = mockDumbBatchSharedFolderModal.mock.calls[0][0];
|
|
118
|
-
expect(passedProps.hasRecipientsInitially).toBe(true);
|
|
119
|
-
});
|
|
120
|
-
it('should render the mocked component', function () {
|
|
121
|
-
var _setup2 = setup(),
|
|
122
|
-
getByTestId = _setup2.getByTestId;
|
|
123
|
-
|
|
124
|
-
expect(getByTestId('dumb-batch-shared-folder-modal')).toBeInTheDocument();
|
|
125
|
-
});
|
|
126
|
-
});
|