cozy-sharing 18.0.0 → 20.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 +57 -0
- package/dist/SharingProvider.js +16 -9
- package/dist/components/Recipient/LinkRecipient.js +20 -4
- 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 +155 -0
- package/dist/components/ShareRestrictionModal/ShareRestrictionContentModal.js +118 -0
- package/dist/components/ShareRestrictionModal/ShareRestrictionModal.js +256 -0
- package/dist/components/ShareRestrictionModal/helpers.js +310 -0
- package/dist/components/ShareRestrictionModal/helpers.spec.js +232 -0
- package/dist/components/WhoHasAccess.js +1 -5
- package/dist/helpers/permissions.js +15 -0
- package/locales/en.json +30 -0
- package/locales/fr.json +31 -0
- package/package.json +11 -7
- package/src/SharingProvider.jsx +10 -5
- package/src/components/Recipient/LinkRecipient.jsx +28 -4
- 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 +126 -0
- package/src/components/ShareRestrictionModal/ShareRestrictionContentModal.jsx +124 -0
- package/src/components/ShareRestrictionModal/ShareRestrictionModal.jsx +186 -0
- package/src/components/ShareRestrictionModal/helpers.js +227 -0
- package/src/components/ShareRestrictionModal/helpers.spec.js +159 -0
- package/src/components/WhoHasAccess.jsx +1 -5
- package/src/helpers/permissions.js +12 -0
- 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,155 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import React, { useState } from 'react';
|
|
7
|
+
import Box from 'cozy-ui/transpiled/react/Box';
|
|
8
|
+
import Icon from 'cozy-ui/transpiled/react/Icon';
|
|
9
|
+
import IconButton from 'cozy-ui/transpiled/react/IconButton';
|
|
10
|
+
import List from 'cozy-ui/transpiled/react/List';
|
|
11
|
+
import ListItem from 'cozy-ui/transpiled/react/ListItem';
|
|
12
|
+
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon';
|
|
13
|
+
import ListItemSecondaryAction from 'cozy-ui/transpiled/react/ListItemSecondaryAction';
|
|
14
|
+
import ListItemText from 'cozy-ui/transpiled/react/ListItemText';
|
|
15
|
+
import Switch from 'cozy-ui/transpiled/react/Switch';
|
|
16
|
+
import TextField from 'cozy-ui/transpiled/react/TextField';
|
|
17
|
+
import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert';
|
|
18
|
+
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
|
|
19
|
+
import { copyToClipboard } from './helpers';
|
|
20
|
+
import { checkIsPermissionHasPassword } from '../../helpers/permissions';
|
|
21
|
+
import { useSharingContext } from '../../hooks/useSharingContext';
|
|
22
|
+
export var BoxPassword = function BoxPassword(_ref) {
|
|
23
|
+
var file = _ref.file,
|
|
24
|
+
onChange = _ref.onChange,
|
|
25
|
+
password = _ref.password,
|
|
26
|
+
onToggle = _ref.onToggle,
|
|
27
|
+
toggle = _ref.toggle,
|
|
28
|
+
helperText = _ref.helperText,
|
|
29
|
+
inputProps = _ref.inputProps;
|
|
30
|
+
|
|
31
|
+
var _useI18n = useI18n(),
|
|
32
|
+
t = _useI18n.t;
|
|
33
|
+
|
|
34
|
+
var _useAlert = useAlert(),
|
|
35
|
+
showAlert = _useAlert.showAlert;
|
|
36
|
+
|
|
37
|
+
var _useState = useState(false),
|
|
38
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
39
|
+
displayHelper = _useState2[0],
|
|
40
|
+
setDisplayHelper = _useState2[1];
|
|
41
|
+
|
|
42
|
+
var inputRef = React.useRef();
|
|
43
|
+
|
|
44
|
+
var _useSharingContext = useSharingContext(),
|
|
45
|
+
getDocumentPermissions = _useSharingContext.getDocumentPermissions;
|
|
46
|
+
|
|
47
|
+
var permissions = getDocumentPermissions(file._id);
|
|
48
|
+
var hasPassword = checkIsPermissionHasPassword(permissions);
|
|
49
|
+
|
|
50
|
+
var handlePasswordToggle = function handlePasswordToggle(val) {
|
|
51
|
+
var _val$target$checked, _val$target;
|
|
52
|
+
|
|
53
|
+
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;
|
|
54
|
+
onToggle(value);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
var handleChange = function handleChange(val) {
|
|
58
|
+
var _val$target$value, _val$target2;
|
|
59
|
+
|
|
60
|
+
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;
|
|
61
|
+
onChange(value);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
var handleOnFocus = function handleOnFocus() {
|
|
65
|
+
setDisplayHelper(false);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
var handleOnBlur = function handleOnBlur() {
|
|
69
|
+
handleChange(inputRef.current.value.trim());
|
|
70
|
+
setDisplayHelper(true);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
var handleCopy = /*#__PURE__*/function () {
|
|
74
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
75
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
76
|
+
while (1) switch (_context.prev = _context.next) {
|
|
77
|
+
case 0:
|
|
78
|
+
_context.next = 2;
|
|
79
|
+
return copyToClipboard(password, {
|
|
80
|
+
t: t,
|
|
81
|
+
showAlert: showAlert
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
case 2:
|
|
85
|
+
case "end":
|
|
86
|
+
return _context.stop();
|
|
87
|
+
}
|
|
88
|
+
}, _callee);
|
|
89
|
+
}));
|
|
90
|
+
|
|
91
|
+
return function handleCopy() {
|
|
92
|
+
return _ref2.apply(this, arguments);
|
|
93
|
+
};
|
|
94
|
+
}();
|
|
95
|
+
|
|
96
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
97
|
+
borderRadius: "0.5rem",
|
|
98
|
+
border: "1px solid var(--borderMainColor)"
|
|
99
|
+
}, /*#__PURE__*/React.createElement(List, {
|
|
100
|
+
className: "u-p-0"
|
|
101
|
+
}, /*#__PURE__*/React.createElement(ListItem, {
|
|
102
|
+
button: true,
|
|
103
|
+
size: "large",
|
|
104
|
+
ellipsis: false,
|
|
105
|
+
onClick: function onClick() {
|
|
106
|
+
return handlePasswordToggle(!toggle);
|
|
107
|
+
}
|
|
108
|
+
}, /*#__PURE__*/React.createElement(ListItemIcon, null, /*#__PURE__*/React.createElement(Icon, {
|
|
109
|
+
icon: "password"
|
|
110
|
+
})), /*#__PURE__*/React.createElement(ListItemText, {
|
|
111
|
+
primary: t('BoxPassword.text')
|
|
112
|
+
}), /*#__PURE__*/React.createElement(ListItemSecondaryAction, null, /*#__PURE__*/React.createElement(Switch, {
|
|
113
|
+
edge: "end",
|
|
114
|
+
color: "primary",
|
|
115
|
+
checked: toggle,
|
|
116
|
+
onChange: handlePasswordToggle
|
|
117
|
+
})))), toggle && /*#__PURE__*/React.createElement("div", {
|
|
118
|
+
className: "u-pt-half u-ph-1 u-pb-1"
|
|
119
|
+
}, /*#__PURE__*/React.createElement(TextField, _extends({
|
|
120
|
+
inputRef: inputRef,
|
|
121
|
+
autoFocus: true,
|
|
122
|
+
label: t('BoxPassword.label')
|
|
123
|
+
}, hasPassword && {
|
|
124
|
+
placeholder: '****',
|
|
125
|
+
InputLabelProps: {
|
|
126
|
+
shrink: true
|
|
127
|
+
}
|
|
128
|
+
}, {
|
|
129
|
+
value: password,
|
|
130
|
+
error: displayHelper && !!helperText,
|
|
131
|
+
helperText: displayHelper && helperText,
|
|
132
|
+
onChange: handleChange,
|
|
133
|
+
onFocus: handleOnFocus,
|
|
134
|
+
onBlur: handleOnBlur,
|
|
135
|
+
fullWidth: true,
|
|
136
|
+
type: "text",
|
|
137
|
+
variant: "outlined",
|
|
138
|
+
InputProps: {
|
|
139
|
+
endAdornment: /*#__PURE__*/React.createElement(IconButton, {
|
|
140
|
+
onClick: handleCopy
|
|
141
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
142
|
+
icon: "copy"
|
|
143
|
+
}))
|
|
144
|
+
},
|
|
145
|
+
inputProps: inputProps
|
|
146
|
+
}))));
|
|
147
|
+
};
|
|
148
|
+
BoxPassword.propTypes = {
|
|
149
|
+
onChange: PropTypes.func.isRequired,
|
|
150
|
+
password: PropTypes.string,
|
|
151
|
+
onToggle: PropTypes.func.isRequired,
|
|
152
|
+
toggle: PropTypes.bool.isRequired,
|
|
153
|
+
helperText: PropTypes.string,
|
|
154
|
+
inputProps: PropTypes.object
|
|
155
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { addDays, isValid } 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
|
+
import { checkIsPermissionHasPassword } from '../../helpers/permissions';
|
|
11
|
+
import { useSharingContext } from '../../hooks/useSharingContext';
|
|
12
|
+
var PASSWORD_MIN_LENGTH = 4;
|
|
13
|
+
export var ShareRestrictionContentModal = function ShareRestrictionContentModal(_ref) {
|
|
14
|
+
var file = _ref.file,
|
|
15
|
+
selectedDate = _ref.selectedDate,
|
|
16
|
+
setSelectedDate = _ref.setSelectedDate,
|
|
17
|
+
dateToggle = _ref.dateToggle,
|
|
18
|
+
setDateToggle = _ref.setDateToggle,
|
|
19
|
+
setIsValidDate = _ref.setIsValidDate,
|
|
20
|
+
helperTextPassword = _ref.helperTextPassword,
|
|
21
|
+
password = _ref.password,
|
|
22
|
+
setPassword = _ref.setPassword,
|
|
23
|
+
passwordToggle = _ref.passwordToggle,
|
|
24
|
+
setPasswordToggle = _ref.setPasswordToggle,
|
|
25
|
+
setIsValidPassword = _ref.setIsValidPassword,
|
|
26
|
+
editingRights = _ref.editingRights,
|
|
27
|
+
setEditingRights = _ref.setEditingRights;
|
|
28
|
+
|
|
29
|
+
var _useI18n = useI18n(),
|
|
30
|
+
t = _useI18n.t;
|
|
31
|
+
|
|
32
|
+
var _useSharingContext = useSharingContext(),
|
|
33
|
+
getDocumentPermissions = _useSharingContext.getDocumentPermissions;
|
|
34
|
+
|
|
35
|
+
var permissions = getDocumentPermissions(file._id);
|
|
36
|
+
var hasPassword = checkIsPermissionHasPassword(permissions);
|
|
37
|
+
|
|
38
|
+
var handlePassword = function handlePassword(value) {
|
|
39
|
+
setPassword(value);
|
|
40
|
+
setIsValidPassword(hasPassword && value.trim().length === 0 || value.trim().length >= PASSWORD_MIN_LENGTH);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
var handlePasswordToggle = function handlePasswordToggle(val) {
|
|
44
|
+
setPasswordToggle(val);
|
|
45
|
+
setPassword('');
|
|
46
|
+
|
|
47
|
+
if (val && !password) {
|
|
48
|
+
setIsValidPassword(hasPassword);
|
|
49
|
+
} else {
|
|
50
|
+
setIsValidPassword(true);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
var handleDate = function handleDate(date) {
|
|
55
|
+
setSelectedDate(date);
|
|
56
|
+
setIsValidDate(isValid(date));
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
var handleDateToggle = function handleDateToggle(val) {
|
|
60
|
+
setDateToggle(val);
|
|
61
|
+
|
|
62
|
+
if (!val) {
|
|
63
|
+
setSelectedDate(null);
|
|
64
|
+
setIsValidDate(true);
|
|
65
|
+
} else {
|
|
66
|
+
var defaultValue = val ? addDays(new Date(), 30) : null;
|
|
67
|
+
setSelectedDate(defaultValue);
|
|
68
|
+
setIsValidDate(true);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
73
|
+
display: "flex",
|
|
74
|
+
flexDirection: "column",
|
|
75
|
+
gridGap: "1rem"
|
|
76
|
+
}, /*#__PURE__*/React.createElement(Typography, {
|
|
77
|
+
variant: "h4",
|
|
78
|
+
className: "u-mb-half u-ml-half"
|
|
79
|
+
}, t('ShareRestrictionModal.title')), /*#__PURE__*/React.createElement(BoxEditingRights, {
|
|
80
|
+
file: file,
|
|
81
|
+
editingRights: editingRights,
|
|
82
|
+
setEditingRights: setEditingRights
|
|
83
|
+
}), /*#__PURE__*/React.createElement(BoxDate, {
|
|
84
|
+
onChange: handleDate,
|
|
85
|
+
date: selectedDate,
|
|
86
|
+
onToggle: handleDateToggle,
|
|
87
|
+
toggle: dateToggle
|
|
88
|
+
}), /*#__PURE__*/React.createElement(BoxPassword, {
|
|
89
|
+
file: file,
|
|
90
|
+
onChange: handlePassword,
|
|
91
|
+
password: password,
|
|
92
|
+
onToggle: handlePasswordToggle,
|
|
93
|
+
toggle: passwordToggle,
|
|
94
|
+
helperText: helperTextPassword,
|
|
95
|
+
inputProps: {
|
|
96
|
+
minLength: PASSWORD_MIN_LENGTH
|
|
97
|
+
}
|
|
98
|
+
}));
|
|
99
|
+
};
|
|
100
|
+
ShareRestrictionContentModal.propTypes = {
|
|
101
|
+
file: PropTypes.object.isRequired,
|
|
102
|
+
// Date
|
|
103
|
+
selectedDate: PropTypes.object,
|
|
104
|
+
setSelectedDate: PropTypes.func.isRequired,
|
|
105
|
+
dateToggle: PropTypes.bool,
|
|
106
|
+
setDateToggle: PropTypes.func.isRequired,
|
|
107
|
+
setIsValidDate: PropTypes.func.isRequired,
|
|
108
|
+
// Password
|
|
109
|
+
helperTextPassword: PropTypes.string,
|
|
110
|
+
password: PropTypes.string,
|
|
111
|
+
setPassword: PropTypes.func.isRequired,
|
|
112
|
+
passwordToggle: PropTypes.bool.isRequired,
|
|
113
|
+
setPasswordToggle: PropTypes.func.isRequired,
|
|
114
|
+
setIsValidPassword: PropTypes.func.isRequired,
|
|
115
|
+
// Editing rights
|
|
116
|
+
editingRights: PropTypes.oneOf(['readOnly', 'write']),
|
|
117
|
+
setEditingRights: PropTypes.func.isRequired
|
|
118
|
+
};
|
|
@@ -0,0 +1,256 @@
|
|
|
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 { generateWebLink, useClient } from 'cozy-client';
|
|
8
|
+
import Button from 'cozy-ui/transpiled/react/Buttons';
|
|
9
|
+
import { ConfirmDialog } from 'cozy-ui/transpiled/react/CozyDialogs';
|
|
10
|
+
import Icon from 'cozy-ui/transpiled/react/Icon';
|
|
11
|
+
import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert';
|
|
12
|
+
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
|
|
13
|
+
import { ShareRestrictionContentModal } from './ShareRestrictionContentModal';
|
|
14
|
+
import { copyToClipboard, updatePermissions, makeTTL, revokePermissions, createPermissions } from './helpers';
|
|
15
|
+
import { checkIsPermissionHasExpiresDate, checkIsPermissionHasPassword, checkIsReadOnlyPermissions, getPermissionExpiresDate } from '../../helpers/permissions';
|
|
16
|
+
import { useSharingContext } from '../../hooks/useSharingContext';
|
|
17
|
+
var PASSWORD_MIN_LENGTH = 4;
|
|
18
|
+
export var ShareRestrictionModal = function ShareRestrictionModal(_ref) {
|
|
19
|
+
var file = _ref.file,
|
|
20
|
+
onClose = _ref.onClose;
|
|
21
|
+
var client = useClient();
|
|
22
|
+
|
|
23
|
+
var _useI18n = useI18n(),
|
|
24
|
+
t = _useI18n.t;
|
|
25
|
+
|
|
26
|
+
var _useAlert = useAlert(),
|
|
27
|
+
showAlert = _useAlert.showAlert;
|
|
28
|
+
|
|
29
|
+
var _useState = useState(''),
|
|
30
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
31
|
+
password = _useState2[0],
|
|
32
|
+
setPassword = _useState2[1];
|
|
33
|
+
|
|
34
|
+
var _useState3 = useState(true),
|
|
35
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
36
|
+
isValidDate = _useState4[0],
|
|
37
|
+
setIsValidDate = _useState4[1];
|
|
38
|
+
|
|
39
|
+
var _useState5 = useState(true),
|
|
40
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
41
|
+
isValidPassword = _useState6[0],
|
|
42
|
+
setIsValidPassword = _useState6[1];
|
|
43
|
+
|
|
44
|
+
var _useState7 = useState(false),
|
|
45
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
46
|
+
loading = _useState8[0],
|
|
47
|
+
setLoading = _useState8[1];
|
|
48
|
+
|
|
49
|
+
var _useSharingContext = useSharingContext(),
|
|
50
|
+
documentType = _useSharingContext.documentType,
|
|
51
|
+
getDocumentPermissions = _useSharingContext.getDocumentPermissions,
|
|
52
|
+
updateDocumentPermissions = _useSharingContext.updateDocumentPermissions,
|
|
53
|
+
shareByLink = _useSharingContext.shareByLink,
|
|
54
|
+
getSharingLink = _useSharingContext.getSharingLink,
|
|
55
|
+
revokeSharingLink = _useSharingContext.revokeSharingLink;
|
|
56
|
+
|
|
57
|
+
var hasSharingLink = getSharingLink(file._id) !== null;
|
|
58
|
+
var permissions = getDocumentPermissions(file._id);
|
|
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];
|
|
79
|
+
|
|
80
|
+
var _useState15 = useState(isReadOnlyPermissions || permissions.length === 0 ? 'readOnly' : 'write'),
|
|
81
|
+
_useState16 = _slicedToArray(_useState15, 2),
|
|
82
|
+
editingRights = _useState16[0],
|
|
83
|
+
setEditingRights = _useState16[1];
|
|
84
|
+
|
|
85
|
+
var helperTextPassword = !isValidPassword ? t('ShareRestrictionModal.invalidPasswordMessage', {
|
|
86
|
+
smart_count: PASSWORD_MIN_LENGTH - password.length
|
|
87
|
+
}) : null;
|
|
88
|
+
|
|
89
|
+
var handleClick = /*#__PURE__*/function () {
|
|
90
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
91
|
+
var ttl, _yield$createPermissi2, perms, url, _yield$updatePermissi3, _yield$updatePermissi4, _perms, _url;
|
|
92
|
+
|
|
93
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
94
|
+
while (1) switch (_context.prev = _context.next) {
|
|
95
|
+
case 0:
|
|
96
|
+
setLoading(true); // If the file is not shared, we create a new sharing link
|
|
97
|
+
|
|
98
|
+
if (hasSharingLink) {
|
|
99
|
+
_context.next = 13;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
ttl = makeTTL(dateToggle && selectedDate);
|
|
104
|
+
_context.next = 5;
|
|
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
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
case 5:
|
|
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;
|
|
127
|
+
return copyToClipboard(url, {
|
|
128
|
+
t: t,
|
|
129
|
+
showAlert: showAlert
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
case 10:
|
|
133
|
+
onClose();
|
|
134
|
+
_context.next = 22;
|
|
135
|
+
break;
|
|
136
|
+
|
|
137
|
+
case 13:
|
|
138
|
+
_context.next = 15;
|
|
139
|
+
return updatePermissions({
|
|
140
|
+
file: file,
|
|
141
|
+
t: t,
|
|
142
|
+
dateToggle: dateToggle,
|
|
143
|
+
selectedDate: selectedDate,
|
|
144
|
+
passwordToggle: passwordToggle,
|
|
145
|
+
password: password,
|
|
146
|
+
editingRights: editingRights,
|
|
147
|
+
documentType: documentType,
|
|
148
|
+
updateDocumentPermissions: updateDocumentPermissions,
|
|
149
|
+
showAlert: showAlert
|
|
150
|
+
});
|
|
151
|
+
|
|
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'
|
|
162
|
+
});
|
|
163
|
+
_context.next = 21;
|
|
164
|
+
return copyToClipboard(_url, {
|
|
165
|
+
t: t,
|
|
166
|
+
showAlert: showAlert
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
case 21:
|
|
170
|
+
onClose();
|
|
171
|
+
|
|
172
|
+
case 22:
|
|
173
|
+
case "end":
|
|
174
|
+
return _context.stop();
|
|
175
|
+
}
|
|
176
|
+
}, _callee);
|
|
177
|
+
}));
|
|
178
|
+
|
|
179
|
+
return function handleClick() {
|
|
180
|
+
return _ref2.apply(this, arguments);
|
|
181
|
+
};
|
|
182
|
+
}();
|
|
183
|
+
|
|
184
|
+
var handleRevokeLink = /*#__PURE__*/function () {
|
|
185
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
186
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
187
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
188
|
+
case 0:
|
|
189
|
+
setLoading(true);
|
|
190
|
+
_context2.next = 3;
|
|
191
|
+
return revokePermissions({
|
|
192
|
+
file: file,
|
|
193
|
+
t: t,
|
|
194
|
+
documentType: documentType,
|
|
195
|
+
revokeSharingLink: revokeSharingLink,
|
|
196
|
+
showAlert: showAlert
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
case 3:
|
|
200
|
+
onClose();
|
|
201
|
+
|
|
202
|
+
case 4:
|
|
203
|
+
case "end":
|
|
204
|
+
return _context2.stop();
|
|
205
|
+
}
|
|
206
|
+
}, _callee2);
|
|
207
|
+
}));
|
|
208
|
+
|
|
209
|
+
return function handleRevokeLink() {
|
|
210
|
+
return _ref3.apply(this, arguments);
|
|
211
|
+
};
|
|
212
|
+
}();
|
|
213
|
+
|
|
214
|
+
return /*#__PURE__*/React.createElement(ConfirmDialog, {
|
|
215
|
+
open: true,
|
|
216
|
+
onClose: onClose,
|
|
217
|
+
content: /*#__PURE__*/React.createElement(ShareRestrictionContentModal, {
|
|
218
|
+
file: file // Date
|
|
219
|
+
,
|
|
220
|
+
dateToggle: dateToggle,
|
|
221
|
+
setDateToggle: setDateToggle,
|
|
222
|
+
setSelectedDate: setSelectedDate,
|
|
223
|
+
selectedDate: selectedDate,
|
|
224
|
+
setIsValidDate: setIsValidDate // Password
|
|
225
|
+
,
|
|
226
|
+
helperTextPassword: helperTextPassword,
|
|
227
|
+
passwordToggle: passwordToggle,
|
|
228
|
+
setPasswordToggle: setPasswordToggle,
|
|
229
|
+
password: password,
|
|
230
|
+
setPassword: setPassword,
|
|
231
|
+
setIsValidPassword: setIsValidPassword // Editing rights
|
|
232
|
+
,
|
|
233
|
+
editingRights: editingRights,
|
|
234
|
+
setEditingRights: setEditingRights
|
|
235
|
+
}),
|
|
236
|
+
actions: /*#__PURE__*/React.createElement(React.Fragment, null, hasSharingLink && /*#__PURE__*/React.createElement(Button, {
|
|
237
|
+
label: t('Share.permissionLink.deactivate'),
|
|
238
|
+
variant: "secondary",
|
|
239
|
+
color: "error",
|
|
240
|
+
startIcon: /*#__PURE__*/React.createElement(Icon, {
|
|
241
|
+
icon: "trash"
|
|
242
|
+
}),
|
|
243
|
+
onClick: handleRevokeLink,
|
|
244
|
+
busy: loading
|
|
245
|
+
}), /*#__PURE__*/React.createElement(Button, {
|
|
246
|
+
label: t('ShareRestrictionModal.action.confirm'),
|
|
247
|
+
onClick: handleClick,
|
|
248
|
+
disabled: !isValidDate || !isValidPassword,
|
|
249
|
+
busy: loading
|
|
250
|
+
}))
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
ShareRestrictionModal.propTypes = {
|
|
254
|
+
file: PropTypes.object.isRequired,
|
|
255
|
+
onClose: PropTypes.func
|
|
256
|
+
};
|