cozy-sharing 40.1.5 → 40.1.7
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 +8 -0
- package/dist/components/FederatedFolder/FederatedFolderModal.js +10 -12
- package/dist/components/Recipient/DowngradePermissionConfirmDialog.js +3 -12
- package/dist/components/Recipient/GroupRecipient.js +1 -4
- package/dist/components/Recipient/GroupRecipient.stories.js +3 -1
- package/dist/components/Recipient/GroupRecipientDetailWithAccess.js +1 -4
- package/dist/components/Recipient/GroupRecipientPermissions.js +5 -8
- package/dist/components/Recipient/GroupRecipientPermissions.stories.js +2 -0
- package/dist/components/Recipient/LinkRecipient.js +2 -6
- package/dist/components/Recipient/LinkRecipient.stories.js +4 -0
- package/dist/components/Recipient/LinkRecipientPermissions.js +13 -12
- package/dist/components/Recipient/LinkRecipientPermissions.stories.js +5 -1
- package/dist/components/Recipient/MemberRecipient.js +7 -6
- package/dist/components/Recipient/MemberRecipient.spec.js +7 -12
- package/dist/components/Recipient/MemberRecipientPermissions.js +28 -13
- package/dist/components/Recipient/MemberRecipientPermissions.spec.js +5 -14
- package/dist/components/Recipient/MemberRecipientPermissions.stories.js +2 -1
- package/dist/components/Recipient/OwnerRecipient.js +4 -17
- package/dist/components/Recipient/OwnerRecipient.stories.js +3 -1
- package/dist/components/Recipient/OwnerRecipientDefaultLite.js +1 -1
- package/dist/components/Recipient/PermissionTypeMenu.js +32 -155
- package/dist/components/Recipient/PermissionTypeMenuWrapper.js +37 -0
- package/dist/components/Recipient/{PermissionTypeMenu.spec.js → PermissionTypeMenuWrapper.spec.js} +2 -2
- package/dist/components/Recipient/RecipientList.js +10 -0
- package/dist/components/Recipient/RecipientList.stories.js +3 -0
- package/dist/components/ShareDialogCozyToCozy.js +20 -19
- package/dist/components/ShareDialogCozyToCozy.spec.js +3 -0
- package/dist/components/ShareDialogOnlyByLink.js +3 -5
- package/dist/components/ShareDialogOnlyByLink.spec.js +0 -1
- package/dist/components/ShareModal/SharingDetailsModal.js +2 -2
- package/dist/components/SharedDrive/EditSharedDriveModal.js +11 -10
- package/dist/components/SharedDrive/useSharedDrive.js +8 -11
- package/dist/components/SharingContent.js +3 -5
- package/dist/components/WhoHasAccess.js +27 -11
- package/dist/components/WhoHasAccessWrapper.js +122 -0
- package/dist/helpers/recipients.js +46 -0
- package/dist/helpers/recipients.spec.js +89 -0
- package/dist/hooks/useMemberPermissionType.js +191 -0
- package/dist/hooks/useResolveRecipients.js +53 -0
- package/dist/hooks/useResolveRecipients.spec.js +140 -0
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/src/components/FederatedFolder/FederatedFolderModal.jsx +6 -12
- package/src/components/Recipient/DowngradePermissionConfirmDialog.jsx +3 -10
- package/src/components/Recipient/GroupRecipient.jsx +1 -5
- package/src/components/Recipient/GroupRecipient.stories.jsx +3 -1
- package/src/components/Recipient/GroupRecipientDetailWithAccess.jsx +1 -4
- package/src/components/Recipient/GroupRecipientPermissions.jsx +5 -5
- package/src/components/Recipient/GroupRecipientPermissions.stories.jsx +2 -0
- package/src/components/Recipient/LinkRecipient.jsx +2 -4
- package/src/components/Recipient/LinkRecipient.stories.jsx +4 -0
- package/src/components/Recipient/LinkRecipientPermissions.jsx +16 -12
- package/src/components/Recipient/LinkRecipientPermissions.stories.jsx +5 -1
- package/src/components/Recipient/MemberRecipient.jsx +4 -4
- package/src/components/Recipient/MemberRecipient.spec.jsx +7 -10
- package/src/components/Recipient/MemberRecipientPermissions.jsx +29 -13
- package/src/components/Recipient/MemberRecipientPermissions.spec.jsx +5 -11
- package/src/components/Recipient/MemberRecipientPermissions.stories.jsx +2 -1
- package/src/components/Recipient/OwnerRecipient.jsx +4 -17
- package/src/components/Recipient/OwnerRecipient.stories.jsx +1 -1
- package/src/components/Recipient/OwnerRecipientDefaultLite.jsx +1 -1
- package/src/components/Recipient/PermissionTypeMenu.jsx +21 -81
- package/src/components/Recipient/PermissionTypeMenuWrapper.jsx +32 -0
- package/src/components/Recipient/{PermissionTypeMenu.spec.jsx → PermissionTypeMenuWrapper.spec.jsx} +2 -2
- package/src/components/Recipient/RecipientList.jsx +10 -0
- package/src/components/Recipient/RecipientList.stories.jsx +3 -0
- package/src/components/ShareDialogCozyToCozy.jsx +10 -11
- package/src/components/ShareDialogCozyToCozy.spec.jsx +1 -0
- package/src/components/ShareDialogOnlyByLink.jsx +2 -4
- package/src/components/ShareDialogOnlyByLink.spec.jsx +0 -1
- package/src/components/ShareModal/SharingDetailsModal.jsx +2 -2
- package/src/components/SharedDrive/EditSharedDriveModal.jsx +6 -11
- package/src/components/SharedDrive/useSharedDrive.js +4 -11
- package/src/components/SharingContent.jsx +2 -4
- package/src/components/WhoHasAccess.jsx +26 -12
- package/src/components/WhoHasAccessWrapper.jsx +117 -0
- package/src/helpers/recipients.js +44 -0
- package/src/helpers/recipients.spec.js +82 -0
- package/src/hooks/useMemberPermissionType.js +110 -0
- package/src/hooks/useResolveRecipients.js +38 -0
- package/src/hooks/useResolveRecipients.spec.js +70 -0
- package/src/index.jsx +1 -1
- package/dist/components/Recipient/OwnerRecipientDefault.js +0 -27
- package/dist/components/Recipient/OwnerRecipientDefault.stories.js +0 -10
- package/src/components/Recipient/OwnerRecipientDefault.jsx +0 -37
- package/src/components/Recipient/OwnerRecipientDefault.stories.jsx +0 -13
|
@@ -17,9 +17,9 @@ import Typography from 'cozy-ui/transpiled/react/Typography';
|
|
|
17
17
|
import { useSubmitWithLoader } from 'cozy-ui/transpiled/react/hooks/useSubmitWithLoader';
|
|
18
18
|
import { useI18n } from 'twake-i18n';
|
|
19
19
|
import SharedDriveHeader from './SharedDriveHeader';
|
|
20
|
-
import { getOrCreateFromArray } from '../../helpers/contacts';
|
|
21
20
|
import withLocales from '../../hoc/withLocales';
|
|
22
21
|
import { usePendingRecipients } from '../../hooks/usePendingRecipients';
|
|
22
|
+
import { useResolveRecipients } from '../../hooks/useResolveRecipients';
|
|
23
23
|
import { useSharingContext } from '../../hooks/useSharingContext';
|
|
24
24
|
var styles = {
|
|
25
25
|
"share-modal-content": "share__share-modal-content___1iqEq",
|
|
@@ -40,7 +40,7 @@ var styles = {
|
|
|
40
40
|
"aligned-dropdown-button": "share__aligned-dropdown-button___3crgG"
|
|
41
41
|
};
|
|
42
42
|
import { default as DumbShareByEmail } from '../ShareByEmail';
|
|
43
|
-
import
|
|
43
|
+
import WhoHasAccessWrapper from '../WhoHasAccessWrapper';
|
|
44
44
|
export var EditSharedDriveModal = withLocales(function (_ref) {
|
|
45
45
|
var onClose = _ref.onClose,
|
|
46
46
|
document = _ref.document;
|
|
@@ -64,6 +64,8 @@ export var EditSharedDriveModal = withLocales(function (_ref) {
|
|
|
64
64
|
onSubmit = _useSubmitWithLoader.onSubmit,
|
|
65
65
|
isLoading = _useSubmitWithLoader.isLoading;
|
|
66
66
|
|
|
67
|
+
var resolveRecipients = useResolveRecipients();
|
|
68
|
+
|
|
67
69
|
var _useState = useState(document.name),
|
|
68
70
|
_useState2 = _slicedToArray(_useState, 2),
|
|
69
71
|
driveName = _useState2[0],
|
|
@@ -71,19 +73,18 @@ export var EditSharedDriveModal = withLocales(function (_ref) {
|
|
|
71
73
|
|
|
72
74
|
var onSave = /*#__PURE__*/function () {
|
|
73
75
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
74
|
-
var
|
|
76
|
+
var _yield$resolveRecipie, readWriteRecipients, readOnlyRecipients;
|
|
77
|
+
|
|
75
78
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
76
79
|
while (1) switch (_context.prev = _context.next) {
|
|
77
80
|
case 0:
|
|
78
81
|
_context.next = 2;
|
|
79
|
-
return
|
|
80
|
-
return client.create('io.cozy.contacts', contact);
|
|
81
|
-
});
|
|
82
|
+
return resolveRecipients(pendingRecipients, selectedOption);
|
|
82
83
|
|
|
83
84
|
case 2:
|
|
84
|
-
|
|
85
|
-
readWriteRecipients =
|
|
86
|
-
readOnlyRecipients =
|
|
85
|
+
_yield$resolveRecipie = _context.sent;
|
|
86
|
+
readWriteRecipients = _yield$resolveRecipie.recipients;
|
|
87
|
+
readOnlyRecipients = _yield$resolveRecipie.readOnlyRecipients;
|
|
87
88
|
_context.next = 7;
|
|
88
89
|
return share({
|
|
89
90
|
document: document,
|
|
@@ -156,7 +157,7 @@ export var EditSharedDriveModal = withLocales(function (_ref) {
|
|
|
156
157
|
onPendingRecipientsChange: setPendingRecipients,
|
|
157
158
|
selectedOption: selectedOption,
|
|
158
159
|
onSelectedOptionChange: setSelectedOption
|
|
159
|
-
})), /*#__PURE__*/React.createElement(
|
|
160
|
+
})), /*#__PURE__*/React.createElement(WhoHasAccessWrapper, {
|
|
160
161
|
isOwner: true,
|
|
161
162
|
isSharedDrive: true,
|
|
162
163
|
showOwner: false,
|
|
@@ -3,11 +3,11 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
3
3
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
4
|
import { useState } from 'react';
|
|
5
5
|
import { useClient } from 'cozy-client';
|
|
6
|
-
import { getOrCreateFromArray } from '../../helpers/contacts';
|
|
7
6
|
import { usePendingRecipients } from '../../hooks/usePendingRecipients';
|
|
8
|
-
import {
|
|
7
|
+
import { useResolveRecipients } from '../../hooks/useResolveRecipients';
|
|
9
8
|
export var useSharedDrive = function useSharedDrive() {
|
|
10
9
|
var client = useClient();
|
|
10
|
+
var resolveRecipients = useResolveRecipients();
|
|
11
11
|
|
|
12
12
|
var _useState = useState(''),
|
|
13
13
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -24,23 +24,20 @@ export var useSharedDrive = function useSharedDrive() {
|
|
|
24
24
|
setSharedDriveName(event.target.value);
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
var createContact = function createContact(contact) {
|
|
28
|
-
return client.create(DOCTYPE_CONTACTS, contact);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
27
|
var onCreate = /*#__PURE__*/function () {
|
|
32
28
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
33
|
-
var
|
|
29
|
+
var _yield$resolveRecipie, readWriteRecipients, readOnlyRecipients;
|
|
30
|
+
|
|
34
31
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
35
32
|
while (1) switch (_context.prev = _context.next) {
|
|
36
33
|
case 0:
|
|
37
34
|
_context.next = 2;
|
|
38
|
-
return
|
|
35
|
+
return resolveRecipients(pendingRecipients, selectedOption);
|
|
39
36
|
|
|
40
37
|
case 2:
|
|
41
|
-
|
|
42
|
-
readWriteRecipients =
|
|
43
|
-
readOnlyRecipients =
|
|
38
|
+
_yield$resolveRecipie = _context.sent;
|
|
39
|
+
readWriteRecipients = _yield$resolveRecipie.recipients;
|
|
40
|
+
readOnlyRecipients = _yield$resolveRecipie.readOnlyRecipients;
|
|
44
41
|
_context.next = 7;
|
|
45
42
|
return client.collection('io.cozy.sharings').createSharedDrive({
|
|
46
43
|
name: sharedDriveName,
|
|
@@ -5,7 +5,7 @@ import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints';
|
|
|
5
5
|
import { useI18n } from 'twake-i18n';
|
|
6
6
|
import AntivirusAlert from './AntivirusAlert';
|
|
7
7
|
import { default as DumbShareByEmail } from './ShareByEmail';
|
|
8
|
-
import
|
|
8
|
+
import WhoHasAccessWrapper from './WhoHasAccessWrapper';
|
|
9
9
|
var styles = {
|
|
10
10
|
"share-modal-content": "share__share-modal-content___1iqEq",
|
|
11
11
|
"coz-form": "share__coz-form___1ICST",
|
|
@@ -40,7 +40,6 @@ var SharingContent = function SharingContent(_ref) {
|
|
|
40
40
|
recipientsToBeConfirmed = _ref.recipientsToBeConfirmed,
|
|
41
41
|
verifyRecipient = _ref.verifyRecipient,
|
|
42
42
|
link = _ref.link,
|
|
43
|
-
permissions = _ref.permissions,
|
|
44
43
|
pendingRecipients = _ref.pendingRecipients,
|
|
45
44
|
onPendingRecipientsChange = _ref.onPendingRecipientsChange,
|
|
46
45
|
selectedOption = _ref.selectedOption,
|
|
@@ -75,7 +74,7 @@ var SharingContent = function SharingContent(_ref) {
|
|
|
75
74
|
selectedOption: selectedOption,
|
|
76
75
|
onSelectedOptionChange: onSelectedOptionChange,
|
|
77
76
|
enableCreateContact: true
|
|
78
|
-
})), showWhoHasAccess && /*#__PURE__*/React.createElement(
|
|
77
|
+
})), showWhoHasAccess && /*#__PURE__*/React.createElement(WhoHasAccessWrapper, {
|
|
79
78
|
document: document,
|
|
80
79
|
documentType: documentType,
|
|
81
80
|
isOwner: isOwner,
|
|
@@ -84,8 +83,7 @@ var SharingContent = function SharingContent(_ref) {
|
|
|
84
83
|
recipients: recipients,
|
|
85
84
|
recipientsToBeConfirmed: recipientsToBeConfirmed,
|
|
86
85
|
verifyRecipient: verifyRecipient,
|
|
87
|
-
link: link
|
|
88
|
-
permissions: permissions
|
|
86
|
+
link: link
|
|
89
87
|
}));
|
|
90
88
|
};
|
|
91
89
|
|
|
@@ -6,7 +6,6 @@ import LinkRecipient from './Recipient/LinkRecipient';
|
|
|
6
6
|
import OwnerRecipient from './Recipient/OwnerRecipient';
|
|
7
7
|
import { RecipientList } from './Recipient/RecipientList';
|
|
8
8
|
import { usePrevious } from '../helpers/hooks';
|
|
9
|
-
import { useSharingContext } from '../hooks/useSharingContext';
|
|
10
9
|
/**
|
|
11
10
|
* Displays a warning if some contacts are waiting for confirmation of their sharing
|
|
12
11
|
*
|
|
@@ -43,6 +42,10 @@ var WhoHasAccess = function WhoHasAccess(_ref2) {
|
|
|
43
42
|
canManageLink = _ref2$canManageLink === void 0 ? canManageMembers : _ref2$canManageLink,
|
|
44
43
|
_ref2$showOwner = _ref2.showOwner,
|
|
45
44
|
showOwner = _ref2$showOwner === void 0 ? true : _ref2$showOwner,
|
|
45
|
+
owner = _ref2.owner,
|
|
46
|
+
_ref2$isInsideSharedP = _ref2.isInsideSharedParent,
|
|
47
|
+
isInsideSharedParent = _ref2$isInsideSharedP === void 0 ? false : _ref2$isInsideSharedP,
|
|
48
|
+
sharedParentName = _ref2.sharedParentName,
|
|
46
49
|
recipients = _ref2.recipients,
|
|
47
50
|
_ref2$recipientsToBeC = _ref2.recipientsToBeConfirmed,
|
|
48
51
|
recipientsToBeConfirmed = _ref2$recipientsToBeC === void 0 ? [] : _ref2$recipientsToBeC,
|
|
@@ -51,17 +54,16 @@ var WhoHasAccess = function WhoHasAccess(_ref2) {
|
|
|
51
54
|
className = _ref2.className,
|
|
52
55
|
onRevoke = _ref2.onRevoke,
|
|
53
56
|
onRevokeSelf = _ref2.onRevokeSelf,
|
|
54
|
-
|
|
57
|
+
onRevokeGroup = _ref2.onRevokeGroup,
|
|
58
|
+
onLeaveGroup = _ref2.onLeaveGroup,
|
|
59
|
+
onSetMemberType = _ref2.onSetMemberType,
|
|
60
|
+
onUpdateLinkPermissions = _ref2.onUpdateLinkPermissions,
|
|
61
|
+
onRevokeLink = _ref2.onRevokeLink,
|
|
55
62
|
verifyRecipient = _ref2.verifyRecipient,
|
|
56
63
|
link = _ref2.link,
|
|
57
64
|
permissions = _ref2.permissions;
|
|
58
65
|
var previousLink = usePrevious(link);
|
|
59
66
|
var linkHasBeenJustCreated = link && previousLink === null;
|
|
60
|
-
|
|
61
|
-
var _useSharingContext = useSharingContext(),
|
|
62
|
-
isOrgSharedDrive = _useSharingContext.isOrgSharedDrive;
|
|
63
|
-
|
|
64
|
-
var isOrgDrive = isOrgSharedDrive(document === null || document === void 0 ? void 0 : document._id);
|
|
65
67
|
return /*#__PURE__*/React.createElement("div", {
|
|
66
68
|
className: className
|
|
67
69
|
}, /*#__PURE__*/React.createElement(RecipientWaitingForConfirmationAlert, {
|
|
@@ -73,10 +75,11 @@ var WhoHasAccess = function WhoHasAccess(_ref2) {
|
|
|
73
75
|
onRevoke: onRevoke,
|
|
74
76
|
onRevokeSelf: onRevokeSelf,
|
|
75
77
|
permissions: permissions,
|
|
78
|
+
onUpdateLinkPermissions: onUpdateLinkPermissions,
|
|
79
|
+
onRevokeLink: onRevokeLink,
|
|
76
80
|
fadeIn: linkHasBeenJustCreated
|
|
77
81
|
}), showOwner && /*#__PURE__*/React.createElement(OwnerRecipient, {
|
|
78
|
-
|
|
79
|
-
isOrgSharedDrive: isOrgDrive
|
|
82
|
+
owner: owner
|
|
80
83
|
}), /*#__PURE__*/React.createElement(RecipientList, {
|
|
81
84
|
recipients: recipients,
|
|
82
85
|
recipientsToBeConfirmed: recipientsToBeConfirmed,
|
|
@@ -86,9 +89,13 @@ var WhoHasAccess = function WhoHasAccess(_ref2) {
|
|
|
86
89
|
isSharedDrive: isSharedDrive,
|
|
87
90
|
document: document,
|
|
88
91
|
documentType: documentType,
|
|
92
|
+
isInsideSharedParent: isInsideSharedParent,
|
|
93
|
+
sharedParentName: sharedParentName,
|
|
89
94
|
onRevoke: onRevoke,
|
|
90
95
|
onRevokeSelf: onRevokeSelf,
|
|
91
|
-
|
|
96
|
+
onRevokeGroup: onRevokeGroup,
|
|
97
|
+
onLeaveGroup: onLeaveGroup,
|
|
98
|
+
onSetMemberType: onSetMemberType,
|
|
92
99
|
verifyRecipient: verifyRecipient
|
|
93
100
|
})));
|
|
94
101
|
};
|
|
@@ -99,6 +106,9 @@ WhoHasAccess.propTypes = {
|
|
|
99
106
|
canManageMembers: PropTypes.bool,
|
|
100
107
|
canManageLink: PropTypes.bool,
|
|
101
108
|
showOwner: PropTypes.bool,
|
|
109
|
+
owner: PropTypes.object,
|
|
110
|
+
isInsideSharedParent: PropTypes.bool,
|
|
111
|
+
sharedParentName: PropTypes.string,
|
|
102
112
|
recipients: PropTypes.array.isRequired,
|
|
103
113
|
recipientsToBeConfirmed: PropTypes.arrayOf(PropTypes.shape({
|
|
104
114
|
email: PropTypes.string.isRequired
|
|
@@ -107,6 +117,12 @@ WhoHasAccess.propTypes = {
|
|
|
107
117
|
documentType: PropTypes.string.isRequired,
|
|
108
118
|
onRevoke: PropTypes.func.isRequired,
|
|
109
119
|
onRevokeSelf: PropTypes.func,
|
|
110
|
-
|
|
120
|
+
onRevokeGroup: PropTypes.func.isRequired,
|
|
121
|
+
onLeaveGroup: PropTypes.func.isRequired,
|
|
122
|
+
onSetMemberType: PropTypes.func.isRequired,
|
|
123
|
+
onUpdateLinkPermissions: PropTypes.func.isRequired,
|
|
124
|
+
onRevokeLink: PropTypes.func.isRequired,
|
|
125
|
+
verifyRecipient: PropTypes.func,
|
|
126
|
+
permissions: PropTypes.arrayOf(PropTypes.object)
|
|
111
127
|
};
|
|
112
128
|
export default WhoHasAccess;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
|
|
3
|
+
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; }
|
|
4
|
+
|
|
5
|
+
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; }
|
|
6
|
+
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { useClient, useQuery, hasQueryBeenLoaded } from 'cozy-client';
|
|
9
|
+
import WhoHasAccess from './WhoHasAccess';
|
|
10
|
+
import { hasMemberActions, markCurrentUser } from '../helpers/recipients';
|
|
11
|
+
import { useMemberPermissionType } from '../hooks/useMemberPermissionType';
|
|
12
|
+
import { useSharingContext } from '../hooks/useSharingContext';
|
|
13
|
+
import { buildInstanceSettingsQuery } from '../queries/queries'; // When the owner is not part of a sharing's members (eg. the folder only has
|
|
14
|
+
// a link), there is no per-sharing avatar to reference. The instance's public
|
|
15
|
+
// avatar still holds the owner's picture. fallback=initials makes the stack
|
|
16
|
+
// serve a generated initials avatar (instead of the app icon) when no picture
|
|
17
|
+
// has been uploaded, matching how avatars are rendered everywhere else.
|
|
18
|
+
|
|
19
|
+
var OWNER_PUBLIC_AVATAR_PATH = '/public/avatar?fallback=initials';
|
|
20
|
+
|
|
21
|
+
var WhoHasAccessWrapper = function WhoHasAccessWrapper(_ref) {
|
|
22
|
+
var _instanceSettingsResu;
|
|
23
|
+
|
|
24
|
+
var _ref$isOwner = _ref.isOwner,
|
|
25
|
+
isOwner = _ref$isOwner === void 0 ? false : _ref$isOwner,
|
|
26
|
+
_ref$canManageSharing = _ref.canManageSharing,
|
|
27
|
+
canManageSharing = _ref$canManageSharing === void 0 ? isOwner : _ref$canManageSharing,
|
|
28
|
+
isSharedDrive = _ref.isSharedDrive,
|
|
29
|
+
isReadOnly = _ref.isReadOnly,
|
|
30
|
+
_ref$canManageMembers = _ref.canManageMembers,
|
|
31
|
+
canManageMembers = _ref$canManageMembers === void 0 ? !isReadOnly : _ref$canManageMembers,
|
|
32
|
+
canManageLink = _ref.canManageLink,
|
|
33
|
+
_ref$showOwner = _ref.showOwner,
|
|
34
|
+
showOwner = _ref$showOwner === void 0 ? true : _ref$showOwner,
|
|
35
|
+
recipients = _ref.recipients,
|
|
36
|
+
_ref$recipientsToBeCo = _ref.recipientsToBeConfirmed,
|
|
37
|
+
recipientsToBeConfirmed = _ref$recipientsToBeCo === void 0 ? [] : _ref$recipientsToBeCo,
|
|
38
|
+
document = _ref.document,
|
|
39
|
+
documentType = _ref.documentType,
|
|
40
|
+
className = _ref.className,
|
|
41
|
+
onRevoke = _ref.onRevoke,
|
|
42
|
+
onRevokeSelf = _ref.onRevokeSelf,
|
|
43
|
+
verifyRecipient = _ref.verifyRecipient,
|
|
44
|
+
link = _ref.link;
|
|
45
|
+
var client = useClient();
|
|
46
|
+
|
|
47
|
+
var _useSharingContext = useSharingContext(),
|
|
48
|
+
isOrgSharedDrive = _useSharingContext.isOrgSharedDrive,
|
|
49
|
+
getDocumentPermissions = _useSharingContext.getDocumentPermissions,
|
|
50
|
+
updateDocumentPermissions = _useSharingContext.updateDocumentPermissions,
|
|
51
|
+
revokeSharingLink = _useSharingContext.revokeSharingLink,
|
|
52
|
+
revokeGroup = _useSharingContext.revokeGroup,
|
|
53
|
+
revokeSelf = _useSharingContext.revokeSelf;
|
|
54
|
+
|
|
55
|
+
var instanceUri = client.options.uri;
|
|
56
|
+
var markedRecipients = markCurrentUser(recipients, instanceUri);
|
|
57
|
+
var hasMemberMenus = markedRecipients.some(function (recipient) {
|
|
58
|
+
return !recipient.members && !recipientsToBeConfirmed.some(function (user) {
|
|
59
|
+
return user.email === recipient.email;
|
|
60
|
+
}) && hasMemberActions({
|
|
61
|
+
status: recipient.status,
|
|
62
|
+
isCurrentUser: recipient.isCurrentUser,
|
|
63
|
+
isOwner: isOwner,
|
|
64
|
+
canManageSharing: canManageSharing,
|
|
65
|
+
canManageMembers: canManageMembers
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
var _useMemberPermissionT = useMemberPermissionType(document, {
|
|
70
|
+
shouldFetchPath: hasMemberMenus
|
|
71
|
+
}),
|
|
72
|
+
isInsideSharedParent = _useMemberPermissionT.isInsideSharedParent,
|
|
73
|
+
sharedParentName = _useMemberPermissionT.sharedParentName,
|
|
74
|
+
setMemberType = _useMemberPermissionT.setMemberType;
|
|
75
|
+
|
|
76
|
+
var ownerRecipient = markedRecipients.find(function (recipient) {
|
|
77
|
+
return recipient.status === 'owner';
|
|
78
|
+
});
|
|
79
|
+
var instanceSettingsQuery = buildInstanceSettingsQuery();
|
|
80
|
+
var instanceSettingsResult = useQuery(instanceSettingsQuery.definition, _objectSpread(_objectSpread({}, instanceSettingsQuery.options), {}, {
|
|
81
|
+
enabled: showOwner && !ownerRecipient
|
|
82
|
+
}));
|
|
83
|
+
var defaultOwner = hasQueryBeenLoaded(instanceSettingsResult) ? {
|
|
84
|
+
isOwner: true,
|
|
85
|
+
status: 'owner',
|
|
86
|
+
instance: instanceUri,
|
|
87
|
+
avatarPath: OWNER_PUBLIC_AVATAR_PATH,
|
|
88
|
+
public_name: (_instanceSettingsResu = instanceSettingsResult.data) === null || _instanceSettingsResu === void 0 || (_instanceSettingsResu = _instanceSettingsResu.attributes) === null || _instanceSettingsResu === void 0 ? void 0 : _instanceSettingsResu.public_name
|
|
89
|
+
} : null;
|
|
90
|
+
var owner = ownerRecipient ? _objectSpread(_objectSpread({}, ownerRecipient), {}, {
|
|
91
|
+
isOrgSharedDrive: isOrgSharedDrive(document === null || document === void 0 ? void 0 : document._id)
|
|
92
|
+
}) : defaultOwner;
|
|
93
|
+
return /*#__PURE__*/React.createElement(WhoHasAccess, {
|
|
94
|
+
isOwner: isOwner,
|
|
95
|
+
canManageSharing: canManageSharing,
|
|
96
|
+
isSharedDrive: isSharedDrive,
|
|
97
|
+
isReadOnly: isReadOnly,
|
|
98
|
+
canManageMembers: canManageMembers,
|
|
99
|
+
canManageLink: canManageLink,
|
|
100
|
+
showOwner: showOwner,
|
|
101
|
+
owner: owner,
|
|
102
|
+
isInsideSharedParent: isInsideSharedParent,
|
|
103
|
+
sharedParentName: sharedParentName,
|
|
104
|
+
recipients: markedRecipients,
|
|
105
|
+
recipientsToBeConfirmed: recipientsToBeConfirmed,
|
|
106
|
+
document: document,
|
|
107
|
+
documentType: documentType,
|
|
108
|
+
className: className,
|
|
109
|
+
onRevoke: onRevoke,
|
|
110
|
+
onRevokeSelf: onRevokeSelf,
|
|
111
|
+
onRevokeGroup: revokeGroup,
|
|
112
|
+
onLeaveGroup: revokeSelf,
|
|
113
|
+
onSetMemberType: setMemberType,
|
|
114
|
+
onUpdateLinkPermissions: updateDocumentPermissions,
|
|
115
|
+
onRevokeLink: revokeSharingLink,
|
|
116
|
+
verifyRecipient: verifyRecipient,
|
|
117
|
+
link: link,
|
|
118
|
+
permissions: getDocumentPermissions(document === null || document === void 0 ? void 0 : document._id)
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export default WhoHasAccessWrapper;
|
|
@@ -95,4 +95,50 @@ export var getGroupRecipientSecondaryText = function getGroupRecipientSecondaryT
|
|
|
95
95
|
smart_count: nbMember
|
|
96
96
|
});
|
|
97
97
|
return secondary + (isUserInsideMembers ? " (".concat(t('GroupRecipient.secondary_you'), ")") : '');
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
var isInstance = function isInstance(recipient, instanceUri) {
|
|
101
|
+
return recipient.instance !== undefined && recipient.instance === instanceUri;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Flags with `isCurrentUser` the recipients, and the members of group
|
|
105
|
+
* recipients, whose instance is the current user's one
|
|
106
|
+
*
|
|
107
|
+
* @param {object[]} recipients - Recipients of a sharing
|
|
108
|
+
* @param {string} instanceUri - URI of the current user's instance
|
|
109
|
+
* @returns {object[]} The recipients with their `isCurrentUser` flag
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
export var markCurrentUser = function markCurrentUser(recipients, instanceUri) {
|
|
114
|
+
return recipients.map(function (recipient) {
|
|
115
|
+
return _objectSpread(_objectSpread({}, recipient), {}, {
|
|
116
|
+
isCurrentUser: isInstance(recipient, instanceUri)
|
|
117
|
+
}, recipient.members && {
|
|
118
|
+
members: recipient.members.map(function (member) {
|
|
119
|
+
return _objectSpread(_objectSpread({}, member), {}, {
|
|
120
|
+
isCurrentUser: isInstance(member, instanceUri)
|
|
121
|
+
});
|
|
122
|
+
})
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* @param {object} params
|
|
128
|
+
* @param {string} params.status - Status of the member in the sharing
|
|
129
|
+
* @param {boolean} params.isCurrentUser - Whether the member is the current user
|
|
130
|
+
* @param {boolean} params.isOwner - Whether the current user owns the sharing
|
|
131
|
+
* @param {boolean} params.canManageSharing - Whether the current user can manage the sharing
|
|
132
|
+
* @param {boolean} params.canManageMembers - Whether the members can be managed
|
|
133
|
+
* @returns {boolean} Whether the current user can change the member's
|
|
134
|
+
* permission type or revoke them
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
export var hasMemberActions = function hasMemberActions(_ref2) {
|
|
138
|
+
var status = _ref2.status,
|
|
139
|
+
isCurrentUser = _ref2.isCurrentUser,
|
|
140
|
+
isOwner = _ref2.isOwner,
|
|
141
|
+
canManageSharing = _ref2.canManageSharing,
|
|
142
|
+
canManageMembers = _ref2.canManageMembers;
|
|
143
|
+
return canManageMembers && status !== 'owner' && (isCurrentUser && !isOwner || canManageSharing);
|
|
98
144
|
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
|
|
4
|
+
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; }
|
|
5
|
+
|
|
6
|
+
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; }
|
|
7
|
+
|
|
8
|
+
import { hasMemberActions, markCurrentUser } from './recipients';
|
|
9
|
+
var instanceUri = 'https://alice.cozy.cc';
|
|
10
|
+
describe('markCurrentUser', function () {
|
|
11
|
+
it('flags the recipient whose instance is the current one', function () {
|
|
12
|
+
var recipients = [{
|
|
13
|
+
email: 'alice@cozy.cc',
|
|
14
|
+
instance: instanceUri
|
|
15
|
+
}, {
|
|
16
|
+
email: 'bob@cozy.cc',
|
|
17
|
+
instance: 'https://bob.cozy.cc'
|
|
18
|
+
}, {
|
|
19
|
+
email: 'carol@cozy.cc'
|
|
20
|
+
}];
|
|
21
|
+
expect(markCurrentUser(recipients, instanceUri).map(function (r) {
|
|
22
|
+
return r.isCurrentUser;
|
|
23
|
+
})).toEqual([true, false, false]);
|
|
24
|
+
});
|
|
25
|
+
it('does not flag a recipient without instance when the instance is unknown', function () {
|
|
26
|
+
expect(markCurrentUser([{
|
|
27
|
+
email: 'carol@cozy.cc'
|
|
28
|
+
}], undefined)).toEqual([{
|
|
29
|
+
email: 'carol@cozy.cc',
|
|
30
|
+
isCurrentUser: false
|
|
31
|
+
}]);
|
|
32
|
+
});
|
|
33
|
+
it('flags the members of group recipients', function () {
|
|
34
|
+
var recipients = [{
|
|
35
|
+
name: 'Team',
|
|
36
|
+
members: [{
|
|
37
|
+
instance: 'https://bob.cozy.cc'
|
|
38
|
+
}, {
|
|
39
|
+
instance: instanceUri
|
|
40
|
+
}]
|
|
41
|
+
}];
|
|
42
|
+
|
|
43
|
+
var _markCurrentUser = markCurrentUser(recipients, instanceUri),
|
|
44
|
+
_markCurrentUser2 = _slicedToArray(_markCurrentUser, 1),
|
|
45
|
+
group = _markCurrentUser2[0];
|
|
46
|
+
|
|
47
|
+
expect(group.isCurrentUser).toBe(false);
|
|
48
|
+
expect(group.members.map(function (m) {
|
|
49
|
+
return m.isCurrentUser;
|
|
50
|
+
})).toEqual([false, true]);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
describe('hasMemberActions', function () {
|
|
54
|
+
var ownerRights = {
|
|
55
|
+
isOwner: true,
|
|
56
|
+
canManageSharing: true,
|
|
57
|
+
canManageMembers: true
|
|
58
|
+
};
|
|
59
|
+
var memberRights = {
|
|
60
|
+
isOwner: false,
|
|
61
|
+
canManageSharing: false,
|
|
62
|
+
canManageMembers: true
|
|
63
|
+
};
|
|
64
|
+
it('gives actions on the members to whom can manage the sharing', function () {
|
|
65
|
+
expect(hasMemberActions(_objectSpread(_objectSpread({}, ownerRights), {}, {
|
|
66
|
+
status: 'ready'
|
|
67
|
+
}))).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
it('gives no action on the owner', function () {
|
|
70
|
+
expect(hasMemberActions(_objectSpread(_objectSpread({}, ownerRights), {}, {
|
|
71
|
+
status: 'owner'
|
|
72
|
+
}))).toBe(false);
|
|
73
|
+
});
|
|
74
|
+
it('gives no action when the members cannot be managed', function () {
|
|
75
|
+
expect(hasMemberActions(_objectSpread(_objectSpread({}, ownerRights), {}, {
|
|
76
|
+
canManageMembers: false,
|
|
77
|
+
status: 'ready'
|
|
78
|
+
}))).toBe(false);
|
|
79
|
+
});
|
|
80
|
+
it('gives actions on themselves to a member who cannot manage the sharing', function () {
|
|
81
|
+
expect(hasMemberActions(_objectSpread(_objectSpread({}, memberRights), {}, {
|
|
82
|
+
status: 'ready',
|
|
83
|
+
isCurrentUser: true
|
|
84
|
+
}))).toBe(true);
|
|
85
|
+
expect(hasMemberActions(_objectSpread(_objectSpread({}, memberRights), {}, {
|
|
86
|
+
status: 'ready'
|
|
87
|
+
}))).toBe(false);
|
|
88
|
+
});
|
|
89
|
+
});
|