cozy-sharing 19.0.0 → 21.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/dist/SharingProvider.js +16 -9
  3. package/dist/actions/{openSharingLink.js → addToCozySharingLink.js} +12 -16
  4. package/dist/actions/createCozySharingLink.js +51 -0
  5. package/dist/actions/syncToCozySharingLink.js +51 -0
  6. package/dist/components/Recipient/LinkRecipient.js +20 -4
  7. package/dist/components/ShareRestrictionModal/BoxPassword.js +21 -4
  8. package/dist/components/ShareRestrictionModal/ShareRestrictionContentModal.js +33 -9
  9. package/dist/components/ShareRestrictionModal/ShareRestrictionModal.js +74 -78
  10. package/dist/components/ShareRestrictionModal/helpers.js +82 -47
  11. package/dist/components/ShareRestrictionModal/helpers.spec.js +142 -20
  12. package/dist/components/SharingBanner/components/PublicBanner.js +3 -3
  13. package/dist/components/SharingBanner/components/PublicBanner.spec.js +1 -1
  14. package/dist/components/SharingBanner/components/SharingBanner.js +3 -3
  15. package/dist/components/SharingBanner/hooks/useSharingInfos.js +37 -25
  16. package/dist/components/SharingBanner/hooks/useSharingInfos.spec.js +9 -9
  17. package/dist/helpers/permissions.js +15 -0
  18. package/dist/index.js +3 -1
  19. package/locales/en.json +2 -0
  20. package/locales/fr.json +2 -0
  21. package/package.json +4 -4
  22. package/src/SharingProvider.jsx +10 -5
  23. package/src/actions/addToCozySharingLink.js +51 -0
  24. package/src/actions/createCozySharingLink.js +47 -0
  25. package/src/actions/{openSharingLink.js → syncToCozySharingLink.js} +10 -12
  26. package/src/components/Recipient/LinkRecipient.jsx +28 -4
  27. package/src/components/ShareRestrictionModal/BoxPassword.jsx +14 -0
  28. package/src/components/ShareRestrictionModal/ShareRestrictionContentModal.jsx +31 -9
  29. package/src/components/ShareRestrictionModal/ShareRestrictionModal.jsx +55 -46
  30. package/src/components/ShareRestrictionModal/helpers.js +65 -31
  31. package/src/components/ShareRestrictionModal/helpers.spec.js +92 -11
  32. package/src/components/SharingBanner/components/PublicBanner.jsx +3 -3
  33. package/src/components/SharingBanner/components/PublicBanner.spec.jsx +1 -1
  34. package/src/components/SharingBanner/components/SharingBanner.jsx +3 -3
  35. package/src/components/SharingBanner/hooks/useSharingInfos.jsx +12 -3
  36. package/src/components/SharingBanner/hooks/useSharingInfos.spec.js +7 -7
  37. package/src/helpers/permissions.js +12 -0
  38. package/src/index.jsx +3 -1
@@ -4,17 +4,15 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
4
  import { addDays } from 'date-fns';
5
5
  import PropTypes from 'prop-types';
6
6
  import React, { useState } from 'react';
7
- import { useClient } from 'cozy-client';
8
- import { getSharingLink as makeSharingLink } from 'cozy-client/dist/models/sharing';
9
- import { isMobile } from 'cozy-device-helper';
7
+ import { generateWebLink, useClient } from 'cozy-client';
10
8
  import Button from 'cozy-ui/transpiled/react/Buttons';
11
9
  import { ConfirmDialog } from 'cozy-ui/transpiled/react/CozyDialogs';
12
10
  import Icon from 'cozy-ui/transpiled/react/Icon';
13
11
  import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert';
14
12
  import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
15
13
  import { ShareRestrictionContentModal } from './ShareRestrictionContentModal';
