@jahia/data-helper 1.0.1 → 1.0.4
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/esm/fragments/PredefinedFragments.js +6 -6
- package/esm/fragments/getPermissionFragment.js +27 -0
- package/esm/hooks/useNodeChecks/useNodeChecks.js +18 -22
- package/esm/hooks/useNodeChecks/useNodeChecks.spec.js +30 -0
- package/esm/hooks/useNodeInfo/useNodeInfo.gql-queries.js +12 -1
- package/esm/hooks/useNodeInfo/useNodeInfo.js +12 -0
- package/esm/hooks/useNodeInfo/useNodeInfo.spec.js +34 -1
- package/js/fragments/PredefinedFragments.js +6 -6
- package/js/fragments/getPermissionFragment.js +31 -1
- package/js/hooks/useNodeChecks/useNodeChecks.js +18 -22
- package/js/hooks/useNodeChecks/useNodeChecks.spec.js +30 -0
- package/js/hooks/useNodeInfo/useNodeInfo.gql-queries.js +11 -0
- package/js/hooks/useNodeInfo/useNodeInfo.js +12 -0
- package/js/hooks/useNodeInfo/useNodeInfo.spec.js +34 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function _templateObject20() {
|
|
2
|
-
var data = _taggedTemplateLiteral(["fragment NodeInfoResourceNode on JCRNode {\n resourceChildren: children(names: [\"jcr:content\"]) {\n nodes {\n mimeType: property(name: \"jcr:mimeType\") {\n value\n }\n }\n }\n }"]);
|
|
2
|
+
var data = _taggedTemplateLiteral(["fragment NodeInfoResourceNode on JCRNode {\n resourceChildren: children(names: [\"jcr:content\"]) {\n nodes {\n ...NodeCacheRequiredFields\n mimeType: property(name: \"jcr:mimeType\") {\n value\n }\n }\n }\n }"]);
|
|
3
3
|
|
|
4
4
|
_templateObject20 = function _templateObject20() {
|
|
5
5
|
return data;
|
|
@@ -29,7 +29,7 @@ function _templateObject18() {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
function _templateObject17() {
|
|
32
|
-
var data = _taggedTemplateLiteral(["fragment NodeCacheRequiredFields on JCRNode {\n uuid\n workspace\n path\n
|
|
32
|
+
var data = _taggedTemplateLiteral(["fragment NodeCacheRequiredFields on JCRNode {\n uuid\n workspace\n path\n }"]);
|
|
33
33
|
|
|
34
34
|
_templateObject17 = function _templateObject17() {
|
|
35
35
|
return data;
|
|
@@ -39,7 +39,7 @@ function _templateObject17() {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
function _templateObject16() {
|
|
42
|
-
var data = _taggedTemplateLiteral(["fragment NodeSiteHomePage on JCRNode {\n children(typesFilter:{types:[\"jnt:page\"]}, propertiesFilter:{filters:[{property:\"j:isHomePage\", value:\"true\" }]}) {\n nodes {\n path\n }\n }\n }"]);
|
|
42
|
+
var data = _taggedTemplateLiteral(["fragment NodeSiteHomePage on JCRNode {\n children(typesFilter:{types:[\"jnt:page\"]}, propertiesFilter:{filters:[{property:\"j:isHomePage\", value:\"true\" }]}) {\n nodes {\n path\n ...NodeCacheRequiredFields\n }\n }\n }"]);
|
|
43
43
|
|
|
44
44
|
_templateObject16 = function _templateObject16() {
|
|
45
45
|
return data;
|
|
@@ -49,7 +49,7 @@ function _templateObject16() {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
function _templateObject15() {
|
|
52
|
-
var data = _taggedTemplateLiteral(["fragment ContentRestriction on JCRNode {\n contributeTypes: property(name: \"j:contributeTypes\") {\n values\n }\n ancestors(fieldFilter: {filters: {evaluation: NOT_EMPTY, fieldName: \"contributeTypes\"}}) {\n contributeTypes : property(name: \"j:contributeTypes\") {\n values\n }\n }\n }"]);
|
|
52
|
+
var data = _taggedTemplateLiteral(["fragment ContentRestriction on JCRNode {\n contributeTypes: property(name: \"j:contributeTypes\") {\n values\n }\n ancestors(fieldFilter: {filters: {evaluation: NOT_EMPTY, fieldName: \"contributeTypes\"}}) {\n ...NodeCacheRequiredFields\n contributeTypes : property(name: \"j:contributeTypes\") {\n values\n }\n }\n }"]);
|
|
53
53
|
|
|
54
54
|
_templateObject15 = function _templateObject15() {
|
|
55
55
|
return data;
|
|
@@ -89,7 +89,7 @@ function _templateObject12() {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
function _templateObject11() {
|
|
92
|
-
var data = _taggedTemplateLiteral(["fragment DisplayableNodePath on JCRNode {\n displayableNode {\n path\n }\n }"]);
|
|
92
|
+
var data = _taggedTemplateLiteral(["fragment DisplayableNodePath on JCRNode {\n displayableNode {\n path\n ...NodeCacheRequiredFields\n }\n }"]);
|
|
93
93
|
|
|
94
94
|
_templateObject11 = function _templateObject11() {
|
|
95
95
|
return data;
|
|
@@ -169,7 +169,7 @@ function _templateObject4() {
|
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
function _templateObject3() {
|
|
172
|
-
var data = _taggedTemplateLiteral(["fragment ParentNodeInfo on JCRNode {\n parent {\n path\n name\n }\n }"]);
|
|
172
|
+
var data = _taggedTemplateLiteral(["fragment ParentNodeInfo on JCRNode {\n parent {\n path\n name\n ...NodeCacheRequiredFields\n }\n }"]);
|
|
173
173
|
|
|
174
174
|
_templateObject3 = function _templateObject3() {
|
|
175
175
|
return data;
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
function _templateObject2() {
|
|
2
|
+
var data = _taggedTemplateLiteral(["fragment SiteNodePermission_", " on JCRNode {\n site {\n ...NodeCacheRequiredFields\n ", ":hasPermission(permissionName: $", ")\n }\n }"]);
|
|
3
|
+
|
|
4
|
+
_templateObject2 = function _templateObject2() {
|
|
5
|
+
return data;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
return data;
|
|
9
|
+
}
|
|
10
|
+
|
|
1
11
|
function _templateObject() {
|
|
2
12
|
var data = _taggedTemplateLiteral(["fragment NodePermission_", " on JCRNode {\n ", ":hasPermission(permissionName: $", ")\n }"]);
|
|
3
13
|
|
|
@@ -32,6 +42,23 @@ export var getPermissionFragment = function getPermissionFragment(name) {
|
|
|
32
42
|
variables: _defineProperty({}, encodedName, name)
|
|
33
43
|
};
|
|
34
44
|
};
|
|
45
|
+
export var getSitePermissionFragment = function getSitePermissionFragment(name) {
|
|
46
|
+
var encodedName = getEncodedPermissionName(name);
|
|
47
|
+
|
|
48
|
+
if (!fragments['site_' + encodedName]) {
|
|
49
|
+
var fragment = {
|
|
50
|
+
applyFor: 'node',
|
|
51
|
+
variables: _defineProperty({}, encodedName, 'String!'),
|
|
52
|
+
gql: gql(_templateObject2(), encodedName, encodedName, encodedName)
|
|
53
|
+
};
|
|
54
|
+
fragments['site_' + encodedName] = fragment;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
fragment: fragments['site_' + encodedName],
|
|
59
|
+
variables: _defineProperty({}, encodedName, name)
|
|
60
|
+
};
|
|
61
|
+
};
|
|
35
62
|
export var getEncodedPermissionName = function getEncodedPermissionName(name) {
|
|
36
63
|
return 'permission_' + encodeName(name);
|
|
37
64
|
};
|
|
@@ -20,39 +20,33 @@ var evaluateVisibilityPaths = function evaluateVisibilityPaths(visible, visibili
|
|
|
20
20
|
return !visible;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
function addArrayOptionValues(newValue, useNodeInfoOptions, useNodeInfoKey) {
|
|
24
|
+
if (newValue) {
|
|
25
|
+
useNodeInfoOptions[useNodeInfoKey] = useNodeInfoOptions[useNodeInfoKey] || [];
|
|
26
|
+
useNodeInfoOptions[useNodeInfoKey] = useNodeInfoOptions[useNodeInfoKey].concat(newValue.filter(function (item) {
|
|
27
|
+
return useNodeInfoOptions[useNodeInfoKey].indexOf(item) < 0;
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
23
32
|
export var useNodeChecks = function useNodeChecks(variables, options, queryOptions) {
|
|
24
33
|
var requiredPermission = options.requiredPermission,
|
|
34
|
+
requiredSitePermission = options.requiredSitePermission,
|
|
25
35
|
showOnNodeTypes = options.showOnNodeTypes,
|
|
26
36
|
hideOnNodeTypes = options.hideOnNodeTypes,
|
|
27
37
|
requireModuleInstalledOnSite = options.requireModuleInstalledOnSite,
|
|
28
38
|
showForPaths = options.showForPaths,
|
|
29
39
|
hideForPaths = options.hideForPaths,
|
|
30
|
-
othersOptions = _objectWithoutProperties(options, ["requiredPermission", "showOnNodeTypes", "hideOnNodeTypes", "requireModuleInstalledOnSite", "showForPaths", "hideForPaths"]);
|
|
40
|
+
othersOptions = _objectWithoutProperties(options, ["requiredPermission", "requiredSitePermission", "showOnNodeTypes", "hideOnNodeTypes", "requireModuleInstalledOnSite", "showForPaths", "hideForPaths"]);
|
|
31
41
|
|
|
32
42
|
var useNodeInfoOptions = _objectSpread({}, othersOptions);
|
|
33
43
|
|
|
34
44
|
var requiredPermissions = typeof requiredPermission === 'string' ? [requiredPermission] : requiredPermission;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (showOnNodeTypes) {
|
|
44
|
-
useNodeInfoOptions.getIsNodeTypes = useNodeInfoOptions.getIsNodeTypes || [];
|
|
45
|
-
useNodeInfoOptions.getIsNodeTypes = useNodeInfoOptions.getIsNodeTypes.concat(showOnNodeTypes.filter(function (item) {
|
|
46
|
-
return useNodeInfoOptions.getIsNodeTypes.indexOf(item) < 0;
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (hideOnNodeTypes) {
|
|
51
|
-
useNodeInfoOptions.getIsNodeTypes = useNodeInfoOptions.getIsNodeTypes || [];
|
|
52
|
-
useNodeInfoOptions.getIsNodeTypes = useNodeInfoOptions.getIsNodeTypes.concat(hideOnNodeTypes.filter(function (item) {
|
|
53
|
-
return useNodeInfoOptions.getIsNodeTypes.indexOf(item) < 0;
|
|
54
|
-
}));
|
|
55
|
-
}
|
|
45
|
+
var requiredSitePermissions = typeof requiredSitePermission === 'string' ? [requiredSitePermission] : requiredSitePermission;
|
|
46
|
+
addArrayOptionValues(requiredPermissions, useNodeInfoOptions, 'getPermissions');
|
|
47
|
+
addArrayOptionValues(requiredSitePermissions, useNodeInfoOptions, 'getSitePermissions');
|
|
48
|
+
addArrayOptionValues(showOnNodeTypes, useNodeInfoOptions, 'getIsNodeTypes');
|
|
49
|
+
addArrayOptionValues(hideOnNodeTypes, useNodeInfoOptions, 'getIsNodeTypes');
|
|
56
50
|
|
|
57
51
|
if (requireModuleInstalledOnSite) {
|
|
58
52
|
useNodeInfoOptions.getSiteInstalledModules = true;
|
|
@@ -80,6 +74,8 @@ export var useNodeChecks = function useNodeChecks(variables, options, queryOptio
|
|
|
80
74
|
var doNodeCheck = function doNodeCheck(node) {
|
|
81
75
|
return (!requiredPermissions || requiredPermissions.reduce(function (acc, val) {
|
|
82
76
|
return acc || node[val];
|
|
77
|
+
}, false)) && (!requiredSitePermissions || requiredSitePermissions.reduce(function (acc, val) {
|
|
78
|
+
return acc || node.site[val];
|
|
83
79
|
}, false)) && (!showOnNodeTypes || showOnNodeTypes.reduce(function (acc, val) {
|
|
84
80
|
return acc || node[val];
|
|
85
81
|
}, false)) && (!hideOnNodeTypes || !hideOnNodeTypes.reduce(function (acc, val) {
|
|
@@ -66,4 +66,34 @@ describe('useNodeChecks', function () {
|
|
|
66
66
|
return m.alias.value;
|
|
67
67
|
})).toContain('permission_encoded_Y2FuV3JpdGU');
|
|
68
68
|
});
|
|
69
|
+
it('should request site permissions', function () {
|
|
70
|
+
useNodeChecks({
|
|
71
|
+
path: '/test',
|
|
72
|
+
language: 'en'
|
|
73
|
+
}, {
|
|
74
|
+
requiredPermission: ['canRead', 'canWrite']
|
|
75
|
+
});
|
|
76
|
+
expect(useQuery).toHaveBeenCalled();
|
|
77
|
+
var mock = useQuery.mock;
|
|
78
|
+
var call = mock.calls[mock.calls.length - 1];
|
|
79
|
+
var variables = call[1].variables;
|
|
80
|
+
call[0].definitions[0].variableDefinitions.map(function (v) {
|
|
81
|
+
return v.variable.name.value;
|
|
82
|
+
}).forEach(function (v) {
|
|
83
|
+
return expect(Object.keys(variables)).toContain(v);
|
|
84
|
+
});
|
|
85
|
+
expect(call[0].definitions.map(function (d) {
|
|
86
|
+
return d.name.value;
|
|
87
|
+
})).toContain('NodePermission_permission_encoded_Y2FuUmVhZA');
|
|
88
|
+
expect(call[0].definitions.find(function (d) {
|
|
89
|
+
return d.name.value === 'NodePermission_permission_encoded_Y2FuUmVhZA';
|
|
90
|
+
}).selectionSet.selections.map(function (m) {
|
|
91
|
+
return m.alias.value;
|
|
92
|
+
})).toContain('permission_encoded_Y2FuUmVhZA');
|
|
93
|
+
expect(call[0].definitions.find(function (d) {
|
|
94
|
+
return d.name.value === 'NodePermission_permission_encoded_Y2FuV3JpdGU';
|
|
95
|
+
}).selectionSet.selections.map(function (m) {
|
|
96
|
+
return m.alias.value;
|
|
97
|
+
})).toContain('permission_encoded_Y2FuV3JpdGU');
|
|
98
|
+
});
|
|
69
99
|
});
|
|
@@ -42,7 +42,7 @@ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(
|
|
|
42
42
|
|
|
43
43
|
import gql from 'graphql-tag';
|
|
44
44
|
import { aggregatedPublicationInfoWithExistInLive, aggregatedPublicationInfo, childNodeTypes, contentRestrictions, displayableNode, displayName, getProperties, installedModules, lockInfo, mimeTypes, nodeCacheRequiredFields, operationSupport, parentNode, primaryNodeType, replaceFragmentsInDocument, siteLanguages, subNodesCount } from '../../fragments';
|
|
45
|
-
import { getPermissionFragment } from '../../fragments/getPermissionFragment';
|
|
45
|
+
import { getPermissionFragment, getSitePermissionFragment } from '../../fragments/getPermissionFragment';
|
|
46
46
|
import { getNodeTypeFragment } from '../../fragments/getIsNodeTypeFragment';
|
|
47
47
|
|
|
48
48
|
var getBaseQueryAndVariables = function getBaseQueryAndVariables(variables) {
|
|
@@ -162,6 +162,17 @@ export var getQuery = function getQuery(variables, schemaResult) {
|
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
if (options.getSitePermissions) {
|
|
166
|
+
options.getSitePermissions.forEach(function (name) {
|
|
167
|
+
var _getSitePermissionFra = getSitePermissionFragment(name),
|
|
168
|
+
fragment = _getSitePermissionFra.fragment,
|
|
169
|
+
variables = _getSitePermissionFra.variables;
|
|
170
|
+
|
|
171
|
+
fragments.push(fragment);
|
|
172
|
+
Object.assign(generatedVariables, variables);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
165
176
|
if (options.getIsNodeTypes) {
|
|
166
177
|
options.getIsNodeTypes.forEach(function (name) {
|
|
167
178
|
var _getNodeTypeFragment = getNodeTypeFragment(name),
|
|
@@ -75,6 +75,10 @@ export var useNodeInfo = function useNodeInfo(variables, options, queryOptions)
|
|
|
75
75
|
var decodeResult = function decodeResult(nodeOrig, options) {
|
|
76
76
|
var node = _objectSpread({}, nodeOrig);
|
|
77
77
|
|
|
78
|
+
if (node.site) {
|
|
79
|
+
node.site = _objectSpread({}, node.site);
|
|
80
|
+
}
|
|
81
|
+
|
|
78
82
|
if (node && options) {
|
|
79
83
|
if (options.getPermissions) {
|
|
80
84
|
options.getPermissions.forEach(function (name) {
|
|
@@ -84,6 +88,14 @@ var decodeResult = function decodeResult(nodeOrig, options) {
|
|
|
84
88
|
});
|
|
85
89
|
}
|
|
86
90
|
|
|
91
|
+
if (options.getSitePermissions) {
|
|
92
|
+
options.getSitePermissions.forEach(function (name) {
|
|
93
|
+
var res = node.site[getEncodedPermissionName(name)];
|
|
94
|
+
delete node.site[getEncodedPermissionName(name)];
|
|
95
|
+
node.site[name] = res;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
87
99
|
if (options.getIsNodeTypes) {
|
|
88
100
|
options.getIsNodeTypes.forEach(function (name) {
|
|
89
101
|
var res = node[getEncodedNodeTypeName(name)];
|
|
@@ -10,7 +10,8 @@ jest.mock('react-apollo', function () {
|
|
|
10
10
|
nodeByPath: {
|
|
11
11
|
resourceChildren: {
|
|
12
12
|
nodes: []
|
|
13
|
-
}
|
|
13
|
+
},
|
|
14
|
+
site: {}
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
},
|
|
@@ -149,6 +150,38 @@ describe('useNodeInfo', function () {
|
|
|
149
150
|
return m.alias.value;
|
|
150
151
|
})).toContain('permission_encoded_Y2FuV3JpdGU');
|
|
151
152
|
});
|
|
153
|
+
it('should request site permissions', function () {
|
|
154
|
+
useNodeInfo({
|
|
155
|
+
path: '/test',
|
|
156
|
+
language: 'en'
|
|
157
|
+
}, {
|
|
158
|
+
getSitePermissions: ['canRead', 'canWrite']
|
|
159
|
+
});
|
|
160
|
+
expect(useQuery).toHaveBeenCalled();
|
|
161
|
+
var mock = useQuery.mock;
|
|
162
|
+
var call = mock.calls[mock.calls.length - 1];
|
|
163
|
+
var variables = call[1].variables;
|
|
164
|
+
call[0].definitions[0].variableDefinitions.map(function (v) {
|
|
165
|
+
return v.variable.name.value;
|
|
166
|
+
}).forEach(function (v) {
|
|
167
|
+
return expect(Object.keys(variables)).toContain(v);
|
|
168
|
+
});
|
|
169
|
+
expect(call[0].definitions.map(function (d) {
|
|
170
|
+
return d.name.value;
|
|
171
|
+
})).toContain('SiteNodePermission_permission_encoded_Y2FuUmVhZA');
|
|
172
|
+
expect(call[0].definitions.find(function (d) {
|
|
173
|
+
return d.name.value === 'SiteNodePermission_permission_encoded_Y2FuUmVhZA';
|
|
174
|
+
}).selectionSet.selections[0].name.value).toBe('site');
|
|
175
|
+
expect(call[0].definitions.find(function (d) {
|
|
176
|
+
return d.name.value === 'SiteNodePermission_permission_encoded_Y2FuUmVhZA';
|
|
177
|
+
}).selectionSet.selections[0].selectionSet.selections[1].alias.value).toBe('permission_encoded_Y2FuUmVhZA');
|
|
178
|
+
expect(call[0].definitions.find(function (d) {
|
|
179
|
+
return d.name.value === 'SiteNodePermission_permission_encoded_Y2FuV3JpdGU';
|
|
180
|
+
}).selectionSet.selections[0].name.value).toBe('site');
|
|
181
|
+
expect(call[0].definitions.find(function (d) {
|
|
182
|
+
return d.name.value === 'SiteNodePermission_permission_encoded_Y2FuV3JpdGU';
|
|
183
|
+
}).selectionSet.selections[0].selectionSet.selections[1].alias.value).toBe('permission_encoded_Y2FuV3JpdGU');
|
|
184
|
+
});
|
|
152
185
|
it('should request isNodeTypes', function () {
|
|
153
186
|
useNodeInfo({
|
|
154
187
|
path: '/test',
|
|
@@ -10,7 +10,7 @@ var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
11
|
|
|
12
12
|
function _templateObject20() {
|
|
13
|
-
var data = _taggedTemplateLiteral(["fragment NodeInfoResourceNode on JCRNode {\n resourceChildren: children(names: [\"jcr:content\"]) {\n nodes {\n mimeType: property(name: \"jcr:mimeType\") {\n value\n }\n }\n }\n }"]);
|
|
13
|
+
var data = _taggedTemplateLiteral(["fragment NodeInfoResourceNode on JCRNode {\n resourceChildren: children(names: [\"jcr:content\"]) {\n nodes {\n ...NodeCacheRequiredFields\n mimeType: property(name: \"jcr:mimeType\") {\n value\n }\n }\n }\n }"]);
|
|
14
14
|
|
|
15
15
|
_templateObject20 = function _templateObject20() {
|
|
16
16
|
return data;
|
|
@@ -40,7 +40,7 @@ function _templateObject18() {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
function _templateObject17() {
|
|
43
|
-
var data = _taggedTemplateLiteral(["fragment NodeCacheRequiredFields on JCRNode {\n uuid\n workspace\n path\n
|
|
43
|
+
var data = _taggedTemplateLiteral(["fragment NodeCacheRequiredFields on JCRNode {\n uuid\n workspace\n path\n }"]);
|
|
44
44
|
|
|
45
45
|
_templateObject17 = function _templateObject17() {
|
|
46
46
|
return data;
|
|
@@ -50,7 +50,7 @@ function _templateObject17() {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
function _templateObject16() {
|
|
53
|
-
var data = _taggedTemplateLiteral(["fragment NodeSiteHomePage on JCRNode {\n children(typesFilter:{types:[\"jnt:page\"]}, propertiesFilter:{filters:[{property:\"j:isHomePage\", value:\"true\" }]}) {\n nodes {\n path\n }\n }\n }"]);
|
|
53
|
+
var data = _taggedTemplateLiteral(["fragment NodeSiteHomePage on JCRNode {\n children(typesFilter:{types:[\"jnt:page\"]}, propertiesFilter:{filters:[{property:\"j:isHomePage\", value:\"true\" }]}) {\n nodes {\n path\n ...NodeCacheRequiredFields\n }\n }\n }"]);
|
|
54
54
|
|
|
55
55
|
_templateObject16 = function _templateObject16() {
|
|
56
56
|
return data;
|
|
@@ -60,7 +60,7 @@ function _templateObject16() {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
function _templateObject15() {
|
|
63
|
-
var data = _taggedTemplateLiteral(["fragment ContentRestriction on JCRNode {\n contributeTypes: property(name: \"j:contributeTypes\") {\n values\n }\n ancestors(fieldFilter: {filters: {evaluation: NOT_EMPTY, fieldName: \"contributeTypes\"}}) {\n contributeTypes : property(name: \"j:contributeTypes\") {\n values\n }\n }\n }"]);
|
|
63
|
+
var data = _taggedTemplateLiteral(["fragment ContentRestriction on JCRNode {\n contributeTypes: property(name: \"j:contributeTypes\") {\n values\n }\n ancestors(fieldFilter: {filters: {evaluation: NOT_EMPTY, fieldName: \"contributeTypes\"}}) {\n ...NodeCacheRequiredFields\n contributeTypes : property(name: \"j:contributeTypes\") {\n values\n }\n }\n }"]);
|
|
64
64
|
|
|
65
65
|
_templateObject15 = function _templateObject15() {
|
|
66
66
|
return data;
|
|
@@ -100,7 +100,7 @@ function _templateObject12() {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
function _templateObject11() {
|
|
103
|
-
var data = _taggedTemplateLiteral(["fragment DisplayableNodePath on JCRNode {\n displayableNode {\n path\n }\n }"]);
|
|
103
|
+
var data = _taggedTemplateLiteral(["fragment DisplayableNodePath on JCRNode {\n displayableNode {\n path\n ...NodeCacheRequiredFields\n }\n }"]);
|
|
104
104
|
|
|
105
105
|
_templateObject11 = function _templateObject11() {
|
|
106
106
|
return data;
|
|
@@ -180,7 +180,7 @@ function _templateObject4() {
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
function _templateObject3() {
|
|
183
|
-
var data = _taggedTemplateLiteral(["fragment ParentNodeInfo on JCRNode {\n parent {\n path\n name\n }\n }"]);
|
|
183
|
+
var data = _taggedTemplateLiteral(["fragment ParentNodeInfo on JCRNode {\n parent {\n path\n name\n ...NodeCacheRequiredFields\n }\n }"]);
|
|
184
184
|
|
|
185
185
|
_templateObject3 = function _templateObject3() {
|
|
186
186
|
return data;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getEncodedPermissionName = exports.getPermissionFragment = void 0;
|
|
6
|
+
exports.getEncodedPermissionName = exports.getSitePermissionFragment = exports.getPermissionFragment = void 0;
|
|
7
7
|
|
|
8
8
|
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
9
9
|
|
|
@@ -11,6 +11,16 @@ var _encodeName = require("./encodeName");
|
|
|
11
11
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
13
|
|
|
14
|
+
function _templateObject2() {
|
|
15
|
+
var data = _taggedTemplateLiteral(["fragment SiteNodePermission_", " on JCRNode {\n site {\n ...NodeCacheRequiredFields\n ", ":hasPermission(permissionName: $", ")\n }\n }"]);
|
|
16
|
+
|
|
17
|
+
_templateObject2 = function _templateObject2() {
|
|
18
|
+
return data;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
23
|
+
|
|
14
24
|
function _templateObject() {
|
|
15
25
|
var data = _taggedTemplateLiteral(["fragment NodePermission_", " on JCRNode {\n ", ":hasPermission(permissionName: $", ")\n }"]);
|
|
16
26
|
|
|
@@ -47,6 +57,26 @@ var getPermissionFragment = function getPermissionFragment(name) {
|
|
|
47
57
|
|
|
48
58
|
exports.getPermissionFragment = getPermissionFragment;
|
|
49
59
|
|
|
60
|
+
var getSitePermissionFragment = function getSitePermissionFragment(name) {
|
|
61
|
+
var encodedName = getEncodedPermissionName(name);
|
|
62
|
+
|
|
63
|
+
if (!fragments['site_' + encodedName]) {
|
|
64
|
+
var fragment = {
|
|
65
|
+
applyFor: 'node',
|
|
66
|
+
variables: _defineProperty({}, encodedName, 'String!'),
|
|
67
|
+
gql: (0, _graphqlTag["default"])(_templateObject2(), encodedName, encodedName, encodedName)
|
|
68
|
+
};
|
|
69
|
+
fragments['site_' + encodedName] = fragment;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
fragment: fragments['site_' + encodedName],
|
|
74
|
+
variables: _defineProperty({}, encodedName, name)
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
exports.getSitePermissionFragment = getSitePermissionFragment;
|
|
79
|
+
|
|
50
80
|
var getEncodedPermissionName = function getEncodedPermissionName(name) {
|
|
51
81
|
return 'permission_' + (0, _encodeName.encodeName)(name);
|
|
52
82
|
};
|
|
@@ -27,39 +27,33 @@ var evaluateVisibilityPaths = function evaluateVisibilityPaths(visible, visibili
|
|
|
27
27
|
return !visible;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
function addArrayOptionValues(newValue, useNodeInfoOptions, useNodeInfoKey) {
|
|
31
|
+
if (newValue) {
|
|
32
|
+
useNodeInfoOptions[useNodeInfoKey] = useNodeInfoOptions[useNodeInfoKey] || [];
|
|
33
|
+
useNodeInfoOptions[useNodeInfoKey] = useNodeInfoOptions[useNodeInfoKey].concat(newValue.filter(function (item) {
|
|
34
|
+
return useNodeInfoOptions[useNodeInfoKey].indexOf(item) < 0;
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
30
39
|
var useNodeChecks = function useNodeChecks(variables, options, queryOptions) {
|
|
31
40
|
var requiredPermission = options.requiredPermission,
|
|
41
|
+
requiredSitePermission = options.requiredSitePermission,
|
|
32
42
|
showOnNodeTypes = options.showOnNodeTypes,
|
|
33
43
|
hideOnNodeTypes = options.hideOnNodeTypes,
|
|
34
44
|
requireModuleInstalledOnSite = options.requireModuleInstalledOnSite,
|
|
35
45
|
showForPaths = options.showForPaths,
|
|
36
46
|
hideForPaths = options.hideForPaths,
|
|
37
|
-
othersOptions = _objectWithoutProperties(options, ["requiredPermission", "showOnNodeTypes", "hideOnNodeTypes", "requireModuleInstalledOnSite", "showForPaths", "hideForPaths"]);
|
|
47
|
+
othersOptions = _objectWithoutProperties(options, ["requiredPermission", "requiredSitePermission", "showOnNodeTypes", "hideOnNodeTypes", "requireModuleInstalledOnSite", "showForPaths", "hideForPaths"]);
|
|
38
48
|
|
|
39
49
|
var useNodeInfoOptions = _objectSpread({}, othersOptions);
|
|
40
50
|
|
|
41
51
|
var requiredPermissions = typeof requiredPermission === 'string' ? [requiredPermission] : requiredPermission;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (showOnNodeTypes) {
|
|
51
|
-
useNodeInfoOptions.getIsNodeTypes = useNodeInfoOptions.getIsNodeTypes || [];
|
|
52
|
-
useNodeInfoOptions.getIsNodeTypes = useNodeInfoOptions.getIsNodeTypes.concat(showOnNodeTypes.filter(function (item) {
|
|
53
|
-
return useNodeInfoOptions.getIsNodeTypes.indexOf(item) < 0;
|
|
54
|
-
}));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (hideOnNodeTypes) {
|
|
58
|
-
useNodeInfoOptions.getIsNodeTypes = useNodeInfoOptions.getIsNodeTypes || [];
|
|
59
|
-
useNodeInfoOptions.getIsNodeTypes = useNodeInfoOptions.getIsNodeTypes.concat(hideOnNodeTypes.filter(function (item) {
|
|
60
|
-
return useNodeInfoOptions.getIsNodeTypes.indexOf(item) < 0;
|
|
61
|
-
}));
|
|
62
|
-
}
|
|
52
|
+
var requiredSitePermissions = typeof requiredSitePermission === 'string' ? [requiredSitePermission] : requiredSitePermission;
|
|
53
|
+
addArrayOptionValues(requiredPermissions, useNodeInfoOptions, 'getPermissions');
|
|
54
|
+
addArrayOptionValues(requiredSitePermissions, useNodeInfoOptions, 'getSitePermissions');
|
|
55
|
+
addArrayOptionValues(showOnNodeTypes, useNodeInfoOptions, 'getIsNodeTypes');
|
|
56
|
+
addArrayOptionValues(hideOnNodeTypes, useNodeInfoOptions, 'getIsNodeTypes');
|
|
63
57
|
|
|
64
58
|
if (requireModuleInstalledOnSite) {
|
|
65
59
|
useNodeInfoOptions.getSiteInstalledModules = true;
|
|
@@ -87,6 +81,8 @@ var useNodeChecks = function useNodeChecks(variables, options, queryOptions) {
|
|
|
87
81
|
var doNodeCheck = function doNodeCheck(node) {
|
|
88
82
|
return (!requiredPermissions || requiredPermissions.reduce(function (acc, val) {
|
|
89
83
|
return acc || node[val];
|
|
84
|
+
}, false)) && (!requiredSitePermissions || requiredSitePermissions.reduce(function (acc, val) {
|
|
85
|
+
return acc || node.site[val];
|
|
90
86
|
}, false)) && (!showOnNodeTypes || showOnNodeTypes.reduce(function (acc, val) {
|
|
91
87
|
return acc || node[val];
|
|
92
88
|
}, false)) && (!hideOnNodeTypes || !hideOnNodeTypes.reduce(function (acc, val) {
|
|
@@ -70,4 +70,34 @@ describe('useNodeChecks', function () {
|
|
|
70
70
|
return m.alias.value;
|
|
71
71
|
})).toContain('permission_encoded_Y2FuV3JpdGU');
|
|
72
72
|
});
|
|
73
|
+
it('should request site permissions', function () {
|
|
74
|
+
(0, _index.useNodeChecks)({
|
|
75
|
+
path: '/test',
|
|
76
|
+
language: 'en'
|
|
77
|
+
}, {
|
|
78
|
+
requiredPermission: ['canRead', 'canWrite']
|
|
79
|
+
});
|
|
80
|
+
expect(_reactApollo.useQuery).toHaveBeenCalled();
|
|
81
|
+
var mock = _reactApollo.useQuery.mock;
|
|
82
|
+
var call = mock.calls[mock.calls.length - 1];
|
|
83
|
+
var variables = call[1].variables;
|
|
84
|
+
call[0].definitions[0].variableDefinitions.map(function (v) {
|
|
85
|
+
return v.variable.name.value;
|
|
86
|
+
}).forEach(function (v) {
|
|
87
|
+
return expect(Object.keys(variables)).toContain(v);
|
|
88
|
+
});
|
|
89
|
+
expect(call[0].definitions.map(function (d) {
|
|
90
|
+
return d.name.value;
|
|
91
|
+
})).toContain('NodePermission_permission_encoded_Y2FuUmVhZA');
|
|
92
|
+
expect(call[0].definitions.find(function (d) {
|
|
93
|
+
return d.name.value === 'NodePermission_permission_encoded_Y2FuUmVhZA';
|
|
94
|
+
}).selectionSet.selections.map(function (m) {
|
|
95
|
+
return m.alias.value;
|
|
96
|
+
})).toContain('permission_encoded_Y2FuUmVhZA');
|
|
97
|
+
expect(call[0].definitions.find(function (d) {
|
|
98
|
+
return d.name.value === 'NodePermission_permission_encoded_Y2FuV3JpdGU';
|
|
99
|
+
}).selectionSet.selections.map(function (m) {
|
|
100
|
+
return m.alias.value;
|
|
101
|
+
})).toContain('permission_encoded_Y2FuV3JpdGU');
|
|
102
|
+
});
|
|
73
103
|
});
|
|
@@ -174,6 +174,17 @@ var getQuery = function getQuery(variables, schemaResult) {
|
|
|
174
174
|
});
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
if (options.getSitePermissions) {
|
|
178
|
+
options.getSitePermissions.forEach(function (name) {
|
|
179
|
+
var _getSitePermissionFra = (0, _getPermissionFragment.getSitePermissionFragment)(name),
|
|
180
|
+
fragment = _getSitePermissionFra.fragment,
|
|
181
|
+
variables = _getSitePermissionFra.variables;
|
|
182
|
+
|
|
183
|
+
fragments.push(fragment);
|
|
184
|
+
Object.assign(generatedVariables, variables);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
177
188
|
if (options.getIsNodeTypes) {
|
|
178
189
|
options.getIsNodeTypes.forEach(function (name) {
|
|
179
190
|
var _getNodeTypeFragment = (0, _getIsNodeTypeFragment.getNodeTypeFragment)(name),
|
|
@@ -91,6 +91,10 @@ exports.useNodeInfo = useNodeInfo;
|
|
|
91
91
|
var decodeResult = function decodeResult(nodeOrig, options) {
|
|
92
92
|
var node = _objectSpread({}, nodeOrig);
|
|
93
93
|
|
|
94
|
+
if (node.site) {
|
|
95
|
+
node.site = _objectSpread({}, node.site);
|
|
96
|
+
}
|
|
97
|
+
|
|
94
98
|
if (node && options) {
|
|
95
99
|
if (options.getPermissions) {
|
|
96
100
|
options.getPermissions.forEach(function (name) {
|
|
@@ -100,6 +104,14 @@ var decodeResult = function decodeResult(nodeOrig, options) {
|
|
|
100
104
|
});
|
|
101
105
|
}
|
|
102
106
|
|
|
107
|
+
if (options.getSitePermissions) {
|
|
108
|
+
options.getSitePermissions.forEach(function (name) {
|
|
109
|
+
var res = node.site[(0, _getPermissionFragment.getEncodedPermissionName)(name)];
|
|
110
|
+
delete node.site[(0, _getPermissionFragment.getEncodedPermissionName)(name)];
|
|
111
|
+
node.site[name] = res;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
103
115
|
if (options.getIsNodeTypes) {
|
|
104
116
|
options.getIsNodeTypes.forEach(function (name) {
|
|
105
117
|
var res = node[(0, _getIsNodeTypeFragment.getEncodedNodeTypeName)(name)];
|
|
@@ -15,7 +15,8 @@ jest.mock('react-apollo', function () {
|
|
|
15
15
|
nodeByPath: {
|
|
16
16
|
resourceChildren: {
|
|
17
17
|
nodes: []
|
|
18
|
-
}
|
|
18
|
+
},
|
|
19
|
+
site: {}
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
},
|
|
@@ -154,6 +155,38 @@ describe('useNodeInfo', function () {
|
|
|
154
155
|
return m.alias.value;
|
|
155
156
|
})).toContain('permission_encoded_Y2FuV3JpdGU');
|
|
156
157
|
});
|
|
158
|
+
it('should request site permissions', function () {
|
|
159
|
+
(0, _index.useNodeInfo)({
|
|
160
|
+
path: '/test',
|
|
161
|
+
language: 'en'
|
|
162
|
+
}, {
|
|
163
|
+
getSitePermissions: ['canRead', 'canWrite']
|
|
164
|
+
});
|
|
165
|
+
expect(_reactApollo.useQuery).toHaveBeenCalled();
|
|
166
|
+
var mock = _reactApollo.useQuery.mock;
|
|
167
|
+
var call = mock.calls[mock.calls.length - 1];
|
|
168
|
+
var variables = call[1].variables;
|
|
169
|
+
call[0].definitions[0].variableDefinitions.map(function (v) {
|
|
170
|
+
return v.variable.name.value;
|
|
171
|
+
}).forEach(function (v) {
|
|
172
|
+
return expect(Object.keys(variables)).toContain(v);
|
|
173
|
+
});
|
|
174
|
+
expect(call[0].definitions.map(function (d) {
|
|
175
|
+
return d.name.value;
|
|
176
|
+
})).toContain('SiteNodePermission_permission_encoded_Y2FuUmVhZA');
|
|
177
|
+
expect(call[0].definitions.find(function (d) {
|
|
178
|
+
return d.name.value === 'SiteNodePermission_permission_encoded_Y2FuUmVhZA';
|
|
179
|
+
}).selectionSet.selections[0].name.value).toBe('site');
|
|
180
|
+
expect(call[0].definitions.find(function (d) {
|
|
181
|
+
return d.name.value === 'SiteNodePermission_permission_encoded_Y2FuUmVhZA';
|
|
182
|
+
}).selectionSet.selections[0].selectionSet.selections[1].alias.value).toBe('permission_encoded_Y2FuUmVhZA');
|
|
183
|
+
expect(call[0].definitions.find(function (d) {
|
|
184
|
+
return d.name.value === 'SiteNodePermission_permission_encoded_Y2FuV3JpdGU';
|
|
185
|
+
}).selectionSet.selections[0].name.value).toBe('site');
|
|
186
|
+
expect(call[0].definitions.find(function (d) {
|
|
187
|
+
return d.name.value === 'SiteNodePermission_permission_encoded_Y2FuV3JpdGU';
|
|
188
|
+
}).selectionSet.selections[0].selectionSet.selections[1].alias.value).toBe('permission_encoded_Y2FuV3JpdGU');
|
|
189
|
+
});
|
|
157
190
|
it('should request isNodeTypes', function () {
|
|
158
191
|
(0, _index.useNodeInfo)({
|
|
159
192
|
path: '/test',
|