cozy-sharing 18.0.0 → 19.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 +31 -0
- package/dist/components/Recipient/LinkRecipientPermissions.js +18 -129
- package/dist/components/Recipient/actions/editPermissionLink.js +71 -0
- package/dist/components/Recipient/actions/readOnlyPermissionLink.js +63 -0
- package/dist/components/ShareByLink.js +45 -185
- package/dist/components/ShareDialogCozyToCozy.js +2 -6
- package/dist/components/ShareDialogOnlyByLink.js +2 -8
- package/dist/components/ShareDialogTwoStepsConfirmationContainer.js +1 -3
- package/dist/components/ShareModal/EditableSharingModal.js +1 -7
- package/dist/components/ShareModal.js +0 -12
- package/dist/components/ShareRestrictionModal/BoxDate.js +77 -0
- package/dist/components/ShareRestrictionModal/BoxEditingRights.js +83 -0
- package/dist/components/ShareRestrictionModal/BoxPassword.js +138 -0
- package/dist/components/ShareRestrictionModal/ShareRestrictionContentModal.js +94 -0
- package/dist/components/ShareRestrictionModal/ShareRestrictionModal.js +260 -0
- package/dist/components/ShareRestrictionModal/helpers.js +275 -0
- package/dist/components/ShareRestrictionModal/helpers.spec.js +110 -0
- package/dist/components/WhoHasAccess.js +1 -5
- package/locales/en.json +28 -0
- package/locales/fr.json +29 -0
- package/package.json +11 -7
- package/src/components/Recipient/LinkRecipientPermissions.jsx +28 -137
- package/src/components/Recipient/actions/editPermissionLink.js +63 -0
- package/src/components/Recipient/actions/readOnlyPermissionLink.js +59 -0
- package/src/components/ShareByLink.jsx +20 -96
- package/src/components/ShareDialogCozyToCozy.jsx +1 -5
- package/src/components/ShareDialogOnlyByLink.jsx +0 -6
- package/src/components/ShareDialogTwoStepsConfirmationContainer.jsx +0 -2
- package/src/components/ShareModal/EditableSharingModal.jsx +1 -7
- package/src/components/ShareModal.jsx +0 -12
- package/src/components/ShareRestrictionModal/BoxDate.jsx +76 -0
- package/src/components/ShareRestrictionModal/BoxEditingRights.jsx +91 -0
- package/src/components/ShareRestrictionModal/BoxPassword.jsx +112 -0
- package/src/components/ShareRestrictionModal/ShareRestrictionContentModal.jsx +102 -0
- package/src/components/ShareRestrictionModal/ShareRestrictionModal.jsx +177 -0
- package/src/components/ShareRestrictionModal/helpers.js +193 -0
- package/src/components/ShareRestrictionModal/helpers.spec.js +78 -0
- package/src/components/WhoHasAccess.jsx +1 -5
- package/dist/components/EditLinkPermissionDialog.js +0 -72
- package/dist/components/EditLinkPermissionDialog.spec.js +0 -48
- package/src/components/EditLinkPermissionDialog.jsx +0 -89
- package/src/components/EditLinkPermissionDialog.spec.jsx +0 -53
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
+
import { addDays } from 'date-fns';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
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';
|
|
10
|
+
import Button from 'cozy-ui/transpiled/react/Buttons';
|
|
11
|
+
import { ConfirmDialog } from 'cozy-ui/transpiled/react/CozyDialogs';
|
|
12
|
+
import Icon from 'cozy-ui/transpiled/react/Icon';
|
|
13
|
+
import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert';
|
|
14
|
+
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
|
|
15
|
+
import { ShareRestrictionContentModal } from './ShareRestrictionContentModal';
|
|
16
|
+
import { copyToClipboard, forwardFile, updatePermissions, makeTTL, READ_ONLY_PERMS, WRITE_PERMS, revokePermissions } from './helpers';
|
|
17
|
+
import { checkIsReadOnlyPermissions } from '../../helpers/permissions';
|
|
18
|
+
import { useSharingContext } from '../../hooks/useSharingContext';
|
|
19
|
+
var PASSWORD_MIN_LENGTH = 4;
|
|
20
|
+
export var ShareRestrictionModal = function ShareRestrictionModal(_ref) {
|
|
21
|
+
var file = _ref.file,
|
|
22
|
+
onClose = _ref.onClose;
|
|
23
|
+
var client = useClient();
|
|
24
|
+
|
|
25
|
+
var _useI18n = useI18n(),
|
|
26
|
+
t = _useI18n.t;
|
|
27
|
+
|
|
28
|
+
var _useAlert = useAlert(),
|
|
29
|
+
showAlert = _useAlert.showAlert;
|
|
30
|
+
|
|
31
|
+
var _useState = useState(''),
|
|
32
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
33
|
+
password = _useState2[0],
|
|
34
|
+
setPassword = _useState2[1];
|
|
35
|
+
|
|
36
|
+
var _useState3 = useState(addDays(new Date(), 30)),
|
|
37
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
38
|
+
selectedDate = _useState4[0],
|
|
39
|
+
setSelectedDate = _useState4[1];
|
|
40
|
+
|
|
41
|
+
var _useState5 = useState(true),
|
|
42
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
43
|
+
isValidDate = _useState6[0],
|
|
44
|
+
setIsValidDate = _useState6[1];
|
|
45
|
+
|
|
46
|
+
var _useState7 = useState(true),
|
|
47
|
+
_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];
|
|
65
|
+
|
|
66
|
+
var _useSharingContext = useSharingContext(),
|
|
67
|
+
documentType = _useSharingContext.documentType,
|
|
68
|
+
getDocumentPermissions = _useSharingContext.getDocumentPermissions,
|
|
69
|
+
updateDocumentPermissions = _useSharingContext.updateDocumentPermissions,
|
|
70
|
+
shareByLink = _useSharingContext.shareByLink,
|
|
71
|
+
getSharingLink = _useSharingContext.getSharingLink,
|
|
72
|
+
revokeSharingLink = _useSharingContext.revokeSharingLink;
|
|
73
|
+
|
|
74
|
+
var hasSharingLink = getSharingLink(file._id) !== null;
|
|
75
|
+
var permissions = getDocumentPermissions(file._id);
|
|
76
|
+
var isReadOnlyPermissions = checkIsReadOnlyPermissions(permissions);
|
|
77
|
+
|
|
78
|
+
var _useState15 = useState(isReadOnlyPermissions || permissions.length === 0 ? 'readOnly' : 'write'),
|
|
79
|
+
_useState16 = _slicedToArray(_useState15, 2),
|
|
80
|
+
editingRights = _useState16[0],
|
|
81
|
+
setEditingRights = _useState16[1];
|
|
82
|
+
|
|
83
|
+
var isDesktopOrMobileWithoutShareAPI = isMobile() && !navigator.share || !isMobile();
|
|
84
|
+
var helperTextPassword = !isValidPassword ? t('ShareRestrictionModal.invalidPasswordMessage', {
|
|
85
|
+
smart_count: PASSWORD_MIN_LENGTH - password.length
|
|
86
|
+
}) : null;
|
|
87
|
+
|
|
88
|
+
var handleDateChange = function handleDateChange(date, isValid) {
|
|
89
|
+
setSelectedDate(date);
|
|
90
|
+
setIsValidDate(isValid);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
var handleClick = /*#__PURE__*/function () {
|
|
94
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
95
|
+
var verbs, url, ttl, _url;
|
|
96
|
+
|
|
97
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
98
|
+
while (1) switch (_context.prev = _context.next) {
|
|
99
|
+
case 0:
|
|
100
|
+
setLoading(true); // If the file is not shared, we create a new sharing link
|
|
101
|
+
|
|
102
|
+
if (hasSharingLink) {
|
|
103
|
+
_context.next = 10;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
verbs = editingRights === 'readOnly' ? READ_ONLY_PERMS : WRITE_PERMS;
|
|
108
|
+
_context.next = 5;
|
|
109
|
+
return shareByLink(file, {
|
|
110
|
+
verbs: verbs
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
case 5:
|
|
114
|
+
url = getSharingLink(file._id);
|
|
115
|
+
_context.next = 8;
|
|
116
|
+
return copyToClipboard(url, {
|
|
117
|
+
t: t,
|
|
118
|
+
showAlert: showAlert
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
case 8:
|
|
122
|
+
onClose();
|
|
123
|
+
return _context.abrupt("return");
|
|
124
|
+
|
|
125
|
+
case 10:
|
|
126
|
+
_context.next = 12;
|
|
127
|
+
return updatePermissions({
|
|
128
|
+
file: file,
|
|
129
|
+
t: t,
|
|
130
|
+
editingRights: editingRights,
|
|
131
|
+
documentType: documentType,
|
|
132
|
+
updateDocumentPermissions: updateDocumentPermissions,
|
|
133
|
+
showAlert: showAlert
|
|
134
|
+
});
|
|
135
|
+
|
|
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
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
case 16:
|
|
151
|
+
_url = _context.sent;
|
|
152
|
+
_context.next = 19;
|
|
153
|
+
return copyToClipboard(_url, {
|
|
154
|
+
t: t,
|
|
155
|
+
showAlert: showAlert
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
case 19:
|
|
159
|
+
_context.next = 23;
|
|
160
|
+
break;
|
|
161
|
+
|
|
162
|
+
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
|
+
onClose();
|
|
175
|
+
|
|
176
|
+
case 24:
|
|
177
|
+
case "end":
|
|
178
|
+
return _context.stop();
|
|
179
|
+
}
|
|
180
|
+
}, _callee);
|
|
181
|
+
}));
|
|
182
|
+
|
|
183
|
+
return function handleClick() {
|
|
184
|
+
return _ref2.apply(this, arguments);
|
|
185
|
+
};
|
|
186
|
+
}();
|
|
187
|
+
|
|
188
|
+
var handleRevokeLink = /*#__PURE__*/function () {
|
|
189
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
190
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
191
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
192
|
+
case 0:
|
|
193
|
+
setLoading(true);
|
|
194
|
+
_context2.next = 3;
|
|
195
|
+
return revokePermissions({
|
|
196
|
+
file: file,
|
|
197
|
+
t: t,
|
|
198
|
+
documentType: documentType,
|
|
199
|
+
revokeSharingLink: revokeSharingLink,
|
|
200
|
+
showAlert: showAlert
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
case 3:
|
|
204
|
+
onClose();
|
|
205
|
+
|
|
206
|
+
case 4:
|
|
207
|
+
case "end":
|
|
208
|
+
return _context2.stop();
|
|
209
|
+
}
|
|
210
|
+
}, _callee2);
|
|
211
|
+
}));
|
|
212
|
+
|
|
213
|
+
return function handleRevokeLink() {
|
|
214
|
+
return _ref3.apply(this, arguments);
|
|
215
|
+
};
|
|
216
|
+
}();
|
|
217
|
+
|
|
218
|
+
return /*#__PURE__*/React.createElement(ConfirmDialog, {
|
|
219
|
+
open: true,
|
|
220
|
+
onClose: onClose,
|
|
221
|
+
content: /*#__PURE__*/React.createElement(ShareRestrictionContentModal, {
|
|
222
|
+
file: file // Date
|
|
223
|
+
,
|
|
224
|
+
dateToggle: dateToggle,
|
|
225
|
+
setDateToggle: setDateToggle,
|
|
226
|
+
setSelectedDate: handleDateChange,
|
|
227
|
+
selectedDate: selectedDate,
|
|
228
|
+
setIsValidDate: setIsValidDate // Password
|
|
229
|
+
,
|
|
230
|
+
helperTextPassword: helperTextPassword,
|
|
231
|
+
passwordToggle: passwordToggle,
|
|
232
|
+
setPasswordToggle: setPasswordToggle,
|
|
233
|
+
password: password,
|
|
234
|
+
setPassword: setPassword,
|
|
235
|
+
setIsValidPassword: setIsValidPassword // Editing rights
|
|
236
|
+
,
|
|
237
|
+
editingRights: editingRights,
|
|
238
|
+
setEditingRights: setEditingRights
|
|
239
|
+
}),
|
|
240
|
+
actions: /*#__PURE__*/React.createElement(React.Fragment, null, hasSharingLink && /*#__PURE__*/React.createElement(Button, {
|
|
241
|
+
label: t('Share.permissionLink.deactivate'),
|
|
242
|
+
variant: "secondary",
|
|
243
|
+
color: "error",
|
|
244
|
+
startIcon: /*#__PURE__*/React.createElement(Icon, {
|
|
245
|
+
icon: "trash"
|
|
246
|
+
}),
|
|
247
|
+
onClick: handleRevokeLink,
|
|
248
|
+
busy: loading
|
|
249
|
+
}), /*#__PURE__*/React.createElement(Button, {
|
|
250
|
+
label: t('ShareRestrictionModal.action.confirm'),
|
|
251
|
+
onClick: handleClick,
|
|
252
|
+
disabled: !isValidDate || !isValidPassword,
|
|
253
|
+
busy: loading
|
|
254
|
+
}))
|
|
255
|
+
});
|
|
256
|
+
};
|
|
257
|
+
ShareRestrictionModal.propTypes = {
|
|
258
|
+
file: PropTypes.object.isRequired,
|
|
259
|
+
onClose: PropTypes.func
|
|
260
|
+
};
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import { getSharingLink } from 'cozy-client/dist/models/sharing';
|
|
4
|
+
import minilog from 'cozy-minilog';
|
|
5
|
+
var log = minilog('ShareRestrictionModal/helpers');
|
|
6
|
+
export var WRITE_PERMS = ['GET', 'POST', 'PUT', 'PATCH'];
|
|
7
|
+
export var READ_ONLY_PERMS = ['GET'];
|
|
8
|
+
/**
|
|
9
|
+
* Copy a string to the clipboard
|
|
10
|
+
*
|
|
11
|
+
* @param {string} value - The string saved to the clipboard
|
|
12
|
+
* @param {object} [options]
|
|
13
|
+
* @param {number} options.t - Translation function
|
|
14
|
+
* @param {Function} options.showAlert - Function to display an alert
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export var copyToClipboard = /*#__PURE__*/function () {
|
|
18
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(value) {
|
|
19
|
+
var _ref2,
|
|
20
|
+
t,
|
|
21
|
+
showAlert,
|
|
22
|
+
_args = arguments;
|
|
23
|
+
|
|
24
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
25
|
+
while (1) switch (_context.prev = _context.next) {
|
|
26
|
+
case 0:
|
|
27
|
+
_ref2 = _args.length > 1 && _args[1] !== undefined ? _args[1] : {}, t = _ref2.t, showAlert = _ref2.showAlert;
|
|
28
|
+
|
|
29
|
+
if (value) {
|
|
30
|
+
_context.next = 3;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return _context.abrupt("return", false);
|
|
35
|
+
|
|
36
|
+
case 3:
|
|
37
|
+
_context.prev = 3;
|
|
38
|
+
_context.next = 6;
|
|
39
|
+
return navigator.clipboard.writeText(value);
|
|
40
|
+
|
|
41
|
+
case 6:
|
|
42
|
+
showAlert({
|
|
43
|
+
message: t('copyReminderContent.success'),
|
|
44
|
+
severity: 'success',
|
|
45
|
+
variant: 'filled'
|
|
46
|
+
});
|
|
47
|
+
_context.next = 13;
|
|
48
|
+
break;
|
|
49
|
+
|
|
50
|
+
case 9:
|
|
51
|
+
_context.prev = 9;
|
|
52
|
+
_context.t0 = _context["catch"](3);
|
|
53
|
+
showAlert({
|
|
54
|
+
message: t('copyReminderContent.error'),
|
|
55
|
+
severity: 'error',
|
|
56
|
+
variant: 'filled'
|
|
57
|
+
});
|
|
58
|
+
log.error("Error in 'copyToClipboard' function when trying to copy to clipboard", _context.t0);
|
|
59
|
+
|
|
60
|
+
case 13:
|
|
61
|
+
case "end":
|
|
62
|
+
return _context.stop();
|
|
63
|
+
}
|
|
64
|
+
}, _callee, null, [[3, 9]]);
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
return function copyToClipboard(_x) {
|
|
68
|
+
return _ref.apply(this, arguments);
|
|
69
|
+
};
|
|
70
|
+
}();
|
|
71
|
+
/**
|
|
72
|
+
* Make a TTL string from a date
|
|
73
|
+
* @param {Date|string} selectedDate
|
|
74
|
+
* @returns {string} - TTL string in seconds (e.g. '1234s')
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
export var makeTTL = function makeTTL(selectedDate) {
|
|
78
|
+
if (!selectedDate) return;
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
var selectedDateConverted = selectedDate;
|
|
82
|
+
|
|
83
|
+
if (typeof selectedDate === 'string') {
|
|
84
|
+
var _selectedDateConverte;
|
|
85
|
+
|
|
86
|
+
selectedDateConverted = new Date(selectedDate);
|
|
87
|
+
|
|
88
|
+
if (((_selectedDateConverte = selectedDateConverted) === null || _selectedDateConverte === void 0 ? void 0 : _selectedDateConverte.toString()) === 'Invalid Date') {
|
|
89
|
+
throw new Error("Invalid date: ".concat(selectedDate));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (selectedDateConverted instanceof Date) {
|
|
94
|
+
var now = new Date();
|
|
95
|
+
var ttl = selectedDateConverted > now ? "".concat(Math.round((selectedDateConverted - now) / 1000), "s") : undefined;
|
|
96
|
+
return ttl;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
throw new Error("Invalid date: ".concat(selectedDate));
|
|
100
|
+
} catch (error) {
|
|
101
|
+
log.error(error);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* forwardFile - Triggers the download of one or multiple files by the browser
|
|
107
|
+
* @param {object} options
|
|
108
|
+
* @param {import('cozy-client/types/CozyClient').default} options.client
|
|
109
|
+
* @param {import('cozy-client/types/types').IOCozyFile} options.file File to download
|
|
110
|
+
* @param {Function} options.t i18n function
|
|
111
|
+
* @param {string} options.ttl Time to live of the sharing link
|
|
112
|
+
* @param {string} options.password Password of the sharing link
|
|
113
|
+
* @param {Function} options.showAlert - Function to display an alert
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
export var forwardFile = /*#__PURE__*/function () {
|
|
117
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3) {
|
|
118
|
+
var client, file, t, ttl, password, showAlert, url, isZipFile, shareData;
|
|
119
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
120
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
121
|
+
case 0:
|
|
122
|
+
client = _ref3.client, file = _ref3.file, t = _ref3.t, ttl = _ref3.ttl, password = _ref3.password, showAlert = _ref3.showAlert;
|
|
123
|
+
_context2.prev = 1;
|
|
124
|
+
_context2.next = 4;
|
|
125
|
+
return getSharingLink(client, [file._id], {
|
|
126
|
+
ttl: ttl,
|
|
127
|
+
password: password
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
case 4:
|
|
131
|
+
url = _context2.sent;
|
|
132
|
+
isZipFile = file.class === 'zip';
|
|
133
|
+
shareData = {
|
|
134
|
+
title: t('shareFile.title', {
|
|
135
|
+
name: file.name,
|
|
136
|
+
smart_count: isZipFile ? 2 : 1
|
|
137
|
+
}),
|
|
138
|
+
text: t('shareFile.text', {
|
|
139
|
+
name: file.name,
|
|
140
|
+
smart_count: isZipFile ? 2 : 1
|
|
141
|
+
}),
|
|
142
|
+
url: url
|
|
143
|
+
};
|
|
144
|
+
navigator.share(shareData);
|
|
145
|
+
_context2.next = 13;
|
|
146
|
+
break;
|
|
147
|
+
|
|
148
|
+
case 10:
|
|
149
|
+
_context2.prev = 10;
|
|
150
|
+
_context2.t0 = _context2["catch"](1);
|
|
151
|
+
showAlert({
|
|
152
|
+
message: t('shareFile.error'),
|
|
153
|
+
severity: 'error',
|
|
154
|
+
variant: 'filled'
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
case 13:
|
|
158
|
+
case "end":
|
|
159
|
+
return _context2.stop();
|
|
160
|
+
}
|
|
161
|
+
}, _callee2, null, [[1, 10]]);
|
|
162
|
+
}));
|
|
163
|
+
|
|
164
|
+
return function forwardFile(_x2) {
|
|
165
|
+
return _ref4.apply(this, arguments);
|
|
166
|
+
};
|
|
167
|
+
}();
|
|
168
|
+
/**
|
|
169
|
+
* updatePermissions - Updates the permissions of a file
|
|
170
|
+
* @param {object} options
|
|
171
|
+
* @param {import('cozy-client/types/types').IOCozyFile} options.file File to update permissions
|
|
172
|
+
* @param {Function} options.t i18n function
|
|
173
|
+
* @param {string} options.documentType - Type of the document
|
|
174
|
+
* @param {'readOnly'|'write'} options.editingRights - Editing rights
|
|
175
|
+
* @param {Function} options.updateDocumentPermissions - Function to update permissions
|
|
176
|
+
* @param {Function} options.showAlert - Function to display an alert
|
|
177
|
+
*/
|
|
178
|
+
|
|
179
|
+
export var updatePermissions = /*#__PURE__*/function () {
|
|
180
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref5) {
|
|
181
|
+
var file, t, editingRights, documentType, updateDocumentPermissions, showAlert;
|
|
182
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
183
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
184
|
+
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));
|
|
193
|
+
|
|
194
|
+
case 8:
|
|
195
|
+
_context3.prev = 8;
|
|
196
|
+
_context3.t1 = _context3["catch"](4);
|
|
197
|
+
showAlert({
|
|
198
|
+
message: t("".concat(documentType, ".share.shareByLink.permserror")),
|
|
199
|
+
severity: 'error',
|
|
200
|
+
variant: 'filled'
|
|
201
|
+
});
|
|
202
|
+
log.error("Error in 'readOnlyPermissionLink' function when trying to change permission", _context3.t1);
|
|
203
|
+
|
|
204
|
+
case 12:
|
|
205
|
+
return _context3.abrupt("break", 22);
|
|
206
|
+
|
|
207
|
+
case 13:
|
|
208
|
+
_context3.prev = 13;
|
|
209
|
+
return _context3.abrupt("return", updateDocumentPermissions(file, WRITE_PERMS));
|
|
210
|
+
|
|
211
|
+
case 17:
|
|
212
|
+
_context3.prev = 17;
|
|
213
|
+
_context3.t2 = _context3["catch"](13);
|
|
214
|
+
showAlert({
|
|
215
|
+
message: t("".concat(documentType, ".share.shareByLink.permserror")),
|
|
216
|
+
severity: 'error',
|
|
217
|
+
variant: 'filled'
|
|
218
|
+
});
|
|
219
|
+
log.error("Error in 'editPermissionLink' function when trying to change permission", _context3.t2);
|
|
220
|
+
|
|
221
|
+
case 21:
|
|
222
|
+
return _context3.abrupt("break", 22);
|
|
223
|
+
|
|
224
|
+
case 22:
|
|
225
|
+
case "end":
|
|
226
|
+
return _context3.stop();
|
|
227
|
+
}
|
|
228
|
+
}, _callee3, null, [[4, 8], [13, 17]]);
|
|
229
|
+
}));
|
|
230
|
+
|
|
231
|
+
return function updatePermissions(_x3) {
|
|
232
|
+
return _ref6.apply(this, arguments);
|
|
233
|
+
};
|
|
234
|
+
}();
|
|
235
|
+
/**
|
|
236
|
+
* revokePermissions - Revokes the permissions of a file
|
|
237
|
+
* @param {object} options
|
|
238
|
+
* @param {import('cozy-client/types/types').IOCozyFile} options.file File to revoke permissions
|
|
239
|
+
* @param {Function} options.t i18n function
|
|
240
|
+
* @param {string} options.documentType - Type of the document
|
|
241
|
+
* @param {Function} options.revokeSharingLink - Function to revoke permissions
|
|
242
|
+
* @param {Function} options.showAlert - Function to display an alert
|
|
243
|
+
*/
|
|
244
|
+
|
|
245
|
+
export var revokePermissions = /*#__PURE__*/function () {
|
|
246
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref7) {
|
|
247
|
+
var file, t, documentType, revokeSharingLink, showAlert;
|
|
248
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
249
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
250
|
+
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));
|
|
254
|
+
|
|
255
|
+
case 5:
|
|
256
|
+
_context4.prev = 5;
|
|
257
|
+
_context4.t0 = _context4["catch"](1);
|
|
258
|
+
showAlert({
|
|
259
|
+
message: t("".concat(documentType, ".share.error.revoke")),
|
|
260
|
+
severity: 'error',
|
|
261
|
+
variant: 'filled'
|
|
262
|
+
});
|
|
263
|
+
log.error("Error in 'revokePermissions' function when trying to revoke sharing link", _context4.t0);
|
|
264
|
+
|
|
265
|
+
case 9:
|
|
266
|
+
case "end":
|
|
267
|
+
return _context4.stop();
|
|
268
|
+
}
|
|
269
|
+
}, _callee4, null, [[1, 5]]);
|
|
270
|
+
}));
|
|
271
|
+
|
|
272
|
+
return function revokePermissions(_x4) {
|
|
273
|
+
return _ref8.apply(this, arguments);
|
|
274
|
+
};
|
|
275
|
+
}();
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import { makeTTL, revokePermissions, updatePermissions } from './helpers';
|
|
4
|
+
describe('ShareRestrictionModal/helpers', function () {
|
|
5
|
+
describe('makeTTL', function () {
|
|
6
|
+
it('sould return undefined', function () {
|
|
7
|
+
expect(makeTTL()).toBeUndefined();
|
|
8
|
+
expect(makeTTL(123)).toBeUndefined();
|
|
9
|
+
expect(makeTTL('abc')).toBeUndefined();
|
|
10
|
+
expect(makeTTL(new Date('2023-01-01T00:00:00.000Z'))).toBeUndefined();
|
|
11
|
+
expect(makeTTL(new Date('abc'))).toBeUndefined();
|
|
12
|
+
expect(makeTTL('2023-01-01T00:00:00.000Z')).toBeUndefined();
|
|
13
|
+
});
|
|
14
|
+
it('sould return TTL in seconds', function () {
|
|
15
|
+
expect(makeTTL(new Date('2100-01-01T00:00:00.000Z'))).toBeDefined();
|
|
16
|
+
expect(makeTTL('2100-01-01T00:00:00.000Z')).toBeDefined();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
describe('updatePermissions', function () {
|
|
20
|
+
var documentType = 'Files';
|
|
21
|
+
it('should call updateDocumentPermissions with "readOnly" permission', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
22
|
+
var updateDocumentPermissions, file, editingRights;
|
|
23
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
24
|
+
while (1) switch (_context.prev = _context.next) {
|
|
25
|
+
case 0:
|
|
26
|
+
updateDocumentPermissions = jest.fn();
|
|
27
|
+
file = {
|
|
28
|
+
_id: '123'
|
|
29
|
+
};
|
|
30
|
+
editingRights = 'readOnly';
|
|
31
|
+
_context.next = 5;
|
|
32
|
+
return updatePermissions({
|
|
33
|
+
file: file,
|
|
34
|
+
t: jest.fn(),
|
|
35
|
+
editingRights: editingRights,
|
|
36
|
+
documentType: documentType,
|
|
37
|
+
updateDocumentPermissions: updateDocumentPermissions,
|
|
38
|
+
showAlert: jest.fn()
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
case 5:
|
|
42
|
+
expect(updateDocumentPermissions).toHaveBeenCalledWith(file, ['GET']);
|
|
43
|
+
|
|
44
|
+
case 6:
|
|
45
|
+
case "end":
|
|
46
|
+
return _context.stop();
|
|
47
|
+
}
|
|
48
|
+
}, _callee);
|
|
49
|
+
})));
|
|
50
|
+
it('should call updateDocumentPermissions with "write" permissions', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
51
|
+
var updateDocumentPermissions, file, editingRights;
|
|
52
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
53
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
54
|
+
case 0:
|
|
55
|
+
updateDocumentPermissions = jest.fn();
|
|
56
|
+
file = {
|
|
57
|
+
_id: '123'
|
|
58
|
+
};
|
|
59
|
+
editingRights = 'write';
|
|
60
|
+
_context2.next = 5;
|
|
61
|
+
return updatePermissions({
|
|
62
|
+
file: file,
|
|
63
|
+
t: jest.fn(),
|
|
64
|
+
editingRights: editingRights,
|
|
65
|
+
documentType: documentType,
|
|
66
|
+
updateDocumentPermissions: updateDocumentPermissions,
|
|
67
|
+
showAlert: jest.fn()
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
case 5:
|
|
71
|
+
expect(updateDocumentPermissions).toHaveBeenCalledWith(file, ['GET', 'POST', 'PUT', 'PATCH']);
|
|
72
|
+
|
|
73
|
+
case 6:
|
|
74
|
+
case "end":
|
|
75
|
+
return _context2.stop();
|
|
76
|
+
}
|
|
77
|
+
}, _callee2);
|
|
78
|
+
})));
|
|
79
|
+
});
|
|
80
|
+
describe('revokePermissions', function () {
|
|
81
|
+
var documentType = 'Files';
|
|
82
|
+
it('should call revokeSharingLink', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
83
|
+
var revokeSharingLink, file;
|
|
84
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
85
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
86
|
+
case 0:
|
|
87
|
+
revokeSharingLink = jest.fn();
|
|
88
|
+
file = {
|
|
89
|
+
_id: '123'
|
|
90
|
+
};
|
|
91
|
+
_context3.next = 4;
|
|
92
|
+
return revokePermissions({
|
|
93
|
+
file: file,
|
|
94
|
+
t: jest.fn(),
|
|
95
|
+
documentType: documentType,
|
|
96
|
+
revokeSharingLink: revokeSharingLink,
|
|
97
|
+
showAlert: jest.fn()
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
case 4:
|
|
101
|
+
expect(revokeSharingLink).toHaveBeenCalledWith(file);
|
|
102
|
+
|
|
103
|
+
case 5:
|
|
104
|
+
case "end":
|
|
105
|
+
return _context3.stop();
|
|
106
|
+
}
|
|
107
|
+
}, _callee3);
|
|
108
|
+
})));
|
|
109
|
+
});
|
|
110
|
+
});
|
|
@@ -40,9 +40,7 @@ var WhoHasAccess = function WhoHasAccess(_ref2) {
|
|
|
40
40
|
onRevokeSelf = _ref2.onRevokeSelf,
|
|
41
41
|
verifyRecipient = _ref2.verifyRecipient,
|
|
42
42
|
link = _ref2.link,
|
|
43
|
-
permissions = _ref2.permissions
|
|
44
|
-
onUpdateShareLinkPermissions = _ref2.onUpdateShareLinkPermissions,
|
|
45
|
-
onRevokeLink = _ref2.onRevokeLink;
|
|
43
|
+
permissions = _ref2.permissions;
|
|
46
44
|
var previousLink = usePrevious(link);
|
|
47
45
|
var linkHasBeenJustCreated = link && previousLink === null;
|
|
48
46
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -56,8 +54,6 @@ var WhoHasAccess = function WhoHasAccess(_ref2) {
|
|
|
56
54
|
onRevokeSelf: onRevokeSelf,
|
|
57
55
|
link: link,
|
|
58
56
|
permissions: permissions,
|
|
59
|
-
onChangePermissions: onUpdateShareLinkPermissions,
|
|
60
|
-
onDisable: onRevokeLink,
|
|
61
57
|
fadeIn: linkHasBeenJustCreated
|
|
62
58
|
}), /*#__PURE__*/React.createElement(OwnerRecipient, {
|
|
63
59
|
recipients: recipients
|
package/locales/en.json
CHANGED
|
@@ -416,5 +416,33 @@
|
|
|
416
416
|
},
|
|
417
417
|
"addEmail": "Enter an email address to invite the contact"
|
|
418
418
|
}
|
|
419
|
+
},
|
|
420
|
+
"ShareRestrictionModal": {
|
|
421
|
+
"action": {
|
|
422
|
+
"confirm": "Confirm"
|
|
423
|
+
},
|
|
424
|
+
"invalidPasswordMessage": "%{smart_count} character is missing |||| %{smart_count} characters are missings"
|
|
425
|
+
},
|
|
426
|
+
"BoxDate": {
|
|
427
|
+
"label": "Deadline",
|
|
428
|
+
"text": "Remove access after a deadline"
|
|
429
|
+
},
|
|
430
|
+
"BoxPassword": {
|
|
431
|
+
"label": "Password",
|
|
432
|
+
"text": "Limit access with a password"
|
|
433
|
+
},
|
|
434
|
+
"BoxEditingRights": {
|
|
435
|
+
"editSubText": "People with access to the link can modify the content",
|
|
436
|
+
"readOnlySubText": "People who have access to the link can only view the content",
|
|
437
|
+
"text": "Editing rights"
|
|
438
|
+
},
|
|
439
|
+
"copyReminderContent": {
|
|
440
|
+
"success": "Copied to clipboard",
|
|
441
|
+
"error": "Cannot copy to clipboard"
|
|
442
|
+
},
|
|
443
|
+
"shareFile": {
|
|
444
|
+
"error": "Problem with link recovery: %{error}",
|
|
445
|
+
"text": "Link to my document %{name}: |||| Link to my documents %{name}: ",
|
|
446
|
+
"title": "Link to my document %{name} |||| Link to my documents %{name}"
|
|
419
447
|
}
|
|
420
448
|
}
|