16
- import { copyToClipboard, forwardFile, updatePermissions, makeTTL, READ_ONLY_PERMS, WRITE_PERMS, revokePermissions } from './helpers';
17
- import { checkIsReadOnlyPermissions } from '../../helpers/permissions';
14
+ import { copyToClipboard, updatePermissions, makeTTL, revokePermissions, createPermissions } from './helpers';
15
+ import { checkIsPermissionHasExpiresDate, checkIsPermissionHasPassword, checkIsReadOnlyPermissions, getPermissionExpiresDate } from '../../helpers/permissions';
18
16
  import { useSharingContext } from '../../hooks/useSharingContext';
19
17
  var PASSWORD_MIN_LENGTH = 4;
20
18
  export var ShareRestrictionModal = function ShareRestrictionModal(_ref) {
@@ -33,35 +31,20 @@ export var ShareRestrictionModal = function ShareRestrictionModal(_ref) {
33
31
  password = _useState2[0],
34
32
  setPassword = _useState2[1];
35
33
 
36
- var _useState3 = useState(addDays(new Date(), 30)),
34
+ var _useState3 = useState(true),
37
35
  _useState4 = _slicedToArray(_useState3, 2),
38
- selectedDate = _useState4[0],
39
- setSelectedDate = _useState4[1];
36
+ isValidDate = _useState4[0],
37
+ setIsValidDate = _useState4[1];
40
38
 
41
39
  var _useState5 = useState(true),
42
40
  _useState6 = _slicedToArray(_useState5, 2),
43
- isValidDate = _useState6[0],
44
- setIsValidDate = _useState6[1];
41
+ isValidPassword = _useState6[0],
42
+ setIsValidPassword = _useState6[1];
45
43
 
46
- var _useState7 = useState(true),
44
+ var _useState7 = useState(false),
47
45
  _useState8 = _slicedToArray(_useState7, 2),
48
- isValidPassword = _useState8[0],
49
- setIsValidPassword = _useState8[1];
50
-
51
- var _useState9 = useState(true),
52
- _useState10 = _slicedToArray(_useState9, 2),
53
- dateToggle = _useState10[0],
54
- setDateToggle = _useState10[1];
55
-
56
- var _useState11 = useState(false),
57
- _useState12 = _slicedToArray(_useState11, 2),
58
- passwordToggle = _useState12[0],
59
- setPasswordToggle = _useState12[1];
60
-
61
- var _useState13 = useState(false),
62
- _useState14 = _slicedToArray(_useState13, 2),
63
- loading = _useState14[0],
64
- setLoading = _useState14[1];
46
+ loading = _useState8[0],
47
+ setLoading = _useState8[1];
65
48
 
66
49
  var _useSharingContext = useSharingContext(),
67
50
  documentType = _useSharingContext.documentType,
@@ -74,25 +57,38 @@ export var ShareRestrictionModal = function ShareRestrictionModal(_ref) {
74
57
  var hasSharingLink = getSharingLink(file._id) !== null;
75
58
  var permissions = getDocumentPermissions(file._id);
76
59
  var isReadOnlyPermissions = checkIsReadOnlyPermissions(permissions);
60
+ var hasPassword = checkIsPermissionHasPassword(permissions);
61
+ var hasExpiresDate = checkIsPermissionHasExpiresDate(permissions);
62
+ var expiresDate = getPermissionExpiresDate(permissions);
63
+ var defaultDate = expiresDate ? new Date(expiresDate) : addDays(new Date(), 30);
64
+
65
+ var _useState9 = useState(defaultDate),
66
+ _useState10 = _slicedToArray(_useState9, 2),
67
+ selectedDate = _useState10[0],
68
+ setSelectedDate = _useState10[1];
69
+
70
+ var _useState11 = useState(permissions.length > 0 ? hasExpiresDate : true),
71
+ _useState12 = _slicedToArray(_useState11, 2),
72
+ dateToggle = _useState12[0],
73
+ setDateToggle = _useState12[1];
74
+
75
+ var _useState13 = useState(hasPassword),
76
+ _useState14 = _slicedToArray(_useState13, 2),
77
+ passwordToggle = _useState14[0],
78
+ setPasswordToggle = _useState14[1];
77
79
 
78
80
  var _useState15 = useState(isReadOnlyPermissions || permissions.length === 0 ? 'readOnly' : 'write'),
79
81
  _useState16 = _slicedToArray(_useState15, 2),
80
82
  editingRights = _useState16[0],
81
83
  setEditingRights = _useState16[1];
82
84
 
83
- var isDesktopOrMobileWithoutShareAPI = isMobile() && !navigator.share || !isMobile();
84
85
  var helperTextPassword = !isValidPassword ? t('ShareRestrictionModal.invalidPasswordMessage', {
85
86
  smart_count: PASSWORD_MIN_LENGTH - password.length
86
87
  }) : null;
87
88
 
88
- var handleDateChange = function handleDateChange(date, isValid) {
89
- setSelectedDate(date);
90
- setIsValidDate(isValid);
91
- };
92
-
93
89
  var handleClick = /*#__PURE__*/function () {
94
90
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
95
- var verbs, url, ttl, _url;
91
+ var ttl, _yield$createPermissi2, perms, url, _yield$updatePermissi3, _yield$updatePermissi4, _perms, _url;
96
92
 
97
93
  return _regeneratorRuntime.wrap(function _callee$(_context) {
98
94
  while (1) switch (_context.prev = _context.next) {
@@ -100,80 +96,80 @@ export var ShareRestrictionModal = function ShareRestrictionModal(_ref) {
100
96
  setLoading(true); // If the file is not shared, we create a new sharing link
101
97
 
102
98
  if (hasSharingLink) {
103
- _context.next = 10;
99
+ _context.next = 13;
104
100
  break;
105
101
  }
106
102
 
107
- verbs = editingRights === 'readOnly' ? READ_ONLY_PERMS : WRITE_PERMS;
103
+ ttl = makeTTL(dateToggle && selectedDate);
108
104
  _context.next = 5;
109
- return shareByLink(file, {
110
- verbs: verbs
105
+ return createPermissions({
106
+ file: file,
107
+ t: t,
108
+ ttl: ttl,
109
+ password: password,
110
+ editingRights: editingRights,
111
+ documentType: documentType,
112
+ shareByLink: shareByLink,
113
+ showAlert: showAlert
111
114
  });
112
115
 
113
116
  case 5:
114
- url = getSharingLink(file._id);
115
- _context.next = 8;
117
+ _yield$createPermissi2 = _context.sent;
118
+ perms = _yield$createPermissi2.data;
119
+ url = generateWebLink({
120
+ cozyUrl: client.getStackClient().uri,
121
+ searchParams: [['sharecode', perms.attributes.shortcodes.code]],
122
+ pathname: '/public',
123
+ slug: 'drive',
124
+ subDomainType: client.capabilities.flat_subdomains ? 'flat' : 'nested'
125
+ });
126
+ _context.next = 10;
116
127
  return copyToClipboard(url, {
117
128
  t: t,
118
129
  showAlert: showAlert
119
130
  });
120
131
 
121
- case 8:
132
+ case 10:
122
133
  onClose();
123
- return _context.abrupt("return");
134
+ _context.next = 22;
135
+ break;
124
136
 
125
- case 10:
126
- _context.next = 12;
137
+ case 13:
138
+ _context.next = 15;
127
139
  return updatePermissions({
128
140
  file: file,
129
141
  t: t,
142
+ dateToggle: dateToggle,
143
+ selectedDate: selectedDate,
144
+ passwordToggle: passwordToggle,
145
+ password: password,
130
146
  editingRights: editingRights,
131
147
  documentType: documentType,
132
148
  updateDocumentPermissions: updateDocumentPermissions,
133
149
  showAlert: showAlert
134
150
  });
135
151
 
136
- case 12:
137
- ttl = makeTTL(dateToggle && selectedDate);
138
-
139
- if (!isDesktopOrMobileWithoutShareAPI) {
140
- _context.next = 21;
141
- break;
142
- }
143
-
144
- _context.next = 16;
145
- return makeSharingLink(client, [file._id], {
146
- ttl: ttl,
147
- password: password
152
+ case 15:
153
+ _yield$updatePermissi3 = _context.sent;
154
+ _yield$updatePermissi4 = _slicedToArray(_yield$updatePermissi3, 1);
155
+ _perms = _yield$updatePermissi4[0].data;
156
+ _url = generateWebLink({
157
+ cozyUrl: client.getStackClient().uri,
158
+ searchParams: [['sharecode', _perms.attributes.shortcodes.code]],
159
+ pathname: '/public',
160
+ slug: 'drive',
161
+ subDomainType: client.capabilities.flat_subdomains ? 'flat' : 'nested'
148
162
  });
149
-
150
- case 16:
151
- _url = _context.sent;
152
- _context.next = 19;
163
+ _context.next = 21;
153
164
  return copyToClipboard(_url, {
154
165
  t: t,
155
166
  showAlert: showAlert
156
167
  });
157
168
 
158
- case 19:
159
- _context.next = 23;
160
- break;
161
-
162
169
  case 21:
163
- _context.next = 23;
164
- return forwardFile({
165
- client: client,
166
- file: file,
167
- t: t,
168
- ttl: ttl,
169
- password: password,
170
- showAlert: showAlert
171
- });
172
-
173
- case 23:
174
170
  onClose();
175
171
 
176
- case 24:
172
+ case 22:
177
173
  case "end":
178
174
  return _context.stop();
179
175
  }
@@ -223,7 +219,7 @@ export var ShareRestrictionModal = function ShareRestrictionModal(_ref) {
223
219
  ,
224
220
  dateToggle: dateToggle,
225
221
  setDateToggle: setDateToggle,
226
- setSelectedDate: handleDateChange,
222
+ setSelectedDate: setSelectedDate,
227
223
  selectedDate: selectedDate,
228
224
  setIsValidDate: setIsValidDate // Password
229
225
  ,
@@ -166,70 +166,105 @@ export var forwardFile = /*#__PURE__*/function () {
166
166
  };
167
167
  }();
168
168
  /**
169
- * updatePermissions - Updates the permissions of a file
169
+ * createPermissions - Create the permissions of a file
170
170
  * @param {object} options
171
171
  * @param {import('cozy-client/types/types').IOCozyFile} options.file File to update permissions
172
172
  * @param {Function} options.t i18n function
173
- * @param {string} options.documentType - Type of the document
173
+ * @param {Date|string} options.ttl - Time to live of the sharing link
174
+ * @param {string} options.password - Password
174
175
  * @param {'readOnly'|'write'} options.editingRights - Editing rights
175
- * @param {Function} options.updateDocumentPermissions - Function to update permissions
176
+ * @param {string} options.documentType - Type of the document
177
+ * @param {Function} options.shareByLink - Function to create permissions
176
178
  * @param {Function} options.showAlert - Function to display an alert
177
179
  */
178
180
 
179
- export var updatePermissions = /*#__PURE__*/function () {
181
+ export var createPermissions = /*#__PURE__*/function () {
180
182
  var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref5) {
181
- var file, t, editingRights, documentType, updateDocumentPermissions, showAlert;
183
+ var file, t, ttl, password, editingRights, documentType, shareByLink, showAlert, verbs;
182
184
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
183
185
  while (1) switch (_context3.prev = _context3.next) {
184
186
  case 0:
185
- file = _ref5.file, t = _ref5.t, editingRights = _ref5.editingRights, documentType = _ref5.documentType, updateDocumentPermissions = _ref5.updateDocumentPermissions, showAlert = _ref5.showAlert;
186
- _context3.t0 = editingRights;
187
- _context3.next = _context3.t0 === 'readOnly' ? 4 : _context3.t0 === 'write' ? 13 : 22;
188
- break;
189
-
190
- case 4:
191
- _context3.prev = 4;
192
- return _context3.abrupt("return", updateDocumentPermissions(file, READ_ONLY_PERMS));
187
+ file = _ref5.file, t = _ref5.t, ttl = _ref5.ttl, password = _ref5.password, editingRights = _ref5.editingRights, documentType = _ref5.documentType, shareByLink = _ref5.shareByLink, showAlert = _ref5.showAlert;
188
+ _context3.prev = 1;
189
+ verbs = editingRights === 'readOnly' ? READ_ONLY_PERMS : WRITE_PERMS;
190
+ return _context3.abrupt("return", shareByLink(file, {
191
+ verbs: verbs,
192
+ ttl: ttl,
193
+ password: password
194
+ }));
193
195
 
194
- case 8:
195
- _context3.prev = 8;
196
- _context3.t1 = _context3["catch"](4);
196
+ case 6:
197
+ _context3.prev = 6;
198
+ _context3.t0 = _context3["catch"](1);
197
199
  showAlert({
198
200
  message: t("".concat(documentType, ".share.shareByLink.permserror")),
199
201
  severity: 'error',
200
202
  variant: 'filled'
201
203
  });
202
- log.error("Error in 'readOnlyPermissionLink' function when trying to change permission", _context3.t1);
204
+ log.error("Error in 'readOnlyPermissionLink' function when trying to change permission", _context3.t0);
203
205
 
204
- case 12:
205
- return _context3.abrupt("break", 22);
206
+ case 10:
207
+ case "end":
208
+ return _context3.stop();
209
+ }
210
+ }, _callee3, null, [[1, 6]]);
211
+ }));
206
212
 
207
- case 13:
208
- _context3.prev = 13;
209
- return _context3.abrupt("return", updateDocumentPermissions(file, WRITE_PERMS));
213
+ return function createPermissions(_x3) {
214
+ return _ref6.apply(this, arguments);
215
+ };
216
+ }();
217
+ /**
218
+ * updatePermissions - Updates the permissions of a file
219
+ * @param {object} options
220
+ * @param {import('cozy-client/types/types').IOCozyFile} options.file File to update permissions
221
+ * @param {Function} options.t i18n function
222
+ * @param {boolean} options.dateToggle - Expiration date toggle
223
+ * @param {Date|null} options.selectedDate - Expiration date
224
+ * @param {boolean} options.passwordToggle - Password toggle
225
+ * @param {string} options.password - Password
226
+ * @param {string} options.documentType - Type of the document
227
+ * @param {'readOnly'|'write'} options.editingRights - Editing rights
228
+ * @param {Function} options.updateDocumentPermissions - Function to update permissions
229
+ * @param {Function} options.showAlert - Function to display an alert
230
+ */
231
+
232
+ export var updatePermissions = /*#__PURE__*/function () {
233
+ var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref7) {
234
+ var file, t, dateToggle, selectedDate, passwordToggle, password, editingRights, documentType, updateDocumentPermissions, showAlert, expiresAt, ensurePassword, verbs;
235
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
236
+ while (1) switch (_context4.prev = _context4.next) {
237
+ case 0:
238
+ file = _ref7.file, t = _ref7.t, dateToggle = _ref7.dateToggle, selectedDate = _ref7.selectedDate, passwordToggle = _ref7.passwordToggle, password = _ref7.password, editingRights = _ref7.editingRights, documentType = _ref7.documentType, updateDocumentPermissions = _ref7.updateDocumentPermissions, showAlert = _ref7.showAlert;
239
+ _context4.prev = 1;
240
+ expiresAt = dateToggle ? (selectedDate === null || selectedDate === void 0 ? void 0 : selectedDate.toISOString()) || undefined : '';
241
+ ensurePassword = passwordToggle ? password || undefined : '';
242
+ verbs = editingRights === 'readOnly' ? READ_ONLY_PERMS : WRITE_PERMS;
243
+ return _context4.abrupt("return", updateDocumentPermissions(file, {
244
+ verbs: verbs,
245
+ expiresAt: expiresAt,
246
+ password: ensurePassword
247
+ }));
210
248
 
211
- case 17:
212
- _context3.prev = 17;
213
- _context3.t2 = _context3["catch"](13);
249
+ case 8:
250
+ _context4.prev = 8;
251
+ _context4.t0 = _context4["catch"](1);
214
252
  showAlert({
215
253
  message: t("".concat(documentType, ".share.shareByLink.permserror")),
216
254
  severity: 'error',
217
255
  variant: 'filled'
218
256
  });
219
- log.error("Error in 'editPermissionLink' function when trying to change permission", _context3.t2);
257
+ log.error("Error in 'updateDocumentPermissions' function when trying to change permission", _context4.t0);
220
258
 
221
- case 21:
222
- return _context3.abrupt("break", 22);
223
-
224
- case 22:
259
+ case 12:
225
260
  case "end":
226
- return _context3.stop();
261
+ return _context4.stop();
227
262
  }
228
- }, _callee3, null, [[4, 8], [13, 17]]);
263
+ }, _callee4, null, [[1, 8]]);
229
264
  }));
230
265
 
231
- return function updatePermissions(_x3) {
232
- return _ref6.apply(this, arguments);
266
+ return function updatePermissions(_x4) {
267
+ return _ref8.apply(this, arguments);
233
268
  };
234
269
  }();
235
270
  /**
@@ -243,33 +278,33 @@ export var updatePermissions = /*#__PURE__*/function () {
243
278
  */
244
279
 
245
280
  export var revokePermissions = /*#__PURE__*/function () {
246
- var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref7) {
281
+ var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref9) {
247
282
  var file, t, documentType, revokeSharingLink, showAlert;
248
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
249
- while (1) switch (_context4.prev = _context4.next) {
283
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
284
+ while (1) switch (_context5.prev = _context5.next) {
250
285
  case 0:
251
- file = _ref7.file, t = _ref7.t, documentType = _ref7.documentType, revokeSharingLink = _ref7.revokeSharingLink, showAlert = _ref7.showAlert;
252
- _context4.prev = 1;
253
- return _context4.abrupt("return", revokeSharingLink(file));
286
+ file = _ref9.file, t = _ref9.t, documentType = _ref9.documentType, revokeSharingLink = _ref9.revokeSharingLink, showAlert = _ref9.showAlert;
287
+ _context5.prev = 1;
288
+ return _context5.abrupt("return", revokeSharingLink(file));
254
289
 
255
290
  case 5:
256
- _context4.prev = 5;
257
- _context4.t0 = _context4["catch"](1);
291
+ _context5.prev = 5;
292
+ _context5.t0 = _context5["catch"](1);
258
293
  showAlert({
259
294
  message: t("".concat(documentType, ".share.error.revoke")),
260
295
  severity: 'error',
261
296
  variant: 'filled'
262
297
  });
263
- log.error("Error in 'revokePermissions' function when trying to revoke sharing link", _context4.t0);
298
+ log.error("Error in 'revokePermissions' function when trying to revoke sharing link", _context5.t0);
264
299
 
265
300
  case 9:
266
301
  case "end":
267
- return _context4.stop();
302
+ return _context5.stop();
268
303
  }
269
- }, _callee4, null, [[1, 5]]);
304
+ }, _callee5, null, [[1, 5]]);
270
305
  }));
