cozy-sharing 6.0.6 → 7.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 +16 -0
- package/dist/getSharedDocument.js +14 -5
- package/dist/getSharedDocument.spec.js +81 -10
- package/dist/state.js +2 -6
- package/package.json +2 -2
- package/src/getSharedDocument.js +13 -5
- package/src/getSharedDocument.spec.js +26 -5
- package/src/state.js +2 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [7.0.0](https://github.com/cozy/cozy-libs/compare/cozy-sharing@6.0.6...cozy-sharing@7.0.0) (2023-03-16)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Return also readOnly status from getSharedDocument ([c68ba61](https://github.com/cozy/cozy-libs/commit/c68ba61b69dfd2b152e47252005f294fee818110))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### BREAKING CHANGES
|
|
15
|
+
|
|
16
|
+
* The function now returns the id encapsulated in an object. You can extract the id like this `const { id } = getSharedDocument(client)`
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
## 6.0.6 (2023-03-16)
|
|
7
23
|
|
|
8
24
|
**Note:** Version bump only for package cozy-sharing
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
2
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
-
import
|
|
3
|
+
import { isReadOnly } from 'cozy-client/dist/models/permission';
|
|
4
|
+
/**
|
|
5
|
+
* Get the first shared document for the current shared token
|
|
6
|
+
*
|
|
7
|
+
* @param {CozyClient} client
|
|
8
|
+
* @returns {{id, isReadOnly}} id of the document and the readOnly status
|
|
9
|
+
*/
|
|
4
10
|
|
|
5
11
|
var getSharedDocument = /*#__PURE__*/function () {
|
|
6
12
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(client) {
|
|
7
|
-
var _yield$client$collect, permissionsData, permissions,
|
|
13
|
+
var _yield$client$collect, permissionsData, permissions, perm;
|
|
8
14
|
|
|
9
15
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
10
16
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -15,10 +21,13 @@ var getSharedDocument = /*#__PURE__*/function () {
|
|
|
15
21
|
case 2:
|
|
16
22
|
_yield$client$collect = _context.sent;
|
|
17
23
|
permissionsData = _yield$client$collect.data;
|
|
18
|
-
permissions = permissionsData.attributes.permissions; // permissions contains several named keys, but the one to use depends on the situation. Using the first one is what we want in all known cases.
|
|
24
|
+
permissions = Object.values(permissionsData.attributes.permissions); // permissions contains several named keys, but the one to use depends on the situation. Using the first one is what we want in all known cases.
|
|
19
25
|
|
|
20
|
-
|
|
21
|
-
return _context.abrupt("return",
|
|
26
|
+
perm = permissions[0];
|
|
27
|
+
return _context.abrupt("return", {
|
|
28
|
+
id: perm.values[0],
|
|
29
|
+
isReadOnly: isReadOnly(perm)
|
|
30
|
+
});
|
|
22
31
|
|
|
23
32
|
case 7:
|
|
24
33
|
case "end":
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
2
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
3
|
import getSharedDocument from './getSharedDocument';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
function setupClient() {
|
|
6
|
+
var verbs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
7
|
+
return {
|
|
6
8
|
collection: function collection() {
|
|
7
9
|
return {
|
|
8
10
|
getOwnPermissions: jest.fn().mockReturnValue({
|
|
@@ -11,14 +13,14 @@ describe('Getting the shared document id', function () {
|
|
|
11
13
|
permissions: {
|
|
12
14
|
collection: {
|
|
13
15
|
type: 'io.cozy.photos.albums',
|
|
14
|
-
verbs:
|
|
16
|
+
verbs: verbs,
|
|
15
17
|
values: ['myshareid']
|
|
16
18
|
},
|
|
17
19
|
files: {
|
|
18
20
|
selector: 'referenced_by',
|
|
19
21
|
type: 'io.cozy.files',
|
|
20
22
|
values: ['io.cozy.photos.albums/myshareid'],
|
|
21
|
-
verbs:
|
|
23
|
+
verbs: verbs
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
}
|
|
@@ -27,22 +29,91 @@ describe('Getting the shared document id', function () {
|
|
|
27
29
|
};
|
|
28
30
|
}
|
|
29
31
|
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe('Getting the shared document', function () {
|
|
30
35
|
it('should get the id', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
31
|
-
var id;
|
|
36
|
+
var client, _yield$getSharedDocum, id;
|
|
37
|
+
|
|
32
38
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
33
39
|
while (1) switch (_context.prev = _context.next) {
|
|
34
40
|
case 0:
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
client = setupClient(['GET']);
|
|
42
|
+
_context.next = 3;
|
|
43
|
+
return getSharedDocument(client);
|
|
37
44
|
|
|
38
|
-
case
|
|
39
|
-
|
|
45
|
+
case 3:
|
|
46
|
+
_yield$getSharedDocum = _context.sent;
|
|
47
|
+
id = _yield$getSharedDocum.id;
|
|
40
48
|
expect(id).toEqual('myshareid');
|
|
41
49
|
|
|
42
|
-
case
|
|
50
|
+
case 6:
|
|
43
51
|
case "end":
|
|
44
52
|
return _context.stop();
|
|
45
53
|
}
|
|
46
54
|
}, _callee);
|
|
47
55
|
})));
|
|
56
|
+
it('should return isReadOnly is true when we have only a GET permission', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
57
|
+
var client, _yield$getSharedDocum2, isReadOnly;
|
|
58
|
+
|
|
59
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
60
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
61
|
+
case 0:
|
|
62
|
+
client = setupClient(['GET']);
|
|
63
|
+
_context2.next = 3;
|
|
64
|
+
return getSharedDocument(client);
|
|
65
|
+
|
|
66
|
+
case 3:
|
|
67
|
+
_yield$getSharedDocum2 = _context2.sent;
|
|
68
|
+
isReadOnly = _yield$getSharedDocum2.isReadOnly;
|
|
69
|
+
expect(isReadOnly).toBeTruthy();
|
|
70
|
+
|
|
71
|
+
case 6:
|
|
72
|
+
case "end":
|
|
73
|
+
return _context2.stop();
|
|
74
|
+
}
|
|
75
|
+
}, _callee2);
|
|
76
|
+
})));
|
|
77
|
+
it('should return isReadOnly is false when we have an ALL permission', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
78
|
+
var client, _yield$getSharedDocum3, isReadOnly;
|
|
79
|
+
|
|
80
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
81
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
82
|
+
case 0:
|
|
83
|
+
client = setupClient(['ALL']);
|
|
84
|
+
_context3.next = 3;
|
|
85
|
+
return getSharedDocument(client);
|
|
86
|
+
|
|
87
|
+
case 3:
|
|
88
|
+
_yield$getSharedDocum3 = _context3.sent;
|
|
89
|
+
isReadOnly = _yield$getSharedDocum3.isReadOnly;
|
|
90
|
+
expect(isReadOnly).toBeFalsy();
|
|
91
|
+
|
|
92
|
+
case 6:
|
|
93
|
+
case "end":
|
|
94
|
+
return _context3.stop();
|
|
95
|
+
}
|
|
96
|
+
}, _callee3);
|
|
97
|
+
})));
|
|
98
|
+
it('should return isReadOnly is false when we have a PATCH permission', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
|
99
|
+
var client, _yield$getSharedDocum4, isReadOnly;
|
|
100
|
+
|
|
101
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
102
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
103
|
+
case 0:
|
|
104
|
+
client = setupClient(['GET', 'PATCH', 'PUT']);
|
|
105
|
+
_context4.next = 3;
|
|
106
|
+
return getSharedDocument(client);
|
|
107
|
+
|
|
108
|
+
case 3:
|
|
109
|
+
_yield$getSharedDocum4 = _context4.sent;
|
|
110
|
+
isReadOnly = _yield$getSharedDocum4.isReadOnly;
|
|
111
|
+
expect(isReadOnly).toBeFalsy();
|
|
112
|
+
|
|
113
|
+
case 6:
|
|
114
|
+
case "end":
|
|
115
|
+
return _context4.stop();
|
|
116
|
+
}
|
|
117
|
+
}, _callee4);
|
|
118
|
+
})));
|
|
48
119
|
});
|
package/dist/state.js
CHANGED
|
@@ -461,9 +461,7 @@ var getApps = function getApps(state) {
|
|
|
461
461
|
|
|
462
462
|
export var hasSharedParent = function hasSharedParent(state, documentPath) {
|
|
463
463
|
if (!state.sharedPaths) {
|
|
464
|
-
//
|
|
465
|
-
console.log('hasSharedParent should not occur', state, documentPath);
|
|
466
|
-
return false;
|
|
464
|
+
return false; // hasSharedParent should not occur
|
|
467
465
|
}
|
|
468
466
|
|
|
469
467
|
return state.sharedPaths.some(function (path) {
|
|
@@ -472,9 +470,7 @@ export var hasSharedParent = function hasSharedParent(state, documentPath) {
|
|
|
472
470
|
};
|
|
473
471
|
export var hasSharedChild = function hasSharedChild(state, documentPath) {
|
|
474
472
|
if (!state.sharedPaths) {
|
|
475
|
-
//
|
|
476
|
-
console.log('hasSharedChild should not occur', state, documentPath);
|
|
477
|
-
return false;
|
|
473
|
+
return false; // hasSharedChild should not occur
|
|
478
474
|
}
|
|
479
475
|
|
|
480
476
|
var ret = state.sharedPaths.some(function (path) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-sharing",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Provides sharing login for React applications.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "Cozy",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"sideEffects": [
|
|
62
62
|
"*.css"
|
|
63
63
|
],
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "b623a595cc50731ff2bf2db93f0533cf1553530a"
|
|
65
65
|
}
|
package/src/getSharedDocument.js
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { isReadOnly } from 'cozy-client/dist/models/permission'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Get the first shared document for the current shared token
|
|
5
|
+
*
|
|
6
|
+
* @param {CozyClient} client
|
|
7
|
+
* @returns {{id, isReadOnly}} id of the document and the readOnly status
|
|
8
|
+
*/
|
|
3
9
|
const getSharedDocument = async client => {
|
|
4
10
|
const { data: permissionsData } = await client
|
|
5
11
|
.collection('io.cozy.permissions')
|
|
6
12
|
.getOwnPermissions()
|
|
7
13
|
|
|
8
|
-
const permissions = permissionsData.attributes.permissions
|
|
14
|
+
const permissions = Object.values(permissionsData.attributes.permissions)
|
|
9
15
|
// permissions contains several named keys, but the one to use depends on the situation. Using the first one is what we want in all known cases.
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
const perm = permissions[0]
|
|
17
|
+
return {
|
|
18
|
+
id: perm.values[0],
|
|
19
|
+
isReadOnly: isReadOnly(perm)
|
|
20
|
+
}
|
|
13
21
|
}
|
|
14
22
|
|
|
15
23
|
export default getSharedDocument
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import getSharedDocument from './getSharedDocument'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
function setupClient(verbs = []) {
|
|
4
|
+
return {
|
|
5
5
|
collection: () => ({
|
|
6
6
|
getOwnPermissions: jest.fn().mockReturnValue({
|
|
7
7
|
data: {
|
|
@@ -9,14 +9,14 @@ describe('Getting the shared document id', () => {
|
|
|
9
9
|
permissions: {
|
|
10
10
|
collection: {
|
|
11
11
|
type: 'io.cozy.photos.albums',
|
|
12
|
-
verbs
|
|
12
|
+
verbs,
|
|
13
13
|
values: ['myshareid']
|
|
14
14
|
},
|
|
15
15
|
files: {
|
|
16
16
|
selector: 'referenced_by',
|
|
17
17
|
type: 'io.cozy.files',
|
|
18
18
|
values: ['io.cozy.photos.albums/myshareid'],
|
|
19
|
-
verbs
|
|
19
|
+
verbs
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -24,9 +24,30 @@ describe('Getting the shared document id', () => {
|
|
|
24
24
|
})
|
|
25
25
|
})
|
|
26
26
|
}
|
|
27
|
+
}
|
|
27
28
|
|
|
29
|
+
describe('Getting the shared document', () => {
|
|
28
30
|
it('should get the id', async () => {
|
|
29
|
-
const
|
|
31
|
+
const client = setupClient(['GET'])
|
|
32
|
+
const { id } = await getSharedDocument(client)
|
|
30
33
|
expect(id).toEqual('myshareid')
|
|
31
34
|
})
|
|
35
|
+
|
|
36
|
+
it('should return isReadOnly is true when we have only a GET permission', async () => {
|
|
37
|
+
const client = setupClient(['GET'])
|
|
38
|
+
const { isReadOnly } = await getSharedDocument(client)
|
|
39
|
+
expect(isReadOnly).toBeTruthy()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('should return isReadOnly is false when we have an ALL permission', async () => {
|
|
43
|
+
const client = setupClient(['ALL'])
|
|
44
|
+
const { isReadOnly } = await getSharedDocument(client)
|
|
45
|
+
expect(isReadOnly).toBeFalsy()
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('should return isReadOnly is false when we have a PATCH permission', async () => {
|
|
49
|
+
const client = setupClient(['GET', 'PATCH', 'PUT'])
|
|
50
|
+
const { isReadOnly } = await getSharedDocument(client)
|
|
51
|
+
expect(isReadOnly).toBeFalsy()
|
|
52
|
+
})
|
|
32
53
|
})
|
package/src/state.js
CHANGED
|
@@ -349,18 +349,14 @@ const getApps = state => state.apps
|
|
|
349
349
|
|
|
350
350
|
export const hasSharedParent = (state, documentPath) => {
|
|
351
351
|
if (!state.sharedPaths) {
|
|
352
|
-
//
|
|
353
|
-
console.log('hasSharedParent should not occur', state, documentPath)
|
|
354
|
-
return false
|
|
352
|
+
return false // hasSharedParent should not occur
|
|
355
353
|
}
|
|
356
354
|
return state.sharedPaths.some(path => documentPath.indexOf(`${path}/`) === 0)
|
|
357
355
|
}
|
|
358
356
|
|
|
359
357
|
export const hasSharedChild = (state, documentPath) => {
|
|
360
358
|
if (!state.sharedPaths) {
|
|
361
|
-
//
|
|
362
|
-
console.log('hasSharedChild should not occur', state, documentPath)
|
|
363
|
-
return false
|
|
359
|
+
return false // hasSharedChild should not occur
|
|
364
360
|
}
|
|
365
361
|
const ret = state.sharedPaths.some(
|
|
366
362
|
path => path.indexOf(`${documentPath}/`) === 0
|