not-node 6.5.7 → 6.5.8
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/generic/field._data.js +1 -1
- package/src/identity/index.js +12 -8
- package/src/manifest/manifest.filter.js +2 -3
- package/src/manifest/route.js +15 -7
- package/test/fakes.js +21 -0
- package/test/notRoute.js +13 -10
package/package.json
CHANGED
|
@@ -22,7 +22,7 @@ const initGenericDataForm = ({
|
|
|
22
22
|
});
|
|
23
23
|
const App = getApp();
|
|
24
24
|
App.getModule(MODULE_NAME).setFormConstructor(formName, cls);
|
|
25
|
-
App.getModule(MODULE_NAME).setForm(formName, new cls(App));
|
|
25
|
+
App.getModule(MODULE_NAME).setForm(formName, new cls({ app: App }));
|
|
26
26
|
return true;
|
|
27
27
|
} catch (e) {
|
|
28
28
|
getApp().logger.error(e);
|
package/src/identity/index.js
CHANGED
|
@@ -12,13 +12,7 @@ module.exports = class notAppIdentity {
|
|
|
12
12
|
return this.#identity;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
* Collects various authentification and authorization data from request object
|
|
17
|
-
* @param {import('../types').notNodeExpressRequest} req ExpressRequest
|
|
18
|
-
* @return {import('../types').notAppIdentityData} various authentification data for actor { root:boolean, auth: boolean, role: [string], uid: ObjectId, sid: string, ip:string }
|
|
19
|
-
*/
|
|
20
|
-
static extractAuthData(req) {
|
|
21
|
-
const identity = this.#identity.of(req);
|
|
15
|
+
static identityToAuthData(identity, req) {
|
|
22
16
|
return {
|
|
23
17
|
root: identity.isRoot(),
|
|
24
18
|
admin: identity.isAdmin(),
|
|
@@ -27,11 +21,21 @@ module.exports = class notAppIdentity {
|
|
|
27
21
|
primaryRole: identity.getPrimaryRole(),
|
|
28
22
|
uid: identity.getUserId(),
|
|
29
23
|
sid: identity.getSessionId(),
|
|
30
|
-
ip: getIP(req),
|
|
24
|
+
ip: req ? getIP(req) : undefined,
|
|
31
25
|
provider: identity.constructor.name,
|
|
32
26
|
};
|
|
33
27
|
}
|
|
34
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Collects various authentification and authorization data from request object
|
|
31
|
+
* @param {import('../types').notNodeExpressRequest} req ExpressRequest
|
|
32
|
+
* @return {import('../types').notAppIdentityData} various authentification data for actor { root:boolean, auth: boolean, role: [string], uid: ObjectId, sid: string, ip:string }
|
|
33
|
+
*/
|
|
34
|
+
static extractAuthData(req) {
|
|
35
|
+
const identity = this.#identity.of(req);
|
|
36
|
+
return this.identityToAuthData(identity, req);
|
|
37
|
+
}
|
|
38
|
+
|
|
35
39
|
/**
|
|
36
40
|
*
|
|
37
41
|
* @param {import('../types').notNodeExpressRequest} req
|
|
@@ -41,7 +41,6 @@ module.exports = class notManifestFilter {
|
|
|
41
41
|
if (!route || !route.actions) {
|
|
42
42
|
return result;
|
|
43
43
|
}
|
|
44
|
-
console.log("actions", JSON.stringify(route.actions));
|
|
45
44
|
for (let actionName in route.actions) {
|
|
46
45
|
if (!route.actions[actionName]) {
|
|
47
46
|
continue;
|
|
@@ -136,7 +135,7 @@ module.exports = class notManifestFilter {
|
|
|
136
135
|
**/
|
|
137
136
|
|
|
138
137
|
static filter(manifest, auth, role, root, moduleName = "") {
|
|
139
|
-
|
|
138
|
+
const result = {};
|
|
140
139
|
for (let routeName in manifest) {
|
|
141
140
|
let routeMan = notManifestFilter.filterRoute(
|
|
142
141
|
manifest[routeName],
|
|
@@ -338,7 +337,7 @@ module.exports = class notManifestFilter {
|
|
|
338
337
|
ruleSet = null
|
|
339
338
|
) {
|
|
340
339
|
//full copy
|
|
341
|
-
|
|
340
|
+
const actionRule = merge({}, action);
|
|
342
341
|
//removes server side or secret information (full list of access rules)
|
|
343
342
|
notManifestFilter.clearFromDirtyFields(actionRule);
|
|
344
343
|
//retrives model schema
|
package/src/manifest/route.js
CHANGED
|
@@ -80,10 +80,9 @@ class notRoute {
|
|
|
80
80
|
* @param {import('../types').notNodeExpressRequest} req Express Request Object
|
|
81
81
|
* @return {import('../types').notRouteRule | null} rule or null
|
|
82
82
|
*/
|
|
83
|
-
selectRule(
|
|
84
|
-
const user = notAppIdentity.extractAuthData(req);
|
|
83
|
+
selectRule(identity) {
|
|
85
84
|
if (this.actionData) {
|
|
86
|
-
return notRoute.actionAvailableByRule(this.actionData,
|
|
85
|
+
return notRoute.actionAvailableByRule(this.actionData, identity);
|
|
87
86
|
}
|
|
88
87
|
return null;
|
|
89
88
|
}
|
|
@@ -107,7 +106,15 @@ class notRoute {
|
|
|
107
106
|
* @return {import('../types').notRouteData}
|
|
108
107
|
* @memberof notRoute
|
|
109
108
|
*/
|
|
110
|
-
createRequestRouteData(actionName, rule) {
|
|
109
|
+
createRequestRouteData(actionName, rule, identity) {
|
|
110
|
+
const actionRule = notManifestFilter.filterRouteAction(
|
|
111
|
+
this.actionData,
|
|
112
|
+
identity.auth,
|
|
113
|
+
identity.role,
|
|
114
|
+
identity.root,
|
|
115
|
+
this.routeName,
|
|
116
|
+
this.moduleName
|
|
117
|
+
);
|
|
111
118
|
return {
|
|
112
119
|
actionName,
|
|
113
120
|
modelName: this.routeName,
|
|
@@ -116,7 +123,7 @@ class notRoute {
|
|
|
116
123
|
this.routeName
|
|
117
124
|
)}`,
|
|
118
125
|
rule: copyObj(rule),
|
|
119
|
-
actionData:
|
|
126
|
+
actionData: actionRule,
|
|
120
127
|
actionSignature: notManifestFilter.detectActionSignature(
|
|
121
128
|
this.actionData
|
|
122
129
|
),
|
|
@@ -132,7 +139,8 @@ class notRoute {
|
|
|
132
139
|
**/
|
|
133
140
|
exec(req, res, next) {
|
|
134
141
|
try {
|
|
135
|
-
|
|
142
|
+
const identity = notAppIdentity.extractAuthData(req);
|
|
143
|
+
const rule = this.selectRule(identity);
|
|
136
144
|
if (!rule) {
|
|
137
145
|
return next(
|
|
138
146
|
new HttpError(
|
|
@@ -166,7 +174,7 @@ class notRoute {
|
|
|
166
174
|
const modRoute = mod.getRoute(this.routeName);
|
|
167
175
|
this.setRequestRouteData(
|
|
168
176
|
req,
|
|
169
|
-
this.createRequestRouteData(actionName, rule)
|
|
177
|
+
this.createRequestRouteData(actionName, rule, identity)
|
|
170
178
|
);
|
|
171
179
|
if (this.routeIsRunnable(modRoute, actionName)) {
|
|
172
180
|
return this.executeRoute(modRoute, actionName, {
|
package/test/fakes.js
CHANGED
|
@@ -10,6 +10,27 @@ module.exports = {
|
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
12
|
},
|
|
13
|
+
fakeAuthData: ({
|
|
14
|
+
root = false,
|
|
15
|
+
admin = false,
|
|
16
|
+
auth = false,
|
|
17
|
+
role = [DEFAULT_USER_ROLE_FOR_GUEST],
|
|
18
|
+
primaryRole = DEFAULT_USER_ROLE_FOR_GUEST,
|
|
19
|
+
uid = undefined,
|
|
20
|
+
sid = undefined,
|
|
21
|
+
ip = undefined,
|
|
22
|
+
}) => {
|
|
23
|
+
return {
|
|
24
|
+
root,
|
|
25
|
+
admin,
|
|
26
|
+
auth,
|
|
27
|
+
role,
|
|
28
|
+
primaryRole,
|
|
29
|
+
uid,
|
|
30
|
+
sid,
|
|
31
|
+
ip,
|
|
32
|
+
};
|
|
33
|
+
},
|
|
13
34
|
fakeIdentity: (
|
|
14
35
|
id = {
|
|
15
36
|
root: false,
|
package/test/notRoute.js
CHANGED
|
@@ -27,21 +27,23 @@ describe("notRoute", function () {
|
|
|
27
27
|
|
|
28
28
|
describe("selectRule", function () {
|
|
29
29
|
it("User(auth) request, post.list action", function () {
|
|
30
|
-
|
|
30
|
+
const authData = require("./fakes").fakeAuthData({
|
|
31
31
|
auth: true,
|
|
32
|
+
role: ["user"],
|
|
33
|
+
primaryRole: "user",
|
|
32
34
|
});
|
|
33
35
|
let req = {},
|
|
34
36
|
actionData = {
|
|
35
37
|
method: "get",
|
|
36
38
|
rules: [
|
|
37
39
|
{
|
|
38
|
-
|
|
40
|
+
root: true,
|
|
39
41
|
},
|
|
40
42
|
{
|
|
41
43
|
auth: true,
|
|
42
44
|
},
|
|
43
45
|
{
|
|
44
|
-
|
|
46
|
+
auth: false,
|
|
45
47
|
},
|
|
46
48
|
],
|
|
47
49
|
},
|
|
@@ -52,12 +54,12 @@ describe("notRoute", function () {
|
|
|
52
54
|
"list",
|
|
53
55
|
actionData
|
|
54
56
|
);
|
|
55
|
-
expect(routerAction.selectRule(
|
|
57
|
+
expect(routerAction.selectRule(authData)).to.deep.equal({
|
|
56
58
|
auth: true,
|
|
57
59
|
});
|
|
58
60
|
});
|
|
59
61
|
it("User(!auth) request, post.list action", function () {
|
|
60
|
-
|
|
62
|
+
const authData = require("./fakes").fakeAuthData({
|
|
61
63
|
auth: false,
|
|
62
64
|
});
|
|
63
65
|
let req = {},
|
|
@@ -82,7 +84,7 @@ describe("notRoute", function () {
|
|
|
82
84
|
"list",
|
|
83
85
|
actionData
|
|
84
86
|
);
|
|
85
|
-
expect(routerAction.selectRule(
|
|
87
|
+
expect(routerAction.selectRule(authData)).to.deep.equal({
|
|
86
88
|
auth: false,
|
|
87
89
|
});
|
|
88
90
|
});
|
|
@@ -112,9 +114,10 @@ describe("notRoute", function () {
|
|
|
112
114
|
});
|
|
113
115
|
|
|
114
116
|
it("User(auth, manager) request, post.listAll action", function () {
|
|
115
|
-
|
|
117
|
+
const authData = require("./fakes").fakeAuthData({
|
|
116
118
|
auth: true,
|
|
117
119
|
role: ["manager"],
|
|
120
|
+
primaryRole: "admin",
|
|
118
121
|
});
|
|
119
122
|
let req = {},
|
|
120
123
|
actionData = {
|
|
@@ -136,14 +139,14 @@ describe("notRoute", function () {
|
|
|
136
139
|
"listAll",
|
|
137
140
|
actionData
|
|
138
141
|
);
|
|
139
|
-
expect(routerAction.selectRule(
|
|
142
|
+
expect(routerAction.selectRule(authData)).to.deep.equal({
|
|
140
143
|
auth: true,
|
|
141
144
|
role: ["manager"],
|
|
142
145
|
});
|
|
143
146
|
});
|
|
144
147
|
|
|
145
148
|
it("Admin request, post.listAll action", function () {
|
|
146
|
-
|
|
149
|
+
const authData = require("./fakes").fakeAuthData({
|
|
147
150
|
auth: true,
|
|
148
151
|
root: true,
|
|
149
152
|
primaryRole: DEFAULT_USER_ROLE_FOR_ROOT,
|
|
@@ -169,7 +172,7 @@ describe("notRoute", function () {
|
|
|
169
172
|
"listAll",
|
|
170
173
|
actionData
|
|
171
174
|
);
|
|
172
|
-
expect(routerAction.selectRule(
|
|
175
|
+
expect(routerAction.selectRule(authData)).to.deep.equal({
|
|
173
176
|
root: true,
|
|
174
177
|
});
|
|
175
178
|
});
|