271
306
 
272
- return function revokePermissions(_x4) {
273
- return _ref8.apply(this, arguments);
307
+ return function revokePermissions(_x5) {
308
+ return _ref10.apply(this, arguments);
274
309
  };
275
310
  }();
@@ -19,7 +19,7 @@ describe('ShareRestrictionModal/helpers', function () {
19
19
  describe('updatePermissions', function () {
20
20
  var documentType = 'Files';
21
21
  it('should call updateDocumentPermissions with "readOnly" permission', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
22
- var updateDocumentPermissions, file, editingRights;
22
+ var updateDocumentPermissions, file;
23
23
  return _regeneratorRuntime.wrap(function _callee$(_context) {
24
24
  while (1) switch (_context.prev = _context.next) {
25
25
  case 0:
@@ -27,28 +27,35 @@ describe('ShareRestrictionModal/helpers', function () {
27
27
  file = {
28
28
  _id: '123'
29
29
  };
30
- editingRights = 'readOnly';
31
- _context.next = 5;
30
+ _context.next = 4;
32
31
  return updatePermissions({
33
32
  file: file,
34
33
  t: jest.fn(),
35
- editingRights: editingRights,
34
+ dateToggle: false,
35
+ selectedDate: null,
36
+ passwordToggle: false,
37
+ password: '',
38
+ editingRights: 'readOnly',
36
39
  documentType: documentType,
37
40
  updateDocumentPermissions: updateDocumentPermissions,
38
41
  showAlert: jest.fn()
39
42
  });
40
43
 
41
- case 5:
42
- expect(updateDocumentPermissions).toHaveBeenCalledWith(file, ['GET']);
44
+ case 4:
45
+ expect(updateDocumentPermissions).toHaveBeenCalledWith(file, {
46
+ expiresAt: '',
47
+ password: '',
48
+ verbs: ['GET']
49
+ });
43
50
 
44
- case 6:
51
+ case 5:
45
52
  case "end":
46
53
  return _context.stop();
47
54
  }
48
55
  }, _callee);
49
56
  })));
50
57
  it('should call updateDocumentPermissions with "write" permissions', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
51
- var updateDocumentPermissions, file, editingRights;
58
+ var updateDocumentPermissions, file;
52
59
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
53
60
  while (1) switch (_context2.prev = _context2.next) {
54
61
  case 0:
@@ -56,39 +63,154 @@ describe('ShareRestrictionModal/helpers', function () {
56
63
  file = {
57
64
  _id: '123'
58
65
  };
59
- editingRights = 'write';
60
- _context2.next = 5;
66
+ _context2.next = 4;
61
67
  return updatePermissions({
62
68
  file: file,
63
69
  t: jest.fn(),
64
- editingRights: editingRights,
70
+ dateToggle: false,
71
+ selectedDate: null,
72
+ passwordToggle: false,
73
+ password: '',
74
+ editingRights: 'write',
65
75
  documentType: documentType,
66
76
  updateDocumentPermissions: updateDocumentPermissions,
67
77
  showAlert: jest.fn()
68
78
  });
69
79
 
70
- case 5:
71
- expect(updateDocumentPermissions).toHaveBeenCalledWith(file, ['GET', 'POST', 'PUT', 'PATCH']);
80
+ case 4:
81
+ expect(updateDocumentPermissions).toHaveBeenCalledWith(file, {
82
+ expiresAt: '',
83
+ password: '',
84
+ verbs: ['GET', 'POST', 'PUT', 'PATCH']
85
+ });
72
86
 
73
- case 6:
87
+ case 5:
74
88
  case "end":
75
89
  return _context2.stop();
76
90
  }
77
91
  }, _callee2);
78
92
  })));
