cozy-sharing 17.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 +49 -0
- package/dist/SharingProvider.spec.js +84 -80
- 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/EditableSharingModal.spec.js +49 -52
- package/dist/components/ShareModal/SharingDetailsModal.js +1 -1
- 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/SharedStatus.spec.js +20 -21
- package/dist/components/WhoHasAccess.js +1 -5
- package/jest.config.js +8 -3
- package/jestHelpers/setup.js +1 -8
- package/locales/en.json +28 -0
- package/locales/fr.json +29 -0
- package/package.json +13 -11
- package/src/SharingProvider.spec.jsx +88 -88
- 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/EditableSharingModal.spec.jsx +50 -44
- package/src/components/ShareModal/SharingDetailsModal.jsx +1 -1
- 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/SharedStatus.spec.js +32 -31
- package/src/components/WhoHasAccess.jsx +1 -5
- package/src/components/__snapshots__/SharedStatus.spec.js.snap +59 -129
- package/dist/RefreshableSharings.spec.js +0 -40
- package/dist/components/EditLinkPermissionDialog.js +0 -72
- package/dist/components/EditLinkPermissionDialog.spec.js +0 -48
- package/src/RefreshableSharings.spec.jsx +0 -43
- package/src/components/EditLinkPermissionDialog.jsx +0 -89
- package/src/components/EditLinkPermissionDialog.spec.jsx +0 -53
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import React, { useReducer, useRef } from 'react';
|
|
4
|
+
import { isDirectory as isDir } from 'cozy-client/dist/models/file';
|
|
5
|
+
import ActionsMenu from 'cozy-ui/transpiled/react/ActionsMenu';
|
|
6
|
+
import { makeActions } from 'cozy-ui/transpiled/react/ActionsMenu/Actions';
|
|
7
|
+
import Box from 'cozy-ui/transpiled/react/Box';
|
|
8
|
+
import Icon from 'cozy-ui/transpiled/react/Icon';
|
|
9
|
+
import List from 'cozy-ui/transpiled/react/List';
|
|
10
|
+
import ListItem from 'cozy-ui/transpiled/react/ListItem';
|
|
11
|
+
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
|
|
12
|
+
import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
|
|
13
|
+
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
|
|
14
|
+
import { useSharingContext } from '../../hooks/useSharingContext';
|
|
15
|
+
import { editPermissionLink } from '../Recipient/actions/editPermissionLink';
|
|
16
|
+
import { readOnlyPermissionLink } from '../Recipient/actions/readOnlyPermissionLink';
|
|
17
|
+
export var BoxEditingRights = function BoxEditingRights(_ref) {
|
|
18
|
+
var file = _ref.file,
|
|
19
|
+
editingRights = _ref.editingRights,
|
|
20
|
+
setEditingRights = _ref.setEditingRights;
|
|
21
|
+
|
|
22
|
+
var _useReducer = useReducer(function (state) {
|
|
23
|
+
return !state;
|
|
24
|
+
}, false),
|
|
25
|
+
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
26
|
+
isMenuDisplayed = _useReducer2[0],
|
|
27
|
+
toggleMenuDisplayed = _useReducer2[1];
|
|
28
|
+
|
|
29
|
+
var buttonRef = useRef();
|
|
30
|
+
|
|
31
|
+
var _useI18n = useI18n(),
|
|
32
|
+
t = _useI18n.t;
|
|
33
|
+
|
|
34
|
+
var _useSharingContext = useSharingContext(),
|
|
35
|
+
documentType = _useSharingContext.documentType;
|
|
36
|
+
|
|
37
|
+
var isDirectory = isDir(file);
|
|
38
|
+
var actions = makeActions([readOnlyPermissionLink, editPermissionLink], {
|
|
39
|
+
t: t,
|
|
40
|
+
editingRights: editingRights,
|
|
41
|
+
setEditingRights: setEditingRights,
|
|
42
|
+
documentType: documentType,
|
|
43
|
+
isDirectory: isDirectory
|
|
44
|
+
});
|
|
45
|
+
var textSecondary = editingRights === 'readOnly' ? t('Share.permissionLink.readDescription') : t('Share.permissionLink.writeDescription');
|
|
46
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Box, {
|
|
47
|
+
borderRadius: "0.5rem",
|
|
48
|
+
border: "1px solid var(--borderMainColor)",
|
|
49
|
+
ref: buttonRef
|
|
50
|
+
}, /*#__PURE__*/React.createElement(List, {
|
|
51
|
+
className: "u-p-0"
|
|
52
|
+
}, /*#__PURE__*/React.createElement(ListItem, {
|
|
53
|
+
button: true,
|
|
54
|
+
size: "large",
|
|
55
|
+
ellipsis: false,
|
|
56
|
+
onClick: toggleMenuDisplayed
|
|
57
|
+
}, /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Icon, {
|
|
58
|
+
icon: "people"
|
|
59
|
+
})), /*#__PURE__*/React.createElement(ListItemText, {
|
|
60
|
+
primary: t('BoxEditingRights.text'),
|
|
61
|
+
secondary: textSecondary
|
|
62
|
+
}), /*#__PURE__*/React.createElement(ListItemIcon, {
|
|
63
|
+
className: "u-mr-half"
|
|
64
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
65
|
+
icon: "bottom"
|
|
66
|
+
}))))), /*#__PURE__*/React.createElement(ActionsMenu, {
|
|
67
|
+
ref: buttonRef,
|
|
68
|
+
open: isMenuDisplayed,
|
|
69
|
+
docs: [file],
|
|
70
|
+
actions: actions,
|
|
71
|
+
anchorOrigin: {
|
|
72
|
+
vertical: 'bottom',
|
|
73
|
+
horizontal: 'right'
|
|
74
|
+
},
|
|
75
|
+
autoClose: true,
|
|
76
|
+
onClose: toggleMenuDisplayed
|
|
77
|
+
}));
|
|
78
|
+
};
|
|
79
|
+
BoxEditingRights.propTypes = {
|
|
80
|
+
file: PropTypes.object.isRequired,
|
|
81
|
+
editingRights: PropTypes.oneOf(['readOnly', 'write']).isRequired,
|
|
82
|
+
setEditingRights: PropTypes.func.isRequired
|
|
83
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
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 PropTypes from 'prop-types';
|
|
5
|
+
import React, { useState } from 'react';
|
|
6
|
+
import Box from 'cozy-ui/transpiled/react/Box';
|
|
7
|
+
import Icon from 'cozy-ui/transpiled/react/Icon';
|
|
8
|
+
import IconButton from 'cozy-ui/transpiled/react/IconButton';
|
|
9
|
+
import List from 'cozy-ui/transpiled/react/List';
|
|
10
|
+
import ListItem from 'cozy-ui/transpiled/react/ListItem';
|
|
11
|
+
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
|
|
12
|
+
import ListItemSecondaryAction from 'cozy-ui/transpiled/react/ListItemSecondaryAction';
|
|
13
|
+
import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
|
|
14
|
+
import Switch from 'cozy-ui/transpiled/react/Switch';
|
|
15
|
+
import TextField from 'cozy-ui/transpiled/react/TextField';
|
|
16
|
+
import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert';
|
|
17
|
+
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
|
|
18
|
+
import { copyToClipboard } from './helpers';
|
|
19
|
+
export var BoxPassword = function BoxPassword(_ref) {
|
|
20
|
+
var onChange = _ref.onChange,
|
|
21
|
+
password = _ref.password,
|
|
22
|
+
onToggle = _ref.onToggle,
|
|
23
|
+
toggle = _ref.toggle,
|
|
24
|
+
helperText = _ref.helperText,
|
|
25
|
+
inputProps = _ref.inputProps;
|
|
26
|
+
|
|
27
|
+
var _useI18n = useI18n(),
|
|
28
|
+
t = _useI18n.t;
|
|
29
|
+
|
|
30
|
+
var _useAlert = useAlert(),
|
|
31
|
+
showAlert = _useAlert.showAlert;
|
|
32
|
+
|
|
33
|
+
var _useState = useState(false),
|
|
34
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
35
|
+
displayHelper = _useState2[0],
|
|
36
|
+
setDisplayHelper = _useState2[1];
|
|
37
|
+
|
|
38
|
+
var inputRef = React.useRef();
|
|
39
|
+
|
|
40
|
+
var handlePasswordToggle = function handlePasswordToggle(val) {
|
|
41
|
+
var _val$target$checked, _val$target;
|
|
42
|
+
|
|
43
|
+
var value = (_val$target$checked = val === null || val === void 0 || (_val$target = val.target) === null || _val$target === void 0 ? void 0 : _val$target.checked) !== null && _val$target$checked !== void 0 ? _val$target$checked : val;
|
|
44
|
+
onToggle(value);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
var handleChange = function handleChange(val) {
|
|
48
|
+
var _val$target$value, _val$target2;
|
|
49
|
+
|
|
50
|
+
var value = (_val$target$value = val === null || val === void 0 || (_val$target2 = val.target) === null || _val$target2 === void 0 ? void 0 : _val$target2.value) !== null && _val$target$value !== void 0 ? _val$target$value : val;
|
|
51
|
+
onChange(value);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
var handleOnFocus = function handleOnFocus() {
|
|
55
|
+
setDisplayHelper(false);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
var handleOnBlur = function handleOnBlur() {
|
|
59
|
+
handleChange(inputRef.current.value.trim());
|
|
60
|
+
setDisplayHelper(true);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
var handleCopy = /*#__PURE__*/function () {
|
|
64
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
65
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
66
|
+
while (1) switch (_context.prev = _context.next) {
|
|
67
|
+
case 0:
|
|
68
|
+
_context.next = 2;
|
|
69
|
+
return copyToClipboard(password, {
|
|
70
|
+
t: t,
|
|
71
|
+
showAlert: showAlert
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
case 2:
|
|
75
|
+
case "end":
|
|
76
|
+
return _context.stop();
|
|
77
|
+
}
|
|
78
|
+
}, _callee);
|
|
79
|
+
}));
|
|
80
|
+
|
|
81
|
+
return function handleCopy() {
|
|
82
|
+
return _ref2.apply(this, arguments);
|
|
83
|
+
};
|
|
84
|
+
}();
|
|
85
|
+
|
|
86
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
87
|
+
borderRadius: "0.5rem",
|
|
88
|
+
border: "1px solid var(--borderMainColor)"
|
|
89
|
+
}, /*#__PURE__*/React.createElement(List, {
|
|
90
|
+
className: "u-p-0"
|
|
91
|
+
}, /*#__PURE__*/React.createElement(ListItem, {
|
|
92
|
+
button: true,
|
|
93
|
+
size: "large",
|
|
94
|
+
ellipsis: false,
|
|
95
|
+
onClick: function onClick() {
|
|
96
|
+
return handlePasswordToggle(!toggle);
|
|
97
|
+
}
|
|
98
|
+
}, /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Icon, {
|
|
99
|
+
icon: "password"
|
|
100
|
+
})), /*#__PURE__*/React.createElement(ListItemText, {
|
|
101
|
+
primary: t('BoxPassword.text')
|
|
102
|
+
}), /*#__PURE__*/React.createElement(ListItemSecondaryAction, null, /*#__PURE__*/React.createElement(Switch, {
|
|
103
|
+
edge: "end",
|
|
104
|
+
color: "primary",
|
|
105
|
+
checked: toggle,
|
|
106
|
+
onChange: handlePasswordToggle
|
|
107
|
+
})))), toggle && /*#__PURE__*/React.createElement("div", {
|
|
108
|
+
className: "u-pt-half u-ph-1 u-pb-1"
|
|
109
|
+
}, /*#__PURE__*/React.createElement(TextField, {
|
|
110
|
+
inputRef: inputRef,
|
|
111
|
+
label: t('BoxPassword.label'),
|
|
112
|
+
value: password,
|
|
113
|
+
error: displayHelper && !!helperText,
|
|
114
|
+
helperText: displayHelper && helperText,
|
|
115
|
+
onChange: handleChange,
|
|
116
|
+
onFocus: handleOnFocus,
|
|
117
|
+
onBlur: handleOnBlur,
|
|
118
|
+
fullWidth: true,
|
|
119
|
+
type: "text",
|
|
120
|
+
variant: "outlined",
|
|
121
|
+
InputProps: {
|
|
122
|
+
endAdornment: /*#__PURE__*/React.createElement(IconButton, {
|
|
123
|
+
onClick: handleCopy
|
|
124
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
125
|
+
icon: "copy"
|
|
126
|
+
}))
|
|
127
|
+
},
|
|
128
|
+
inputProps: inputProps
|
|
129
|
+
})));
|
|
130
|
+
};
|
|
131
|
+
BoxPassword.propTypes = {
|
|
132
|
+
onChange: PropTypes.func.isRequired,
|
|
133
|
+
password: PropTypes.string,
|
|
134
|
+
onToggle: PropTypes.func.isRequired,
|
|
135
|
+
toggle: PropTypes.bool.isRequired,
|
|
136
|
+
helperText: PropTypes.string,
|
|
137
|
+
inputProps: PropTypes.object
|
|
138
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { addDays } from 'date-fns';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import Box from 'cozy-ui/transpiled/react/Box';
|
|
5
|
+
import Typography from 'cozy-ui/transpiled/react/Typography';
|
|
6
|
+
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
|
|
7
|
+
import { BoxDate } from './BoxDate';
|
|
8
|
+
import { BoxEditingRights } from './BoxEditingRights';
|
|
9
|
+
import { BoxPassword } from './BoxPassword';
|
|
10
|
+
var PASSWORD_MIN_LENGTH = 4;
|
|
11
|
+
export var ShareRestrictionContentModal = function ShareRestrictionContentModal(_ref) {
|
|
12
|
+
var file = _ref.file,
|
|
13
|
+
selectedDate = _ref.selectedDate,
|
|
14
|
+
setSelectedDate = _ref.setSelectedDate,
|
|
15
|
+
dateToggle = _ref.dateToggle,
|
|
16
|
+
setDateToggle = _ref.setDateToggle,
|
|
17
|
+
setIsValidDate = _ref.setIsValidDate,
|
|
18
|
+
helperTextPassword = _ref.helperTextPassword,
|
|
19
|
+
password = _ref.password,
|
|
20
|
+
setPassword = _ref.setPassword,
|
|
21
|
+
passwordToggle = _ref.passwordToggle,
|
|
22
|
+
setPasswordToggle = _ref.setPasswordToggle,
|
|
23
|
+
setIsValidPassword = _ref.setIsValidPassword,
|
|
24
|
+
editingRights = _ref.editingRights,
|
|
25
|
+
setEditingRights = _ref.setEditingRights;
|
|
26
|
+
|
|
27
|
+
var _useI18n = useI18n(),
|
|
28
|
+
t = _useI18n.t;
|
|
29
|
+
|
|
30
|
+
var handlePasswordToggle = function handlePasswordToggle(val) {
|
|
31
|
+
setPasswordToggle(val);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
var handlePassword = function handlePassword(value) {
|
|
35
|
+
setPassword(value);
|
|
36
|
+
setIsValidPassword(value.trim().length === 0 || value.trim().length >= PASSWORD_MIN_LENGTH);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
var handleDateToggle = function handleDateToggle(val) {
|
|
40
|
+
if (!val) {
|
|
41
|
+
setIsValidDate(true);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
var defaultValue = val ? addDays(new Date(), 30) : null;
|
|
45
|
+
setSelectedDate(defaultValue, true);
|
|
46
|
+
setDateToggle(val);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
50
|
+
display: "flex",
|
|
51
|
+
flexDirection: "column",
|
|
52
|
+
gridGap: "1rem"
|
|
53
|
+
}, /*#__PURE__*/React.createElement(Typography, {
|
|
54
|
+
variant: "h4",
|
|
55
|
+
className: "u-mb-half u-ml-half"
|
|
56
|
+
}, t('ShareRestrictionModal.title')), /*#__PURE__*/React.createElement(BoxEditingRights, {
|
|
57
|
+
file: file,
|
|
58
|
+
editingRights: editingRights,
|
|
59
|
+
setEditingRights: setEditingRights
|
|
60
|
+
}), /*#__PURE__*/React.createElement(BoxDate, {
|
|
61
|
+
onChange: setSelectedDate,
|
|
62
|
+
date: selectedDate,
|
|
63
|
+
onToggle: handleDateToggle,
|
|
64
|
+
toggle: dateToggle
|
|
65
|
+
}), /*#__PURE__*/React.createElement(BoxPassword, {
|
|
66
|
+
onChange: handlePassword,
|
|
67
|
+
password: password,
|
|
68
|
+
onToggle: handlePasswordToggle,
|
|
69
|
+
toggle: passwordToggle,
|
|
70
|
+
helperText: helperTextPassword,
|
|
71
|
+
inputProps: {
|
|
72
|
+
minLength: PASSWORD_MIN_LENGTH
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
75
|
+
};
|
|
76
|
+
ShareRestrictionContentModal.propTypes = {
|
|
77
|
+
file: PropTypes.object.isRequired,
|
|
78
|
+
// Date
|
|
79
|
+
selectedDate: PropTypes.object,
|
|
80
|
+
setSelectedDate: PropTypes.func.isRequired,
|
|
81
|
+
dateToggle: PropTypes.bool,
|
|
82
|
+
setDateToggle: PropTypes.func.isRequired,
|
|
83
|
+
setIsValidDate: PropTypes.func.isRequired,
|
|
84
|
+
// Password
|
|
85
|
+
helperTextPassword: PropTypes.string,
|
|
86
|
+
password: PropTypes.string,
|
|
87
|
+
setPassword: PropTypes.func.isRequired,
|
|
88
|
+
passwordToggle: PropTypes.bool.isRequired,
|
|
89
|
+
setPasswordToggle: PropTypes.func.isRequired,
|
|
90
|
+
setIsValidPassword: PropTypes.func.isRequired,
|
|
91
|
+
// Editing rights
|
|
92
|
+
editingRights: PropTypes.oneOf(['readOnly', 'write']),
|
|
93
|
+
setEditingRights: PropTypes.func.isRequired
|
|
94
|
+
};
|
|
@@ -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
|
+
};
|