cozy-sharing 28.4.4 → 28.6.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 +18 -0
- package/dist/SharingProvider.js +296 -66
- package/dist/SharingProvider.spec.js +332 -2
- package/dist/components/FederatedFolder/DumbFederatedFolderModal.js +7 -4
- package/dist/components/FederatedFolder/FederatedFolderModal.js +79 -23
- package/dist/components/Recipient/LinkRecipient.js +6 -3
- package/dist/components/Recipient/LinkRecipient.stories.js +0 -1
- package/dist/components/Recipient/MemberRecipient.spec.js +13 -0
- package/dist/components/Recipient/MemberRecipientPermissions.js +80 -20
- package/dist/components/Recipient/MemberRecipientPermissions.spec.js +214 -0
- package/dist/components/Recipient/actions/setReadOnlySharedPermission.js +0 -1
- package/dist/components/Recipient/actions/setReadOnlySharedPermission.spec.js +72 -0
- package/dist/components/Recipient/actions/setReadWriteSharedPermission.js +0 -1
- package/dist/components/Recipient/actions/setReadWriteSharedPermission.spec.js +72 -0
- package/dist/components/ShareByLink.js +5 -1
- package/dist/components/ShareDialogCozyToCozy.spec.js +9 -0
- package/dist/components/ShareRestrictionModal/helpers.js +66 -29
- package/dist/components/SharedDrive/DumbSharedDriveModal.js +1 -1
- package/dist/components/SharedFolder/DumbBatchSharedFolderModal.js +17 -4
- package/dist/components/WhoHasAccess.js +0 -1
- package/dist/helpers/shortcodes.js +24 -0
- package/dist/state.js +3 -10
- package/locales/en.json +4 -1
- package/locales/fr.json +4 -1
- package/locales/ru.json +4 -1
- package/locales/vi.json +4 -1
- package/package.json +4 -4
- package/src/SharingProvider.jsx +128 -9
- package/src/SharingProvider.spec.jsx +224 -1
- package/src/components/FederatedFolder/DumbFederatedFolderModal.jsx +6 -3
- package/src/components/FederatedFolder/FederatedFolderModal.jsx +39 -6
- package/src/components/Recipient/LinkRecipient.jsx +10 -4
- package/src/components/Recipient/LinkRecipient.stories.jsx +0 -1
- package/src/components/Recipient/MemberRecipient.spec.jsx +11 -0
- package/src/components/Recipient/MemberRecipientPermissions.jsx +69 -16
- package/src/components/Recipient/MemberRecipientPermissions.spec.jsx +165 -0
- package/src/components/Recipient/actions/setReadOnlySharedPermission.js +1 -1
- package/src/components/Recipient/actions/setReadOnlySharedPermission.spec.jsx +95 -0
- package/src/components/Recipient/actions/setReadWriteSharedPermission.js +1 -1
- package/src/components/Recipient/actions/setReadWriteSharedPermission.spec.jsx +95 -0
- package/src/components/ShareByLink.jsx +3 -1
- package/src/components/ShareDialogCozyToCozy.spec.jsx +6 -0
- package/src/components/ShareRestrictionModal/helpers.js +42 -4
- package/src/components/SharedDrive/DumbSharedDriveModal.jsx +1 -1
- package/src/components/SharedFolder/DumbBatchSharedFolderModal.jsx +32 -16
- package/src/components/WhoHasAccess.jsx +0 -1
- package/src/helpers/shortcodes.js +28 -0
- package/src/state.js +3 -14
|
@@ -1,11 +1,17 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
1
2
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
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; }
|
|
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; }
|
|
7
|
+
|
|
2
8
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
9
|
import { act, render, screen } from '@testing-library/react';
|
|
4
10
|
import React from 'react';
|
|
5
11
|
import { createMockClient } from 'cozy-client';
|
|
6
12
|
import { SharingProvider } from './SharingProvider';
|
|
7
|
-
import SharingContext from './context';
|
|
8
|
-
|
|
13
|
+
import SharingContext from './context';
|
|
14
|
+
import reducer, { addSharingLink, getDocumentPermissions } from './state';
|
|
9
15
|
import AppLike from '../test/AppLike';
|
|
10
16
|
|
|
11
17
|
var AppWrapper = function AppWrapper(_ref) {
|
|
@@ -130,6 +136,330 @@ describe('SharingProvider', function () {
|
|
|
130
136
|
expect(client.collection().findLinksByDoctype).not.toHaveBeenCalled();
|
|
131
137
|
expect(client.collection().findApps).not.toHaveBeenCalled();
|
|
132
138
|
});
|
|
139
|
+
});
|
|
140
|
+
describe('shareByLink', function () {
|
|
141
|
+
var PERM_DRIVE_FILE = {
|
|
142
|
+
type: 'io.cozy.permissions',
|
|
143
|
+
id: 'perm_drive_file',
|
|
144
|
+
attributes: {
|
|
145
|
+
type: 'share',
|
|
146
|
+
permissions: {
|
|
147
|
+
rule0: {
|
|
148
|
+
type: 'io.cozy.files',
|
|
149
|
+
verbs: ['GET'],
|
|
150
|
+
values: ['file_in_drive']
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
shortcodes: {
|
|
154
|
+
code: 'shortcode123'
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
var driveFile = {
|
|
159
|
+
_id: 'file_in_drive',
|
|
160
|
+
id: 'file_in_drive',
|
|
161
|
+
driveId: 'drive_123'
|
|
162
|
+
};
|
|
163
|
+
it('dispatches addSharingLink exactly once for a shared drive file', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
164
|
+
var mockCreateSharingLink, mockClient, provider, permissions;
|
|
165
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
166
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
167
|
+
case 0:
|
|
168
|
+
mockCreateSharingLink = jest.fn().mockResolvedValue({
|
|
169
|
+
data: PERM_DRIVE_FILE
|
|
170
|
+
});
|
|
171
|
+
mockClient = createMockClient({});
|
|
172
|
+
mockClient.collection = jest.fn().mockReturnValue({
|
|
173
|
+
createSharingLink: mockCreateSharingLink
|
|
174
|
+
});
|
|
175
|
+
provider = new SharingProvider({
|
|
176
|
+
client: mockClient
|
|
177
|
+
});
|
|
178
|
+
provider.state = reducer();
|
|
179
|
+
provider.dispatch = jest.fn(function (action) {
|
|
180
|
+
provider.state = reducer(provider.state, action);
|
|
181
|
+
});
|
|
182
|
+
_context3.next = 8;
|
|
183
|
+
return provider.shareByLink(driveFile, {
|
|
184
|
+
verbs: ['GET']
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
case 8:
|
|
188
|
+
expect(provider.dispatch).toHaveBeenCalledTimes(1);
|
|
189
|
+
permissions = getDocumentPermissions(provider.state, driveFile._id);
|
|
190
|
+
expect(permissions).toHaveLength(1);
|
|
191
|
+
expect(permissions[0].id).toBe(PERM_DRIVE_FILE.id);
|
|
192
|
+
|
|
193
|
+
case 12:
|
|
194
|
+
case "end":
|
|
195
|
+
return _context3.stop();
|
|
196
|
+
}
|
|
197
|
+
}, _callee3);
|
|
198
|
+
})));
|
|
199
|
+
it('dispatches addSharingLink once for a regular file (non shared drive)', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
|
200
|
+
var PERM_REGULAR_FILE, regularFile, mockCreateSharingLink, mockClient, provider, permissions;
|
|
201
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
202
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
203
|
+
case 0:
|
|
204
|
+
PERM_REGULAR_FILE = {
|
|
205
|
+
type: 'io.cozy.permissions',
|
|
206
|
+
id: 'perm_regular_file',
|
|
207
|
+
attributes: {
|
|
208
|
+
type: 'share',
|
|
209
|
+
permissions: {
|
|
210
|
+
rule0: {
|
|
211
|
+
type: 'io.cozy.files',
|
|
212
|
+
verbs: ['GET'],
|
|
213
|
+
values: ['regular_file_id']
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
shortcodes: {
|
|
217
|
+
code: 'shortcode456'
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
regularFile = {
|
|
222
|
+
_id: 'regular_file_id',
|
|
223
|
+
id: 'regular_file_id'
|
|
224
|
+
};
|
|
225
|
+
mockCreateSharingLink = jest.fn().mockResolvedValue({
|
|
226
|
+
data: PERM_REGULAR_FILE
|
|
227
|
+
});
|
|
228
|
+
mockClient = createMockClient({});
|
|
229
|
+
mockClient.collection = jest.fn().mockReturnValue({
|
|
230
|
+
createSharingLink: mockCreateSharingLink
|
|
231
|
+
});
|
|
232
|
+
provider = new SharingProvider({
|
|
233
|
+
client: mockClient
|
|
234
|
+
});
|
|
235
|
+
provider.state = reducer();
|
|
236
|
+
provider.permissionCol = {
|
|
237
|
+
createSharingLink: mockCreateSharingLink
|
|
238
|
+
};
|
|
239
|
+
provider.dispatch = jest.fn(function (action) {
|
|
240
|
+
provider.state = reducer(provider.state, action);
|
|
241
|
+
});
|
|
242
|
+
_context4.next = 11;
|
|
243
|
+
return provider.shareByLink(regularFile, {
|
|
244
|
+
verbs: ['GET']
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
case 11:
|
|
248
|
+
expect(provider.dispatch).toHaveBeenCalledTimes(1);
|
|
249
|
+
permissions = getDocumentPermissions(provider.state, regularFile._id);
|
|
250
|
+
expect(permissions).toHaveLength(1);
|
|
251
|
+
expect(permissions[0].id).toBe(PERM_REGULAR_FILE.id);
|
|
252
|
+
|
|
253
|
+
case 15:
|
|
254
|
+
case "end":
|
|
255
|
+
return _context4.stop();
|
|
256
|
+
}
|
|
257
|
+
}, _callee4);
|
|
258
|
+
})));
|
|
259
|
+
});
|
|
260
|
+
describe('updateDocumentPermissions', function () {
|
|
261
|
+
var PERM_DRIVE_FILE = {
|
|
262
|
+
type: 'io.cozy.permissions',
|
|
263
|
+
id: 'perm_drive_file',
|
|
264
|
+
attributes: {
|
|
265
|
+
type: 'share',
|
|
266
|
+
permissions: {
|
|
267
|
+
rule0: {
|
|
268
|
+
type: 'io.cozy.files',
|
|
269
|
+
verbs: ['GET'],
|
|
270
|
+
values: ['file_in_drive']
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
shortcodes: {
|
|
274
|
+
code: 'shortcode123'
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
it('sends only one PATCH request for a shared drive file', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
|
|
279
|
+
var driveFile, mockAdd, mockClient, provider;
|
|
280
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
281
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
282
|
+
case 0:
|
|
283
|
+
driveFile = {
|
|
284
|
+
_id: 'file_in_drive',
|
|
285
|
+
id: 'file_in_drive',
|
|
286
|
+
driveId: 'drive_123'
|
|
287
|
+
};
|
|
288
|
+
mockAdd = jest.fn().mockResolvedValue({
|
|
289
|
+
data: PERM_DRIVE_FILE
|
|
290
|
+
});
|
|
291
|
+
mockClient = createMockClient({});
|
|
292
|
+
mockClient.collection = jest.fn().mockReturnValue({
|
|
293
|
+
add: mockAdd
|
|
294
|
+
});
|
|
295
|
+
provider = new SharingProvider({
|
|
296
|
+
client: mockClient
|
|
297
|
+
}); // Seed the state with exactly one permission (as it would be after a correct shareByLink)
|
|
298
|
+
|
|
299
|
+
provider.state = reducer(undefined, addSharingLink(PERM_DRIVE_FILE));
|
|
300
|
+
provider.dispatch = jest.fn();
|
|
301
|
+
_context5.next = 9;
|
|
302
|
+
return provider.updateDocumentPermissions(driveFile, {
|
|
303
|
+
verbs: ['GET'],
|
|
304
|
+
expiresAt: '',
|
|
305
|
+
password: ''
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
case 9:
|
|
309
|
+
expect(mockAdd).toHaveBeenCalledTimes(1);
|
|
310
|
+
|
|
311
|
+
case 10:
|
|
312
|
+
case "end":
|
|
313
|
+
return _context5.stop();
|
|
314
|
+
}
|
|
315
|
+
}, _callee5);
|
|
316
|
+
})));
|
|
317
|
+
});
|
|
318
|
+
describe('updateSharingMemberType', function () {
|
|
319
|
+
var mockContact = {
|
|
320
|
+
_id: 'contact-1',
|
|
321
|
+
email: [{
|
|
322
|
+
address: 'bob@bob.cozy'
|
|
323
|
+
}]
|
|
324
|
+
};
|
|
325
|
+
var mockSharing = {
|
|
326
|
+
id: 'sharing-123',
|
|
327
|
+
type: 'io.cozy.sharings',
|
|
328
|
+
attributes: {
|
|
329
|
+
members: [{
|
|
330
|
+
status: 'owner',
|
|
331
|
+
email: 'owner@cozy.local'
|
|
332
|
+
}, {
|
|
333
|
+
status: 'ready',
|
|
334
|
+
email: 'bob@bob.cozy'
|
|
335
|
+
}]
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
var instance;
|
|
339
|
+
var mockContactsCollection;
|
|
340
|
+
beforeEach(function () {
|
|
341
|
+
mockContactsCollection = {
|
|
342
|
+
find: jest.fn().mockResolvedValue({
|
|
343
|
+
data: [mockContact]
|
|
344
|
+
})
|
|
345
|
+
};
|
|
346
|
+
var mockClient = {
|
|
347
|
+
getStackClient: function getStackClient() {
|
|
348
|
+
return {
|
|
349
|
+
uri: 'http://cozy.local'
|
|
350
|
+
};
|
|
351
|
+
},
|
|
352
|
+
collection: jest.fn().mockReturnValue(mockContactsCollection)
|
|
353
|
+
};
|
|
354
|
+
instance = new SharingProvider({
|
|
355
|
+
client: mockClient
|
|
356
|
+
});
|
|
357
|
+
instance.state = _objectSpread(_objectSpread({}, instance.state), {}, {
|
|
358
|
+
sharings: [mockSharing]
|
|
359
|
+
});
|
|
360
|
+
instance.sharingCol = {
|
|
361
|
+
revokeRecipient: jest.fn().mockResolvedValue({})
|
|
362
|
+
};
|
|
363
|
+
jest.spyOn(instance, 'addRecipients').mockResolvedValue({});
|
|
364
|
+
});
|
|
365
|
+
it('should throw when sharing is not found', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
|
|
366
|
+
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
367
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
368
|
+
case 0:
|
|
369
|
+
_context6.next = 2;
|
|
370
|
+
return expect(instance.updateSharingMemberType('unknown-id', 1, 'one-way')).rejects.toThrow('Sharing not found');
|
|
371
|
+
|
|
372
|
+
case 2:
|
|
373
|
+
case "end":
|
|
374
|
+
return _context6.stop();
|
|
375
|
+
}
|
|
376
|
+
}, _callee6);
|
|
377
|
+
})));
|
|
378
|
+
it('should throw when member is not found', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7() {
|
|
379
|
+
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
380
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
381
|
+
case 0:
|
|
382
|
+
_context7.next = 2;
|
|
383
|
+
return expect(instance.updateSharingMemberType('sharing-123', 99, 'one-way')).rejects.toThrow('Member not found');
|
|
384
|
+
|
|
385
|
+
case 2:
|
|
386
|
+
case "end":
|
|
387
|
+
return _context7.stop();
|
|
388
|
+
}
|
|
389
|
+
}, _callee7);
|
|
390
|
+
})));
|
|
391
|
+
it('should throw when contact is not found', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
|
|
392
|
+
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
|
|
393
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
394
|
+
case 0:
|
|
395
|
+
mockContactsCollection.find.mockResolvedValue({
|
|
396
|
+
data: []
|
|
397
|
+
});
|
|
398
|
+
_context8.next = 3;
|
|
399
|
+
return expect(instance.updateSharingMemberType('sharing-123', 1, 'one-way')).rejects.toThrow('Contact not found');
|
|
400
|
+
|
|
401
|
+
case 3:
|
|
402
|
+
case "end":
|
|
403
|
+
return _context8.stop();
|
|
404
|
+
}
|
|
405
|
+
}, _callee8);
|
|
406
|
+
})));
|
|
407
|
+
it('should revoke and re-add with readOnly when switching to one-way', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
|
|
408
|
+
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
409
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
410
|
+
case 0:
|
|
411
|
+
_context9.next = 2;
|
|
412
|
+
return instance.updateSharingMemberType('sharing-123', 1, 'one-way');
|
|
413
|
+
|
|
414
|
+
case 2:
|
|
415
|
+
expect(instance.sharingCol.revokeRecipient).toHaveBeenCalledWith(mockSharing, 1);
|
|
416
|
+
expect(instance.addRecipients).toHaveBeenCalledWith({
|
|
417
|
+
document: mockSharing,
|
|
418
|
+
recipients: [],
|
|
419
|
+
readOnlyRecipients: [mockContact]
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
case 4:
|
|
423
|
+
case "end":
|
|
424
|
+
return _context9.stop();
|
|
425
|
+
}
|
|
426
|
+
}, _callee9);
|
|
427
|
+
})));
|
|
428
|
+
it('should revoke and re-add as read-write when switching to two-way', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
|
|
429
|
+
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
430
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
431
|
+
case 0:
|
|
432
|
+
_context10.next = 2;
|
|
433
|
+
return instance.updateSharingMemberType('sharing-123', 1, 'two-way');
|
|
434
|
+
|
|
435
|
+
case 2:
|
|
436
|
+
expect(instance.sharingCol.revokeRecipient).toHaveBeenCalledWith(mockSharing, 1);
|
|
437
|
+
expect(instance.addRecipients).toHaveBeenCalledWith({
|
|
438
|
+
document: mockSharing,
|
|
439
|
+
recipients: [mockContact],
|
|
440
|
+
readOnlyRecipients: []
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
case 4:
|
|
444
|
+
case "end":
|
|
445
|
+
return _context10.stop();
|
|
446
|
+
}
|
|
447
|
+
}, _callee10);
|
|
448
|
+
})));
|
|
449
|
+
it('should rethrow error if addRecipients fails after revocation', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11() {
|
|
450
|
+
return _regeneratorRuntime.wrap(function _callee11$(_context11) {
|
|
451
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
452
|
+
case 0:
|
|
453
|
+
instance.addRecipients.mockRejectedValue(new Error('Network error'));
|
|
454
|
+
_context11.next = 3;
|
|
455
|
+
return expect(instance.updateSharingMemberType('sharing-123', 1, 'one-way')).rejects.toThrow('Network error');
|
|
456
|
+
|
|
457
|
+
case 3:
|
|
458
|
+
case "end":
|
|
459
|
+
return _context11.stop();
|
|
460
|
+
}
|
|
461
|
+
}, _callee11);
|
|
462
|
+
})));
|
|
133
463
|
}); // TODO Convert with react-testing-library
|
|
134
464
|
// describe('hasWriteAccess', () => {
|
|
135
465
|
// it('tells if a doc is writtable', () => {
|
|
@@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { useI18n } from 'twake-i18n';
|
|
4
4
|
import withLocales from '../../hoc/withLocales';
|
|
5
|
-
import DumbBatchSharedFolderModal from '../SharedFolder/DumbBatchSharedFolderModal';
|
|
5
|
+
import { DumbBatchSharedFolderModal } from '../SharedFolder/DumbBatchSharedFolderModal';
|
|
6
6
|
export var DumbFederatedFolderModal = withLocales(function (_ref) {
|
|
7
7
|
var title = _ref.title,
|
|
8
8
|
document = _ref.document,
|
|
@@ -15,7 +15,8 @@ export var DumbFederatedFolderModal = withLocales(function (_ref) {
|
|
|
15
15
|
onSend = _ref.onSend,
|
|
16
16
|
onClose = _ref.onClose,
|
|
17
17
|
onShare = _ref.onShare,
|
|
18
|
-
sharingLink = _ref.sharingLink
|
|
18
|
+
sharingLink = _ref.sharingLink,
|
|
19
|
+
showShareByEmail = _ref.showShareByEmail;
|
|
19
20
|
|
|
20
21
|
var _useI18n = useI18n(),
|
|
21
22
|
t = _useI18n.t;
|
|
@@ -36,7 +37,8 @@ export var DumbFederatedFolderModal = withLocales(function (_ref) {
|
|
|
36
37
|
showNameField: false,
|
|
37
38
|
addPeopleLabel: t('FederatedFolder.addPeople'),
|
|
38
39
|
addButtonLabel: t('FederatedFolder.add'),
|
|
39
|
-
shareLabel: t('FederatedFolder.share')
|
|
40
|
+
shareLabel: t('FederatedFolder.share'),
|
|
41
|
+
showShareByEmail: showShareByEmail
|
|
40
42
|
});
|
|
41
43
|
});
|
|
42
44
|
DumbFederatedFolderModal.propTypes = {
|
|
@@ -51,6 +53,7 @@ DumbFederatedFolderModal.propTypes = {
|
|
|
51
53
|
onSend: PropTypes.func.isRequired,
|
|
52
54
|
onClose: PropTypes.func.isRequired,
|
|
53
55
|
onShare: PropTypes.func.isRequired,
|
|
54
|
-
sharingLink: PropTypes.string
|
|
56
|
+
sharingLink: PropTypes.string,
|
|
57
|
+
showShareByEmail: PropTypes.bool
|
|
55
58
|
};
|
|
56
59
|
export default DumbFederatedFolderModal;
|
|
@@ -2,7 +2,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
3
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
|
-
import React, { useState } from 'react';
|
|
5
|
+
import React, { useState, useEffect } from 'react';
|
|
6
6
|
import { useI18n } from 'twake-i18n';
|
|
7
7
|
import { useClient } from 'cozy-client';
|
|
8
8
|
import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert';
|
|
@@ -20,25 +20,79 @@ export var FederatedFolderModal = withLocales(function (_ref) {
|
|
|
20
20
|
|
|
21
21
|
var _useSharingContext = useSharingContext(),
|
|
22
22
|
share = _useSharingContext.share,
|
|
23
|
-
getSharingLink = _useSharingContext.getSharingLink
|
|
23
|
+
getSharingLink = _useSharingContext.getSharingLink,
|
|
24
|
+
getFederatedShareLink = _useSharingContext.getFederatedShareLink,
|
|
25
|
+
getDocumentPermissions = _useSharingContext.getDocumentPermissions,
|
|
26
|
+
getOwner = _useSharingContext.getOwner,
|
|
27
|
+
getSharingById = _useSharingContext.getSharingById;
|
|
24
28
|
|
|
25
29
|
var _useAlert = useAlert(),
|
|
26
|
-
showAlert = _useAlert.showAlert;
|
|
30
|
+
showAlert = _useAlert.showAlert;
|
|
27
31
|
|
|
32
|
+
var _useState = useState(null),
|
|
33
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
34
|
+
sharingLink = _useState2[0],
|
|
35
|
+
setSharingLink = _useState2[1];
|
|
36
|
+
|
|
37
|
+
var documentPermissions = existingDocument ? getDocumentPermissions(existingDocument._id) : [];
|
|
38
|
+
useEffect(function () {
|
|
39
|
+
var fetchSharingLink = /*#__PURE__*/function () {
|
|
40
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
41
|
+
var link;
|
|
42
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
43
|
+
while (1) switch (_context.prev = _context.next) {
|
|
44
|
+
case 0:
|
|
45
|
+
if (existingDocument) {
|
|
46
|
+
_context.next = 2;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return _context.abrupt("return");
|
|
51
|
+
|
|
52
|
+
case 2:
|
|
53
|
+
if (!existingDocument.driveId) {
|
|
54
|
+
_context.next = 9;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
_context.next = 5;
|
|
59
|
+
return getFederatedShareLink(existingDocument);
|
|
60
|
+
|
|
61
|
+
case 5:
|
|
62
|
+
link = _context.sent;
|
|
63
|
+
setSharingLink(link);
|
|
64
|
+
_context.next = 10;
|
|
65
|
+
break;
|
|
66
|
+
|
|
67
|
+
case 9:
|
|
68
|
+
setSharingLink(getSharingLink(existingDocument._id));
|
|
69
|
+
|
|
70
|
+
case 10:
|
|
71
|
+
case "end":
|
|
72
|
+
return _context.stop();
|
|
73
|
+
}
|
|
74
|
+
}, _callee);
|
|
75
|
+
}));
|
|
76
|
+
|
|
77
|
+
return function fetchSharingLink() {
|
|
78
|
+
return _ref2.apply(this, arguments);
|
|
79
|
+
};
|
|
80
|
+
}();
|
|
28
81
|
|
|
29
|
-
|
|
82
|
+
fetchSharingLink();
|
|
83
|
+
}, [existingDocument, documentPermissions, getFederatedShareLink, getSharingLink, getOwner, getSharingById]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
30
84
|
|
|
31
|
-
var
|
|
85
|
+
var _useState3 = useState({
|
|
32
86
|
recipients: [],
|
|
33
87
|
readOnlyRecipients: []
|
|
34
88
|
}),
|
|
35
|
-
|
|
36
|
-
federatedRecipients =
|
|
37
|
-
setFederatedRecipients =
|
|
89
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
90
|
+
federatedRecipients = _useState4[0],
|
|
91
|
+
setFederatedRecipients = _useState4[1];
|
|
38
92
|
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
folderName =
|
|
93
|
+
var _useState5 = useState((existingDocument === null || existingDocument === void 0 ? void 0 : existingDocument.name) || ''),
|
|
94
|
+
_useState6 = _slicedToArray(_useState5, 1),
|
|
95
|
+
folderName = _useState6[0];
|
|
42
96
|
|
|
43
97
|
var onShare = function onShare(params) {
|
|
44
98
|
setFederatedRecipients({
|
|
@@ -48,12 +102,12 @@ export var FederatedFolderModal = withLocales(function (_ref) {
|
|
|
48
102
|
};
|
|
49
103
|
|
|
50
104
|
var onSend = /*#__PURE__*/function () {
|
|
51
|
-
var
|
|
52
|
-
return _regeneratorRuntime.wrap(function
|
|
53
|
-
while (1) switch (
|
|
105
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
106
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
107
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
54
108
|
case 0:
|
|
55
|
-
|
|
56
|
-
|
|
109
|
+
_context2.prev = 0;
|
|
110
|
+
_context2.next = 3;
|
|
57
111
|
return share({
|
|
58
112
|
description: folderName,
|
|
59
113
|
document: existingDocument,
|
|
@@ -70,12 +124,12 @@ export var FederatedFolderModal = withLocales(function (_ref) {
|
|
|
70
124
|
variant: 'filled'
|
|
71
125
|
});
|
|
72
126
|
onClose();
|
|
73
|
-
|
|
127
|
+
_context2.next = 10;
|
|
74
128
|
break;
|
|
75
129
|
|
|
76
130
|
case 7:
|
|
77
|
-
|
|
78
|
-
|
|
131
|
+
_context2.prev = 7;
|
|
132
|
+
_context2.t0 = _context2["catch"](0);
|
|
79
133
|
showAlert({
|
|
80
134
|
message: t('FederatedFolder.errorNotification'),
|
|
81
135
|
severity: 'error',
|
|
@@ -84,13 +138,13 @@ export var FederatedFolderModal = withLocales(function (_ref) {
|
|
|
84
138
|
|
|
85
139
|
case 10:
|
|
86
140
|
case "end":
|
|
87
|
-
return
|
|
141
|
+
return _context2.stop();
|
|
88
142
|
}
|
|
89
|
-
},
|
|
143
|
+
}, _callee2, null, [[0, 7]]);
|
|
90
144
|
}));
|
|
91
145
|
|
|
92
146
|
return function onSend() {
|
|
93
|
-
return
|
|
147
|
+
return _ref3.apply(this, arguments);
|
|
94
148
|
};
|
|
95
149
|
}();
|
|
96
150
|
|
|
@@ -126,6 +180,7 @@ export var FederatedFolderModal = withLocales(function (_ref) {
|
|
|
126
180
|
var modalTitle = t('FederatedFolder.shareTitle', {
|
|
127
181
|
name: folderName
|
|
128
182
|
});
|
|
183
|
+
var isSharedDrive = Boolean(existingDocument === null || existingDocument === void 0 ? void 0 : existingDocument.driveId);
|
|
129
184
|
return /*#__PURE__*/React.createElement(DumbFederatedFolderModal, {
|
|
130
185
|
title: modalTitle,
|
|
131
186
|
document: existingDocument,
|
|
@@ -140,7 +195,8 @@ export var FederatedFolderModal = withLocales(function (_ref) {
|
|
|
140
195
|
onSend: onSend,
|
|
141
196
|
onClose: onClose,
|
|
142
197
|
onShare: onShare,
|
|
143
|
-
sharingLink: sharingLink
|
|
198
|
+
sharingLink: sharingLink,
|
|
199
|
+
showShareByEmail: !isSharedDrive
|
|
144
200
|
});
|
|
145
201
|
});
|
|
146
202
|
FederatedFolderModal.propTypes = {
|
|
@@ -31,7 +31,6 @@ var LinkRecipient = function LinkRecipient(props) {
|
|
|
31
31
|
|
|
32
32
|
var recipientConfirmationData = props.recipientConfirmationData,
|
|
33
33
|
verifyRecipient = props.verifyRecipient,
|
|
34
|
-
link = props.link,
|
|
35
34
|
fadeIn = props.fadeIn,
|
|
36
35
|
document = props.document;
|
|
37
36
|
var permissions = getDocumentPermissions(document === null || document === void 0 ? void 0 : document._id);
|
|
@@ -41,7 +40,7 @@ var LinkRecipient = function LinkRecipient(props) {
|
|
|
41
40
|
var textPrimary = hasPassword ? t('Share.recipients.linkWithPassword') : t('Share.recipients.anyoneWithTheLink');
|
|
42
41
|
var textSecondary = expiresDate ? t('Share.recipients.expires', {
|
|
43
42
|
date: dateFormatted
|
|
44
|
-
}) :
|
|
43
|
+
}) : '';
|
|
45
44
|
var RightPart = recipientConfirmationData ? /*#__PURE__*/React.createElement(RecipientConfirm, {
|
|
46
45
|
recipientConfirmationData: recipientConfirmationData,
|
|
47
46
|
verifyRecipient: verifyRecipient
|
|
@@ -70,6 +69,10 @@ var LinkRecipient = function LinkRecipient(props) {
|
|
|
70
69
|
};
|
|
71
70
|
|
|
72
71
|
LinkRecipient.propTypes = {
|
|
73
|
-
|
|
72
|
+
recipientConfirmationData: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
|
|
73
|
+
verifyRecipient: PropTypes.func,
|
|
74
|
+
fadeIn: PropTypes.bool,
|
|
75
|
+
document: PropTypes.object,
|
|
76
|
+
permissions: PropTypes.arrayOf(PropTypes.object)
|
|
74
77
|
};
|
|
75
78
|
export default LinkRecipient;
|
|
@@ -5,6 +5,19 @@ import React from 'react';
|
|
|
5
5
|
import { createMockClient } from 'cozy-client';
|
|
6
6
|
import MemberRecipient from './MemberRecipient';
|
|
7
7
|
import AppLike from '../../../test/AppLike';
|
|
8
|
+
var mockUpdateDocumentPermissions = jest.fn();
|
|
9
|
+
var mockUpdateSharingMemberType = jest.fn();
|
|
10
|
+
jest.mock('../../hooks/useSharingContext', function () {
|
|
11
|
+
return {
|
|
12
|
+
// eslint-disable-next-line react/display-name
|
|
13
|
+
useSharingContext: function useSharingContext() {
|
|
14
|
+
return {
|
|
15
|
+
updateDocumentPermissions: mockUpdateDocumentPermissions,
|
|
16
|
+
updateSharingMemberType: mockUpdateSharingMemberType
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
});
|
|
8
21
|
describe('MemberRecipient component', function () {
|
|
9
22
|
var client = createMockClient({});
|
|
10
23
|
client.options = {
|