93
+ it('should call updateDocumentPermissions with empty date & password if their switches are false', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
94
+ var updateDocumentPermissions, file;
95
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
96
+ while (1) switch (_context3.prev = _context3.next) {
97
+ case 0:
98
+ updateDocumentPermissions = jest.fn();
99
+ file = {
100
+ _id: '123'
101
+ };
102
+ _context3.next = 4;
103
+ return updatePermissions({
104
+ file: file,
105
+ t: jest.fn(),
106
+ dateToggle: false,
107
+ selectedDate: null,
108
+ passwordToggle: false,
109
+ password: '',
110
+ editingRights: 'readOnly',
111
+ documentType: documentType,
112
+ updateDocumentPermissions: updateDocumentPermissions,
113
+ showAlert: jest.fn()
114
+ });
115
+
116
+ case 4:
117
+ expect(updateDocumentPermissions).toHaveBeenCalledWith(file, {
118
+ expiresAt: '',
119
+ password: '',
120
+ verbs: ['GET']
121
+ });
122
+
123
+ case 5:
124
+ case "end":
125
+ return _context3.stop();
126
+ }
127
+ }, _callee3);
128
+ })));
129
+ it('should call updateDocumentPermissions with "undefined" date & password if their switches are true but the permission doesn\'t yet have these values', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
130
+ var updateDocumentPermissions, file;
131
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
132
+ while (1) switch (_context4.prev = _context4.next) {
133
+ case 0:
134
+ updateDocumentPermissions = jest.fn();
135
+ file = {
136
+ _id: '123'
137
+ };
138
+ _context4.next = 4;
139
+ return updatePermissions({
140
+ file: file,
141
+ t: jest.fn(),
142
+ dateToggle: true,
143
+ selectedDate: null,
144
+ passwordToggle: true,
145
+ password: '',
146
+ editingRights: 'readOnly',
147
+ documentType: documentType,
148
+ updateDocumentPermissions: updateDocumentPermissions,
149
+ showAlert: jest.fn()
150
+ });
151
+
152
+ case 4:
153
+ expect(updateDocumentPermissions).toHaveBeenCalledWith(file, {
154
+ expiresAt: undefined,
155
+ password: undefined,
156
+ verbs: ['GET']
157
+ });
158
+
159
+ case 5:
160
+ case "end":
161
+ return _context4.stop();
162
+ }
163
+ }, _callee4);
164
+ })));
165
+ it('should call updateDocumentPermissions with expected date & password if their switches are true', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
166
+ var updateDocumentPermissions, file;
167
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
168
+ while (1) switch (_context5.prev = _context5.next) {
169
+ case 0:
170
+ updateDocumentPermissions = jest.fn();
171
+ file = {
172
+ _id: '123'
173
+ };
174
+ _context5.next = 4;
175
+ return updatePermissions({
176
+ file: file,
177
+ t: jest.fn(),
178
+ dateToggle: true,
179
+ selectedDate: new Date('2100-01-01T00:00:00.000Z'),
180
+ passwordToggle: true,
181
+ password: '1234',
182
+ editingRights: 'readOnly',
183
+ documentType: documentType,
184
+ updateDocumentPermissions: updateDocumentPermissions,
185
+ showAlert: jest.fn()
186
+ });
187
+
188
+ case 4:
189
+ expect(updateDocumentPermissions).toHaveBeenCalledWith(file, {
190
+ expiresAt: '2100-01-01T00:00:00.000Z',
191
+ password: '1234',
192
+ verbs: ['GET']
193
+ });
194
+
195
+ case 5:
196
+ case "end":
197
+ return _context5.stop();
198
+ }
199
+ }, _callee5);
200
+ })));
79
201
  });
80
202
  describe('revokePermissions', function () {
81
203
  var documentType = 'Files';
82
- it('should call revokeSharingLink', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
204
+ it('should call revokeSharingLink', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
83
205
  var revokeSharingLink, file;
84
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
85
- while (1) switch (_context3.prev = _context3.next) {
206
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
207
+ while (1) switch (_context6.prev = _context6.next) {
86
208
  case 0:
87
209
  revokeSharingLink = jest.fn();
88
210
  file = {
89
211
  _id: '123'
90
212
  };
91
- _context3.next = 4;
213
+ _context6.next = 4;
92
214
  return revokePermissions({
93
215
  file: file,
94
216
  t: jest.fn(),
@@ -102,9 +224,9 @@ describe('ShareRestrictionModal/helpers', function () {
102
224
 
103
225
  case 5:
104
226
  case "end":
105
- return _context3.stop();
227
+ return _context6.stop();
106
228
  }
107
- }, _callee3);
229
+ }, _callee6);
108
230
  })));
109
231
  });
110
232
  });