cozy-sharing 32.3.1 → 32.3.2
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 +6 -0
- package/dist/components/FederatedFolder/FederatedFolderModal.js +56 -19
- package/dist/components/FederatedFolder/FederatedFolderModal.spec.js +101 -254
- package/dist/components/Recipient/RecipientList.js +0 -15
- package/dist/components/ShareModal/ShareModal.js +8 -8
- package/dist/state.js +6 -1
- package/package.json +2 -2
- package/src/components/FederatedFolder/FederatedFolderModal.jsx +65 -19
- package/src/components/FederatedFolder/FederatedFolderModal.spec.jsx +28 -150
- package/src/components/Recipient/RecipientList.jsx +0 -18
- package/src/components/ShareModal/ShareModal.jsx +5 -5
- package/src/state.js +5 -1
- package/.claude/settings.local.json +0 -27
- package/AGENTS.md +0 -7
- package/dist/RefreshableSharings.spec.js +0 -40
- package/dist/assets/illustrations/illustration-shared-drives.svg +0 -1
- package/dist/components/EditLinkPermissionDialog.js +0 -72
- package/dist/components/EditLinkPermissionDialog.spec.js +0 -48
- package/dist/components/FederatedFolder/DumbFederatedFolderModal.js +0 -65
- package/dist/components/FederatedFolder/DumbFederatedFolderModal.spec.js +0 -107
- package/dist/components/FederatedFolder/FederatedFolderModal.jsx.tmp.179197.1773939270471 +0 -172
- package/dist/components/Recipient/actions/revokeGroup.js +0 -42
- package/dist/components/Recipient/actions/revokeMember.js +0 -42
- package/dist/components/Recipient/actions/revokeSharedDriveMember.js +0 -41
- package/dist/components/ShareModal/ShareModal copy.js +0 -43
- package/dist/components/ShareModal/ShareModal.spec.js +0 -197
- package/dist/components/ShareModal/ShareModalBatchContainer.js +0 -276
- package/dist/components/ShareModal/ShareModalBatchContainer.spec.js +0 -131
- package/dist/components/ShareModal/SharedDriveEditModal.js +0 -59
- package/dist/components/SharedDrive/DumbSharedDriveModal.js +0 -78
- package/dist/components/SharedDrive/DumbSharedDriveModal.spec.js +0 -126
- package/dist/components/SharedDrive/SharedDriveEditModal.js +0 -110
- package/dist/components/SharedDrive/SharedDriveModal copy.js +0 -356
- package/dist/components/SharedDrive/SharedDriveRecipient.js +0 -61
- package/dist/components/SharedDrive/SharedDriveRecipientPermissions.js +0 -109
- package/dist/components/SharedDrive/SharedDriveRecipientStatus.js +0 -22
- package/dist/components/SharedDrive/helpers.js +0 -102
- package/dist/components/SharedDrive/helpers.spec.js +0 -208
- package/dist/components/SharedDriveEditModal.js +0 -43
- package/dist/components/SharedFolder/DumbBatchSharedFolderModal.js +0 -145
- package/dist/components/SharedFolder/DumbBatchSharedFolderModal.spec.js +0 -321
- package/dist/components/SharedStatus.js +0 -61
- package/dist/components/SharedStatus.spec.js +0 -44
- package/dist/components/Sharesubmit.js +0 -28
- package/dist/components/__snapshots__/SharedStatus.spec.js.snap +0 -94
- package/dist/helpers/owner.js +0 -14
- package/dist/helpers/owner.spec.js +0 -34
- package/dist/hooks/useConfirmDiscardChanges.js +0 -33
- package/dist/hooks/useContactsAndGroups.js +0 -65
- package/dist/hooks/useSharedDrive.js +0 -130
- package/dist/hooks/useSharedDriveContactsAndGroups.js +0 -65
- package/dist/propTypes.js +0 -26
- package/dist/styles/shareddrive.styl +0 -8
- package/src/components/SharedDrive/SharedDriveRecipient.jsx +0 -62
- package/src/components/SharedDrive/SharedDriveRecipientPermissions.jsx +0 -78
- package/src/components/SharedDrive/SharedDriveRecipientStatus.jsx +0 -23
- package/src/components/SharedFolder/DumbBatchSharedFolderModal.jsx +0 -161
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import PropTypes from 'prop-types';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { useI18n } from 'twake-i18n';
|
|
4
|
-
import withLocales from '../../hoc/withLocales';
|
|
5
|
-
import { DumbBatchSharedFolderModal } from '../SharedFolder/DumbBatchSharedFolderModal';
|
|
6
|
-
export var DumbSharedDriveModal = withLocales(function (_ref) {
|
|
7
|
-
var title = _ref.title,
|
|
8
|
-
document = _ref.document,
|
|
9
|
-
sharedDriveName = _ref.sharedDriveName,
|
|
10
|
-
handleSharedDriveNameChange = _ref.handleSharedDriveNameChange,
|
|
11
|
-
createContact = _ref.createContact,
|
|
12
|
-
recipients = _ref.recipients,
|
|
13
|
-
currentRecipients = _ref.currentRecipients,
|
|
14
|
-
onRevoke = _ref.onRevoke,
|
|
15
|
-
onSetType = _ref.onSetType,
|
|
16
|
-
onCreate = _ref.onCreate,
|
|
17
|
-
onSend = _ref.onSend,
|
|
18
|
-
onClose = _ref.onClose,
|
|
19
|
-
onShare = _ref.onShare,
|
|
20
|
-
onRename = _ref.onRename,
|
|
21
|
-
_ref$showNameField = _ref.showNameField,
|
|
22
|
-
showNameField = _ref$showNameField === void 0 ? true : _ref$showNameField,
|
|
23
|
-
sharingLink = _ref.sharingLink,
|
|
24
|
-
autoOpenShareRestriction = _ref.autoOpenShareRestriction,
|
|
25
|
-
showGenerateLinkButton = _ref.showGenerateLinkButton;
|
|
26
|
-
|
|
27
|
-
var _useI18n = useI18n(),
|
|
28
|
-
t = _useI18n.t;
|
|
29
|
-
|
|
30
|
-
return /*#__PURE__*/React.createElement(DumbBatchSharedFolderModal, {
|
|
31
|
-
title: title,
|
|
32
|
-
document: document,
|
|
33
|
-
folderName: sharedDriveName,
|
|
34
|
-
handleFolderNameChange: handleSharedDriveNameChange,
|
|
35
|
-
createContact: createContact,
|
|
36
|
-
recipients: recipients,
|
|
37
|
-
currentRecipients: currentRecipients,
|
|
38
|
-
onRevoke: onRevoke,
|
|
39
|
-
onSetType: onSetType,
|
|
40
|
-
onCreate: onCreate,
|
|
41
|
-
onSend: onSend,
|
|
42
|
-
onClose: onClose,
|
|
43
|
-
onShare: onShare,
|
|
44
|
-
onRename: onRename,
|
|
45
|
-
showNameField: showNameField,
|
|
46
|
-
sharingLink: sharingLink,
|
|
47
|
-
nameLabel: t('SharedDrive.sharedDriveModal.nameLabel'),
|
|
48
|
-
addPeopleLabel: t('SharedDrive.sharedDriveModal.addPeople'),
|
|
49
|
-
addButtonLabel: t('SharedDrive.sharedDriveModal.add'),
|
|
50
|
-
cancelLabel: t('SharedDrive.sharedDriveModal.cancel'),
|
|
51
|
-
createLabel: t('SharedDrive.sharedDriveModal.create'),
|
|
52
|
-
shareLabel: t('FederatedFolder.share'),
|
|
53
|
-
saveLabel: t('SharedDrive.sharedDriveModal.save'),
|
|
54
|
-
autoOpenShareRestriction: autoOpenShareRestriction,
|
|
55
|
-
showGenerateLinkButton: showGenerateLinkButton
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
DumbSharedDriveModal.propTypes = {
|
|
59
|
-
title: PropTypes.string,
|
|
60
|
-
document: PropTypes.object,
|
|
61
|
-
sharedDriveName: PropTypes.string,
|
|
62
|
-
handleSharedDriveNameChange: PropTypes.func,
|
|
63
|
-
createContact: PropTypes.func.isRequired,
|
|
64
|
-
recipients: PropTypes.array,
|
|
65
|
-
currentRecipients: PropTypes.array,
|
|
66
|
-
onRevoke: PropTypes.func.isRequired,
|
|
67
|
-
onSetType: PropTypes.func.isRequired,
|
|
68
|
-
onCreate: PropTypes.func,
|
|
69
|
-
onSend: PropTypes.func,
|
|
70
|
-
onClose: PropTypes.func.isRequired,
|
|
71
|
-
onShare: PropTypes.func.isRequired,
|
|
72
|
-
onRename: PropTypes.func,
|
|
73
|
-
showNameField: PropTypes.bool,
|
|
74
|
-
sharingLink: PropTypes.string,
|
|
75
|
-
autoOpenShareRestriction: PropTypes.bool,
|
|
76
|
-
showGenerateLinkButton: PropTypes.bool
|
|
77
|
-
};
|
|
78
|
-
export default DumbSharedDriveModal;
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import { render } from '@testing-library/react';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { DumbSharedDriveModal } from './DumbSharedDriveModal';
|
|
5
|
-
var mockDumbBatchSharedFolderModal = jest.fn();
|
|
6
|
-
jest.mock('../SharedFolder/DumbBatchSharedFolderModal', function () {
|
|
7
|
-
return {
|
|
8
|
-
__esModule: true,
|
|
9
|
-
default: function _default(props) {
|
|
10
|
-
mockDumbBatchSharedFolderModal(props);
|
|
11
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
12
|
-
"data-testid": "dumb-batch-shared-folder-modal"
|
|
13
|
-
}, "DumbBatchSharedFolderModal");
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
jest.mock('../../hoc/withLocales', function () {
|
|
18
|
-
return {
|
|
19
|
-
__esModule: true,
|
|
20
|
-
default: function _default(Component) {
|
|
21
|
-
return Component;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
});
|
|
25
|
-
jest.mock('twake-i18n', function () {
|
|
26
|
-
return {
|
|
27
|
-
useI18n: jest.fn().mockReturnValue({
|
|
28
|
-
t: jest.fn(function (key) {
|
|
29
|
-
return key;
|
|
30
|
-
})
|
|
31
|
-
})
|
|
32
|
-
};
|
|
33
|
-
});
|
|
34
|
-
describe('DumbSharedDriveModal', function () {
|
|
35
|
-
var defaultProps = {
|
|
36
|
-
title: 'Test Shared Drive',
|
|
37
|
-
document: {
|
|
38
|
-
_id: 'doc-123',
|
|
39
|
-
name: 'Test'
|
|
40
|
-
},
|
|
41
|
-
sharedDriveName: 'My Drive',
|
|
42
|
-
handleSharedDriveNameChange: jest.fn(),
|
|
43
|
-
createContact: jest.fn(),
|
|
44
|
-
recipients: [{
|
|
45
|
-
_id: 'r1',
|
|
46
|
-
email: 'test@test.com'
|
|
47
|
-
}],
|
|
48
|
-
currentRecipients: [],
|
|
49
|
-
onRevoke: jest.fn(),
|
|
50
|
-
onSetType: jest.fn(),
|
|
51
|
-
onCreate: jest.fn(),
|
|
52
|
-
onSend: jest.fn(),
|
|
53
|
-
onClose: jest.fn(),
|
|
54
|
-
onShare: jest.fn(),
|
|
55
|
-
onRename: jest.fn(),
|
|
56
|
-
showNameField: true,
|
|
57
|
-
sharingLink: 'https://share.link/123',
|
|
58
|
-
hasRecipientsInitially: false
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
var setup = function setup() {
|
|
62
|
-
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
63
|
-
mockDumbBatchSharedFolderModal.mockClear();
|
|
64
|
-
return render( /*#__PURE__*/React.createElement(DumbSharedDriveModal, _extends({}, defaultProps, props)));
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
it('should render DumbBatchSharedFolderModal with correct props', function () {
|
|
68
|
-
setup();
|
|
69
|
-
expect(mockDumbBatchSharedFolderModal).toHaveBeenCalledWith(expect.objectContaining({
|
|
70
|
-
title: 'Test Shared Drive',
|
|
71
|
-
document: defaultProps.document,
|
|
72
|
-
folderName: 'My Drive',
|
|
73
|
-
handleFolderNameChange: defaultProps.handleSharedDriveNameChange,
|
|
74
|
-
createContact: defaultProps.createContact,
|
|
75
|
-
recipients: defaultProps.recipients,
|
|
76
|
-
currentRecipients: defaultProps.currentRecipients,
|
|
77
|
-
onRevoke: defaultProps.onRevoke,
|
|
78
|
-
onSetType: defaultProps.onSetType,
|
|
79
|
-
onCreate: defaultProps.onCreate,
|
|
80
|
-
onSend: defaultProps.onSend,
|
|
81
|
-
onClose: defaultProps.onClose,
|
|
82
|
-
onShare: defaultProps.onShare,
|
|
83
|
-
onRename: defaultProps.onRename,
|
|
84
|
-
showNameField: true,
|
|
85
|
-
sharingLink: 'https://share.link/123',
|
|
86
|
-
hasRecipientsInitially: false
|
|
87
|
-
}));
|
|
88
|
-
});
|
|
89
|
-
it('should pass correct i18n labels to DumbBatchSharedFolderModal', function () {
|
|
90
|
-
setup();
|
|
91
|
-
var passedProps = mockDumbBatchSharedFolderModal.mock.calls[0][0];
|
|
92
|
-
expect(passedProps.nameLabel).toBe('SharedDrive.sharedDriveModal.nameLabel');
|
|
93
|
-
expect(passedProps.addPeopleLabel).toBe('SharedDrive.sharedDriveModal.addPeople');
|
|
94
|
-
expect(passedProps.addButtonLabel).toBe('SharedDrive.sharedDriveModal.add');
|
|
95
|
-
expect(passedProps.cancelLabel).toBe('SharedDrive.sharedDriveModal.cancel');
|
|
96
|
-
expect(passedProps.createLabel).toBe('SharedDrive.sharedDriveModal.create');
|
|
97
|
-
expect(passedProps.shareLabel).toBe('SharedDrive.sharedDriveModal.share');
|
|
98
|
-
expect(passedProps.saveLabel).toBe('SharedDrive.sharedDriveModal.save');
|
|
99
|
-
});
|
|
100
|
-
it('should default showNameField to true', function () {
|
|
101
|
-
var _setup = setup({
|
|
102
|
-
showNameField: undefined
|
|
103
|
-
}),
|
|
104
|
-
rerender = _setup.rerender; // Re-render without showNameField
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
rerender( /*#__PURE__*/React.createElement(DumbSharedDriveModal, _extends({}, defaultProps, {
|
|
108
|
-
showNameField: undefined
|
|
109
|
-
})));
|
|
110
|
-
var passedProps = mockDumbBatchSharedFolderModal.mock.calls[mockDumbBatchSharedFolderModal.mock.calls.length - 1][0];
|
|
111
|
-
expect(passedProps.showNameField).toBe(true);
|
|
112
|
-
});
|
|
113
|
-
it('should handle hasRecipientsInitially correctly', function () {
|
|
114
|
-
setup({
|
|
115
|
-
hasRecipientsInitially: true
|
|
116
|
-
});
|
|
117
|
-
var passedProps = mockDumbBatchSharedFolderModal.mock.calls[0][0];
|
|
118
|
-
expect(passedProps.hasRecipientsInitially).toBe(true);
|
|
119
|
-
});
|
|
120
|
-
it('should render the mocked component', function () {
|
|
121
|
-
var _setup2 = setup(),
|
|
122
|
-
getByTestId = _setup2.getByTestId;
|
|
123
|
-
|
|
124
|
-
expect(getByTestId('dumb-batch-shared-folder-modal')).toBeInTheDocument();
|
|
125
|
-
});
|
|
126
|
-
});
|
|
@@ -1,110 +0,0 @@
|
|
|
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 { useClient } from 'cozy-client';
|
|
7
|
-
import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert';
|
|
8
|
-
import { useI18n } from 'twake-i18n';
|
|
9
|
-
import { DumbSharedDriveModal } from './DumbSharedDriveModal';
|
|
10
|
-
import withLocales from '../../hoc/withLocales';
|
|
11
|
-
import { useSharingContext } from '../../hooks/useSharingContext';
|
|
12
|
-
import { Contact } from '../../models';
|
|
13
|
-
export var SharedDriveEditModal = withLocales(function (_ref) {
|
|
14
|
-
var document = _ref.document,
|
|
15
|
-
sharing = _ref.sharing,
|
|
16
|
-
recipients = _ref.recipients,
|
|
17
|
-
onShare = _ref.onShare,
|
|
18
|
-
onRevoke = _ref.onRevoke,
|
|
19
|
-
onClose = _ref.onClose,
|
|
20
|
-
autoOpenShareRestriction = _ref.autoOpenShareRestriction,
|
|
21
|
-
showGenerateLinkButton = _ref.showGenerateLinkButton;
|
|
22
|
-
var client = useClient();
|
|
23
|
-
|
|
24
|
-
var _useI18n = useI18n(),
|
|
25
|
-
t = _useI18n.t;
|
|
26
|
-
|
|
27
|
-
var _useAlert = useAlert(),
|
|
28
|
-
showAlert = _useAlert.showAlert;
|
|
29
|
-
|
|
30
|
-
var _useSharingContext = useSharingContext(),
|
|
31
|
-
renameSharedDrive = _useSharingContext.renameSharedDrive;
|
|
32
|
-
|
|
33
|
-
var createContact = function createContact(contact) {
|
|
34
|
-
return client.create(Contact.doctype, contact);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
var _useState = useState(sharing === null || sharing === void 0 ? void 0 : sharing.description),
|
|
38
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
39
|
-
name = _useState2[0],
|
|
40
|
-
setName = _useState2[1];
|
|
41
|
-
|
|
42
|
-
var handleNameChange = function handleNameChange(event) {
|
|
43
|
-
setName(event.target.value);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
var onRename = /*#__PURE__*/function () {
|
|
47
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(value) {
|
|
48
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
49
|
-
while (1) switch (_context.prev = _context.next) {
|
|
50
|
-
case 0:
|
|
51
|
-
_context.prev = 0;
|
|
52
|
-
_context.next = 3;
|
|
53
|
-
return renameSharedDrive(document, value);
|
|
54
|
-
|
|
55
|
-
case 3:
|
|
56
|
-
showAlert({
|
|
57
|
-
message: t('SharedDrive.sharedDriveModal.successNotificationUpdate'),
|
|
58
|
-
severity: 'success'
|
|
59
|
-
});
|
|
60
|
-
onClose();
|
|
61
|
-
_context.next = 10;
|
|
62
|
-
break;
|
|
63
|
-
|
|
64
|
-
case 7:
|
|
65
|
-
_context.prev = 7;
|
|
66
|
-
_context.t0 = _context["catch"](0);
|
|
67
|
-
showAlert({
|
|
68
|
-
message: t('SharedDrive.sharedDriveModal.errorNotificationUpdate'),
|
|
69
|
-
severity: 'error'
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
case 10:
|
|
73
|
-
case "end":
|
|
74
|
-
return _context.stop();
|
|
75
|
-
}
|
|
76
|
-
}, _callee, null, [[0, 7]]);
|
|
77
|
-
}));
|
|
78
|
-
|
|
79
|
-
return function onRename(_x) {
|
|
80
|
-
return _ref2.apply(this, arguments);
|
|
81
|
-
};
|
|
82
|
-
}();
|
|
83
|
-
|
|
84
|
-
return /*#__PURE__*/React.createElement(DumbSharedDriveModal, {
|
|
85
|
-
title: t('Files.share.title', {
|
|
86
|
-
name: sharing === null || sharing === void 0 ? void 0 : sharing.description
|
|
87
|
-
}),
|
|
88
|
-
document: document,
|
|
89
|
-
createContact: createContact,
|
|
90
|
-
recipients: recipients,
|
|
91
|
-
onRevoke: onRevoke,
|
|
92
|
-
onClose: onClose,
|
|
93
|
-
onShare: onShare,
|
|
94
|
-
sharedDriveName: name,
|
|
95
|
-
handleSharedDriveNameChange: handleNameChange,
|
|
96
|
-
onRename: onRename,
|
|
97
|
-
autoOpenShareRestriction: autoOpenShareRestriction,
|
|
98
|
-
showGenerateLinkButton: showGenerateLinkButton
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
SharedDriveEditModal.propTypes = {
|
|
102
|
-
document: PropTypes.object,
|
|
103
|
-
sharing: PropTypes.object,
|
|
104
|
-
recipients: PropTypes.array,
|
|
105
|
-
onShare: PropTypes.func.isRequired,
|
|
106
|
-
onRevoke: PropTypes.func.isRequired,
|
|
107
|
-
onClose: PropTypes.func.isRequired,
|
|
108
|
-
autoOpenShareRestriction: PropTypes.bool,
|
|
109
|
-
showGenerateLinkButton: PropTypes.bool
|
|
110
|
-
};
|
|
@@ -1,356 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
4
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
5
|
-
|
|
6
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
7
|
-
|
|
8
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
9
|
-
|
|
10
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
11
|
-
|
|
12
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
13
|
-
|
|
14
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
15
|
-
|
|
16
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
17
|
-
import PropTypes from 'prop-types';
|
|
18
|
-
import React, { useState, useEffect } from 'react';
|
|
19
|
-
import { useClient } from 'cozy-client';
|
|
20
|
-
import Button from 'cozy-ui/transpiled/react/Buttons';
|
|
21
|
-
import { FixedDialog } from 'cozy-ui/transpiled/react/CozyDialogs';
|
|
22
|
-
import TextField from 'cozy-ui/transpiled/react/TextField';
|
|
23
|
-
import Typography from 'cozy-ui/transpiled/react/Typography';
|
|
24
|
-
import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert';
|
|
25
|
-
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n';
|
|
26
|
-
import { mergeAndDeduplicateRecipients, formatRecipients } from './helpers';
|
|
27
|
-
import withLocales from '../../hoc/withLocales';
|
|
28
|
-
import useContactsAndGroups from '../../hooks/useSharedDriveContactsAndGroups';
|
|
29
|
-
import { useSharingContext } from '../../hooks/useSharingContext';
|
|
30
|
-
import { Contact } from '../../models';
|
|
31
|
-
import { buildSharingsByIdQuery } from '../../queries/queries';
|
|
32
|
-
import { default as DumbShareByEmail } from '../ShareByEmail';
|
|
33
|
-
import WhoHasAccess from '../WhoHasAccess';
|
|
34
|
-
export var SharedDriveModal = withLocales( // ({ onClose, sharedDriveId = '59ee1637e38f3dbab1cbb7eb5f0a922a' }) => {
|
|
35
|
-
function (_ref) {
|
|
36
|
-
var onClose = _ref.onClose,
|
|
37
|
-
sharedDrive = _ref.sharedDrive;
|
|
38
|
-
// ({ onClose, sharedDrive
|
|
39
|
-
var client = useClient();
|
|
40
|
-
|
|
41
|
-
var _useI18n = useI18n(),
|
|
42
|
-
t = _useI18n.t;
|
|
43
|
-
|
|
44
|
-
var _useSharingContext = useSharingContext(),
|
|
45
|
-
share = _useSharingContext.share,
|
|
46
|
-
revoke = _useSharingContext.revoke;
|
|
47
|
-
|
|
48
|
-
var _useAlert = useAlert(),
|
|
49
|
-
showAlert = _useAlert.showAlert;
|
|
50
|
-
|
|
51
|
-
var isUpdate = Boolean(sharedDrive);
|
|
52
|
-
|
|
53
|
-
var _useContactsAndGroups = useContactsAndGroups([]),
|
|
54
|
-
contactsAndGroups = _useContactsAndGroups.contactsAndGroups,
|
|
55
|
-
isLoadingContactsAndGroups = _useContactsAndGroups.isLoading;
|
|
56
|
-
|
|
57
|
-
var _useState = useState({
|
|
58
|
-
recipients: [],
|
|
59
|
-
readOnlyRecipients: []
|
|
60
|
-
}),
|
|
61
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
62
|
-
sharedDriveRecipients = _useState2[0],
|
|
63
|
-
setSharedDriveRecipients = _useState2[1];
|
|
64
|
-
|
|
65
|
-
var _useState3 = useState((sharedDrive === null || sharedDrive === void 0 ? void 0 : sharedDrive.name) || ''),
|
|
66
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
67
|
-
sharedDriveName = _useState4[0],
|
|
68
|
-
setSharedDriveName = _useState4[1];
|
|
69
|
-
|
|
70
|
-
useEffect(function () {
|
|
71
|
-
if (sharedDrive && !isLoadingContactsAndGroups) {
|
|
72
|
-
setSharedDriveName(sharedDrive.rules[0].title);
|
|
73
|
-
setSharedDriveRecipients(separateMembersByPermission(associateToContacts(sharedDrive.members, contactsAndGroups)));
|
|
74
|
-
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
75
|
-
|
|
76
|
-
}, [sharedDrive === null || sharedDrive === void 0 ? void 0 : sharedDrive._id, isLoadingContactsAndGroups]);
|
|
77
|
-
|
|
78
|
-
var onShare = function onShare(params) {
|
|
79
|
-
setSharedDriveRecipients({
|
|
80
|
-
recipients: mergeAndDeduplicateRecipients([sharedDriveRecipients.recipients, params.recipients]),
|
|
81
|
-
readOnlyRecipients: mergeAndDeduplicateRecipients([sharedDriveRecipients.readOnlyRecipients, params.readOnlyRecipients])
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
var handleSharedDriveNameChange = function handleSharedDriveNameChange(event) {
|
|
86
|
-
setSharedDriveName(event.target.value);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
var onUpdate = /*#__PURE__*/function () {
|
|
90
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
91
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
92
|
-
while (1) switch (_context.prev = _context.next) {
|
|
93
|
-
case 0:
|
|
94
|
-
// TODO rename the shared drive
|
|
95
|
-
onClose();
|
|
96
|
-
|
|
97
|
-
case 1:
|
|
98
|
-
case "end":
|
|
99
|
-
return _context.stop();
|
|
100
|
-
}
|
|
101
|
-
}, _callee);
|
|
102
|
-
}));
|
|
103
|
-
|
|
104
|
-
return function onUpdate() {
|
|
105
|
-
return _ref2.apply(this, arguments);
|
|
106
|
-
};
|
|
107
|
-
}();
|
|
108
|
-
|
|
109
|
-
var onCreate = /*#__PURE__*/function () {
|
|
110
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
111
|
-
var _yield$client$create2, sharedDriveFolder;
|
|
112
|
-
|
|
113
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
114
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
115
|
-
case 0:
|
|
116
|
-
_context2.prev = 0;
|
|
117
|
-
_context2.next = 3;
|
|
118
|
-
return client.collection('io.cozy.files').getOrCreateSharedDrivesDirectory();
|
|
119
|
-
|
|
120
|
-
case 3:
|
|
121
|
-
_context2.next = 5;
|
|
122
|
-
return client.create('io.cozy.files', {
|
|
123
|
-
name: sharedDriveName,
|
|
124
|
-
dirId: 'io.cozy.files.shared-drives-dir',
|
|
125
|
-
type: 'directory'
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
case 5:
|
|
129
|
-
_yield$client$create2 = _context2.sent;
|
|
130
|
-
sharedDriveFolder = _yield$client$create2.data;
|
|
131
|
-
_context2.next = 9;
|
|
132
|
-
return share({
|
|
133
|
-
document: sharedDriveFolder,
|
|
134
|
-
recipients: sharedDriveRecipients.recipients,
|
|
135
|
-
readOnlyRecipients: sharedDriveRecipients.readOnlyRecipients,
|
|
136
|
-
sharedDrive: true
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
case 9:
|
|
140
|
-
showAlert({
|
|
141
|
-
message: t('SharedDrive.sharedDriveModal.successNotification'),
|
|
142
|
-
severity: 'success',
|
|
143
|
-
variant: 'filled'
|
|
144
|
-
});
|
|
145
|
-
onClose();
|
|
146
|
-
_context2.next = 16;
|
|
147
|
-
break;
|
|
148
|
-
|
|
149
|
-
case 13:
|
|
150
|
-
_context2.prev = 13;
|
|
151
|
-
_context2.t0 = _context2["catch"](0);
|
|
152
|
-
showAlert({
|
|
153
|
-
message: t('SharedDrive.sharedDriveModal.errorNotification'),
|
|
154
|
-
severity: 'error',
|
|
155
|
-
variant: 'filled'
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
case 16:
|
|
159
|
-
case "end":
|
|
160
|
-
return _context2.stop();
|
|
161
|
-
}
|
|
162
|
-
}, _callee2, null, [[0, 13]]);
|
|
163
|
-
}));
|
|
164
|
-
|
|
165
|
-
return function onCreate() {
|
|
166
|
-
return _ref3.apply(this, arguments);
|
|
167
|
-
};
|
|
168
|
-
}();
|
|
169
|
-
|
|
170
|
-
var onSetType = function onSetType(index, newType) {
|
|
171
|
-
var _id = index.split('virtual-shared-drive-sharing-')[1];
|
|
172
|
-
|
|
173
|
-
if (newType === 'two-way') {
|
|
174
|
-
setSharedDriveRecipients(function (prev) {
|
|
175
|
-
var recipientToMove = prev.readOnlyRecipients.find(function (r) {
|
|
176
|
-
return r._id === _id;
|
|
177
|
-
});
|
|
178
|
-
return {
|
|
179
|
-
recipients: [].concat(_toConsumableArray(prev.recipients), [recipientToMove]),
|
|
180
|
-
readOnlyRecipients: prev.readOnlyRecipients.filter(function (r) {
|
|
181
|
-
return r._id !== _id;
|
|
182
|
-
})
|
|
183
|
-
};
|
|
184
|
-
});
|
|
185
|
-
} else {
|
|
186
|
-
setSharedDriveRecipients(function (prev) {
|
|
187
|
-
var recipientToMove = prev.recipients.find(function (r) {
|
|
188
|
-
return r._id === _id;
|
|
189
|
-
});
|
|
190
|
-
return {
|
|
191
|
-
recipients: prev.recipients.filter(function (r) {
|
|
192
|
-
return r._id !== _id;
|
|
193
|
-
}),
|
|
194
|
-
readOnlyRecipients: [].concat(_toConsumableArray(prev.readOnlyRecipients), [recipientToMove])
|
|
195
|
-
};
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
var onRevoke = /*#__PURE__*/function () {
|
|
201
|
-
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(index) {
|
|
202
|
-
var _id;
|
|
203
|
-
|
|
204
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
205
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
206
|
-
case 0:
|
|
207
|
-
_id = index.split('virtual-shared-drive-sharing-')[1];
|
|
208
|
-
console.log('onRevoke', _id);
|
|
209
|
-
_context3.next = 4;
|
|
210
|
-
return revoke({
|
|
211
|
-
_id: _id
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
case 4:
|
|
215
|
-
console.log('onRevoke after revoke', _id);
|
|
216
|
-
setSharedDriveRecipients(function (prev) {
|
|
217
|
-
return {
|
|
218
|
-
recipients: prev.recipients.filter(function (r) {
|
|
219
|
-
return r._id !== _id;
|
|
220
|
-
}),
|
|
221
|
-
readOnlyRecipients: prev.readOnlyRecipients.filter(function (r) {
|
|
222
|
-
return r._id !== _id;
|
|
223
|
-
})
|
|
224
|
-
};
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
case 6:
|
|
228
|
-
case "end":
|
|
229
|
-
return _context3.stop();
|
|
230
|
-
}
|
|
231
|
-
}, _callee3);
|
|
232
|
-
}));
|
|
233
|
-
|
|
234
|
-
return function onRevoke(_x) {
|
|
235
|
-
return _ref4.apply(this, arguments);
|
|
236
|
-
};
|
|
237
|
-
}();
|
|
238
|
-
|
|
239
|
-
var recipients = formatRecipients(sharedDriveRecipients);
|
|
240
|
-
return /*#__PURE__*/React.createElement(FixedDialog, {
|
|
241
|
-
open: true,
|
|
242
|
-
disableGutters: true,
|
|
243
|
-
onClose: onClose,
|
|
244
|
-
title: t("SharedDrive.sharedDriveModal.".concat(isUpdate ? 'updateTitle' : 'title')),
|
|
245
|
-
content: /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
246
|
-
className: "u-ph-2"
|
|
247
|
-
}, /*#__PURE__*/React.createElement(TextField, {
|
|
248
|
-
required: true,
|
|
249
|
-
label: t('SharedDrive.sharedDriveModal.nameLabel'),
|
|
250
|
-
variant: "outlined",
|
|
251
|
-
size: "small",
|
|
252
|
-
className: "u-w-100 u-mt-1-half",
|
|
253
|
-
value: sharedDriveName,
|
|
254
|
-
onChange: handleSharedDriveNameChange
|
|
255
|
-
}), /*#__PURE__*/React.createElement(Typography, {
|
|
256
|
-
variant: "h6",
|
|
257
|
-
className: "u-mt-1-half u-mb-half"
|
|
258
|
-
}, t('SharedDrive.sharedDriveModal.addPeople')), /*#__PURE__*/React.createElement(DumbShareByEmail, {
|
|
259
|
-
createContact: function createContact(contact) {
|
|
260
|
-
return client.create(Contact.doctype, contact);
|
|
261
|
-
},
|
|
262
|
-
currentRecipients: [],
|
|
263
|
-
document: document,
|
|
264
|
-
documentType: "Files",
|
|
265
|
-
onShare: onShare,
|
|
266
|
-
submitLabel: t('SharedDrive.sharedDriveModal.add'),
|
|
267
|
-
showNotifications: false
|
|
268
|
-
})), /*#__PURE__*/React.createElement(WhoHasAccess, {
|
|
269
|
-
isOwner: true,
|
|
270
|
-
recipients: recipients,
|
|
271
|
-
document: document,
|
|
272
|
-
documentType: "Files",
|
|
273
|
-
className: "u-w-100",
|
|
274
|
-
onRevoke: onRevoke,
|
|
275
|
-
onSetType: onSetType
|
|
276
|
-
})),
|
|
277
|
-
actions: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, {
|
|
278
|
-
variant: "secondary",
|
|
279
|
-
label: t('SharedDrive.sharedDriveModal.cancel'),
|
|
280
|
-
onClick: onClose
|
|
281
|
-
}), /*#__PURE__*/React.createElement(Button, {
|
|
282
|
-
variant: "primary",
|
|
283
|
-
label: t('SharedDrive.sharedDriveModal.update'),
|
|
284
|
-
onClick: onUpdate
|
|
285
|
-
}), /*#__PURE__*/React.createElement(Button, {
|
|
286
|
-
variant: "primary",
|
|
287
|
-
label: t('SharedDrive.sharedDriveModal.create'),
|
|
288
|
-
onClick: onCreate
|
|
289
|
-
}))
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
SharedDriveModal.propTypes = {
|
|
293
|
-
onClose: PropTypes.func.isRequired
|
|
294
|
-
};
|
|
295
|
-
/**
|
|
296
|
-
* Separates sharing members into recipients and read-only recipients
|
|
297
|
-
* @param {Array} members - Array of sharing members
|
|
298
|
-
* @returns {Object} Object containing recipients and readOnlyRecipients arrays
|
|
299
|
-
*/
|
|
300
|
-
|
|
301
|
-
var separateMembersByPermission = function separateMembersByPermission(members) {
|
|
302
|
-
return members.reduce(function (acc, member) {
|
|
303
|
-
if (member.status !== 'owner') {
|
|
304
|
-
if (member.read_only === true) {
|
|
305
|
-
acc.readOnlyRecipients.push(member);
|
|
306
|
-
} else {
|
|
307
|
-
acc.recipients.push(member);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
return acc;
|
|
312
|
-
}, {
|
|
313
|
-
recipients: [],
|
|
314
|
-
readOnlyRecipients: []
|
|
315
|
-
});
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
var associateToContacts = function associateToContacts(members, contacts) {
|
|
319
|
-
console.log('members', members);
|
|
320
|
-
console.log('contacts', contacts);
|
|
321
|
-
var result = [];
|
|
322
|
-
|
|
323
|
-
var _iterator = _createForOfIteratorHelper(members),
|
|
324
|
-
_step;
|
|
325
|
-
|
|
326
|
-
try {
|
|
327
|
-
var _loop = function _loop() {
|
|
328
|
-
var member = _step.value;
|
|
329
|
-
|
|
330
|
-
if (member.status !== 'owner' && member.email && member.instance) {
|
|
331
|
-
console.log('member', member);
|
|
332
|
-
var contact = contacts.find(function (c) {
|
|
333
|
-
var _c$email, _c$cozy;
|
|
334
|
-
|
|
335
|
-
return ((_c$email = c.email) === null || _c$email === void 0 ? void 0 : _c$email[0].address) === member.email && ((_c$cozy = c.cozy) === null || _c$cozy === void 0 || (_c$cozy = _c$cozy[0]) === null || _c$cozy === void 0 ? void 0 : _c$cozy.url) === member.instance;
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
if (contact) {
|
|
339
|
-
result.push(_objectSpread(_objectSpread({}, member), {}, {
|
|
340
|
-
_id: contact._id
|
|
341
|
-
}));
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
347
|
-
_loop();
|
|
348
|
-
}
|
|
349
|
-
} catch (err) {
|
|
350
|
-
_iterator.e(err);
|
|
351
|
-
} finally {
|
|
352
|
-
_iterator.f();
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
return result;
|
|
356
|
-
};
|