not-node 6.3.10 → 6.3.11
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/package.json +1 -1
- package/src/auth/rules.js +3 -3
- package/src/manifest/result.filter.js +19 -8
- package/test/result.filter.js +17 -0
package/package.json
CHANGED
package/src/auth/rules.js
CHANGED
|
@@ -81,9 +81,9 @@ function roleRequireAuthState(requiredAuth, userAuth) {
|
|
|
81
81
|
* @return {boolean}
|
|
82
82
|
*/
|
|
83
83
|
function compareAuthStatus(rule, auth) {
|
|
84
|
-
if (objHas(rule, "auth")) {
|
|
84
|
+
if (objHas(rule, "auth") && typeof rule.auth !== "undefined") {
|
|
85
85
|
return roleRequireAuthState(rule.auth, auth);
|
|
86
|
-
} else if (objHas(rule, "user")) {
|
|
86
|
+
} else if (objHas(rule, "user") && typeof rule.user !== "undefined") {
|
|
87
87
|
return roleRequireAuthState(rule.user, auth);
|
|
88
88
|
} else {
|
|
89
89
|
return true;
|
|
@@ -94,7 +94,7 @@ function compareAuthStatus(rule, auth) {
|
|
|
94
94
|
* Check rule against presented credentials
|
|
95
95
|
* @param {import('../types').notRouteRule} rule action rule
|
|
96
96
|
* @param {boolean} auth user state of auth
|
|
97
|
-
* @param {
|
|
97
|
+
* @param {Array<string>} role user state of role
|
|
98
98
|
* @param {boolean} root user state of root
|
|
99
99
|
* @return {boolean} pass or not
|
|
100
100
|
*/
|
|
@@ -71,11 +71,22 @@ module.exports = class notManifestRouteResultFilter {
|
|
|
71
71
|
if (!filteringTarget) {
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
74
|
-
|
|
75
|
-
filteringTarget
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
if (Array.isArray(filteringTarget)) {
|
|
75
|
+
filteringTarget.forEach((filteringTargetItem) => {
|
|
76
|
+
this.filterByRule(
|
|
77
|
+
filteringTargetItem,
|
|
78
|
+
filteringRule,
|
|
79
|
+
this.getFilteringStrictMode(notRouteData)
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
} else {
|
|
83
|
+
this.filterByRule(
|
|
84
|
+
filteringTarget,
|
|
85
|
+
filteringRule,
|
|
86
|
+
this.getFilteringStrictMode(notRouteData)
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
79
90
|
return result;
|
|
80
91
|
}
|
|
81
92
|
|
|
@@ -104,7 +115,7 @@ module.exports = class notManifestRouteResultFilter {
|
|
|
104
115
|
* if pathToProperty targets array in target, each item of array will be filtered by
|
|
105
116
|
* @param {object} target
|
|
106
117
|
* @param {object} rule map of properties.
|
|
107
|
-
* @param {boolean} strict filtering mode
|
|
118
|
+
* @param {boolean} [strict = DEFAULT_STRICT_MODE] filtering mode
|
|
108
119
|
* example:
|
|
109
120
|
* {
|
|
110
121
|
* 'user': ['username', 'id', 'email'], //filtering properties of object target.user
|
|
@@ -126,7 +137,7 @@ module.exports = class notManifestRouteResultFilter {
|
|
|
126
137
|
static filterByMapRule(target, rule, strict = DEFAULT_STRICT_MODE) {
|
|
127
138
|
//to form ['id', 'user.username', 'files']
|
|
128
139
|
const filteringArray = Object.keys(rule);
|
|
129
|
-
//filtering direct
|
|
140
|
+
//filtering direct children if in strict mode
|
|
130
141
|
if (strict) {
|
|
131
142
|
this.filterStrict(target, filteringArray);
|
|
132
143
|
}
|
|
@@ -212,7 +223,7 @@ module.exports = class notManifestRouteResultFilter {
|
|
|
212
223
|
* @returns {string} path of sub object in notPath notation
|
|
213
224
|
*/
|
|
214
225
|
static getFilteringTargetPath(notRouteData) {
|
|
215
|
-
let path = notPath.PATH_START_OBJECT
|
|
226
|
+
let path = `${notPath.PATH_START_OBJECT}`;
|
|
216
227
|
if (notRouteData) {
|
|
217
228
|
if (objHas(notRouteData.rule, PROP_NAME_RETURN_ROOT)) {
|
|
218
229
|
path += notRouteData.rule[PROP_NAME_RETURN_ROOT];
|
package/test/result.filter.js
CHANGED
|
@@ -35,6 +35,23 @@ describe("notManifestRouteResultFilter", function () {
|
|
|
35
35
|
notManifestRouteResultFilter.filter(notRouteData, reqRes);
|
|
36
36
|
expect(reqRes).to.be.deep.equal({ some: "data" });
|
|
37
37
|
});
|
|
38
|
+
|
|
39
|
+
it("array of objects", function () {
|
|
40
|
+
const reqRes = [
|
|
41
|
+
{ id: 1, _id: 2 },
|
|
42
|
+
{ id: 11, _id: 12 },
|
|
43
|
+
{ id: 21, _id: 22 },
|
|
44
|
+
];
|
|
45
|
+
const notRouteData = {
|
|
46
|
+
rule: { return: ["id"] },
|
|
47
|
+
};
|
|
48
|
+
notManifestRouteResultFilter.filter(notRouteData, reqRes);
|
|
49
|
+
expect(reqRes).to.be.deep.equal([
|
|
50
|
+
{ id: 1 },
|
|
51
|
+
{ id: 11 },
|
|
52
|
+
{ id: 21 },
|
|
53
|
+
]);
|
|
54
|
+
});
|
|
38
55
|
});
|
|
39
56
|
|
|
40
57
|
describe("filterByRule", function () {
|