not-node 6.3.0 → 6.3.2
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/index.js +2 -0
- package/package.json +2 -2
- package/src/auth/const.js +17 -0
- package/src/auth/fields.js +10 -5
- package/src/auth/roles.js +2 -2
- package/src/auth/rules.js +49 -13
- package/src/bootstrap/logic.js +12 -11
- package/src/bootstrap/route.js +1 -1
- package/src/common.js +7 -0
- package/src/fields/filter.js +326 -0
- package/src/fields/index.js +2 -2
- package/src/form/env_extractors/activeUser.js +1 -1
- package/src/form/env_extractors/activeUserId.js +6 -0
- package/src/form/env_extractors/index.js +3 -0
- package/src/form/env_extractors/query.js +6 -0
- package/src/form/fabric.js +3 -3
- package/src/form/form.js +37 -10
- package/src/generic/form.authorizedAction.js +6 -8
- package/src/generic/form.getByID.js +8 -10
- package/src/generic/form.getById.js +8 -9
- package/src/generic/form.listAndCount.js +28 -26
- package/src/generic/logic.js +31 -85
- package/src/identity/index.js +6 -2
- package/src/identity/providers/session.js +14 -12
- package/src/identity/providers/token.js +14 -7
- package/src/init/lib/sessions/index.js +1 -1
- package/src/manifest/manifest.filter.js +118 -17
- package/src/manifest/manifest.js +8 -2
- package/src/manifest/module.js +21 -16
- package/src/manifest/registrator/fields.js +8 -1
- package/src/manifest/registrator/forms.js +1 -0
- package/src/manifest/registrator/locales.js +9 -1
- package/src/manifest/registrator/logics.js +2 -2
- package/src/manifest/registrator/models.js +2 -2
- package/src/manifest/registrator/routes.js +8 -8
- package/src/manifest/result.filter.js +3 -2
- package/src/manifest/route.js +42 -14
- package/src/model/default.js +1 -1
- package/src/model/proto.js +1 -1
- package/src/obsolete.js +23 -7
- package/src/types.js +83 -0
- package/test/auth/fields.js +2 -2
- package/test/auth/obsolete.js +16 -9
- package/test/extractors.js +60 -0
- package/test/filter.js +286 -0
- package/test/init/sessions.js +14 -2
- package/test/notManifestFilter.js +358 -19
- package/test/notModule.js +41 -1
- package/test/transformers.js +21 -0
- package/tmpl/files/module.server/layers/routes.manifest.ejs +9 -0
package/src/form/fabric.js
CHANGED
|
@@ -12,10 +12,10 @@ module.exports = class FormFabric {
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Extracts data
|
|
15
|
-
* @param {
|
|
16
|
-
* @return {Object} forma data
|
|
15
|
+
* @param {import('../types').notNodeExpressRequest} req expressjs request object
|
|
16
|
+
* @return {Promise<Object>} forma data
|
|
17
17
|
**/
|
|
18
|
-
extract(req) {
|
|
18
|
+
async extract(req) {
|
|
19
19
|
return extractor(req);
|
|
20
20
|
}
|
|
21
21
|
};
|
package/src/form/form.js
CHANGED
|
@@ -9,7 +9,7 @@ const { objHas, isFunc, firstLetterToUpper } = require("../common");
|
|
|
9
9
|
const ValidationBuilder = require("not-validation").Builder;
|
|
10
10
|
const ValidationSession = require("not-validation").Session;
|
|
11
11
|
|
|
12
|
-
const { notValidationError, notError } = require("not-error");
|
|
12
|
+
const { notValidationError, notError } = require("not-error/src");
|
|
13
13
|
|
|
14
14
|
const {
|
|
15
15
|
FormExceptionExtractorForFieldIsUndefined,
|
|
@@ -25,11 +25,12 @@ const DEFAULT_TRANSFORMERS = require("./transformers");
|
|
|
25
25
|
**/
|
|
26
26
|
class Form {
|
|
27
27
|
/**
|
|
28
|
-
* @prop {
|
|
28
|
+
* @prop {import('not-validation/src/builder').notValidationSchema} validation schema
|
|
29
29
|
**/
|
|
30
30
|
#SCHEMA = {
|
|
31
31
|
fields: {},
|
|
32
32
|
form: [],
|
|
33
|
+
forms: {},
|
|
33
34
|
};
|
|
34
35
|
/**
|
|
35
36
|
* @prop {string} name of form
|
|
@@ -72,6 +73,13 @@ class Form {
|
|
|
72
73
|
this.#addTransformers(TRANSFORMERS);
|
|
73
74
|
}
|
|
74
75
|
|
|
76
|
+
/**
|
|
77
|
+
*
|
|
78
|
+
*
|
|
79
|
+
* @param {import('../types').notNodeExpressRequest} req
|
|
80
|
+
* @return {*}
|
|
81
|
+
* @memberof Form
|
|
82
|
+
*/
|
|
75
83
|
getModelName(req) {
|
|
76
84
|
if (this.#MODEL_NAME) {
|
|
77
85
|
return this.#MODEL_NAME;
|
|
@@ -81,6 +89,12 @@ class Form {
|
|
|
81
89
|
return undefined;
|
|
82
90
|
}
|
|
83
91
|
|
|
92
|
+
/**
|
|
93
|
+
*
|
|
94
|
+
*
|
|
95
|
+
* @return {string}
|
|
96
|
+
* @memberof Form
|
|
97
|
+
*/
|
|
84
98
|
getModuleName() {
|
|
85
99
|
return this.#MODULE_NAME;
|
|
86
100
|
}
|
|
@@ -88,9 +102,9 @@ class Form {
|
|
|
88
102
|
/**
|
|
89
103
|
* Extract data from ExpressRequest object and validates it
|
|
90
104
|
* returns it or throws
|
|
91
|
-
* @param
|
|
92
|
-
* @return
|
|
93
|
-
* @throws
|
|
105
|
+
* @param {import('../types').notNodeExpressRequest} req expressjs request object
|
|
106
|
+
* @return {Promise<Object>} form data
|
|
107
|
+
* @throws {notValidationError}
|
|
94
108
|
**/
|
|
95
109
|
async run(req) {
|
|
96
110
|
let data = await this.extract(req);
|
|
@@ -100,8 +114,8 @@ class Form {
|
|
|
100
114
|
|
|
101
115
|
/**
|
|
102
116
|
* Extracts data, should be overriden
|
|
103
|
-
* @param {
|
|
104
|
-
* @return {
|
|
117
|
+
* @param {import('../types').notNodeExpressRequest} req expressjs request object
|
|
118
|
+
* @return {Promise<import('../types').PreparedData>} forma data
|
|
105
119
|
**/
|
|
106
120
|
async extract(req) {
|
|
107
121
|
return {
|
|
@@ -137,7 +151,7 @@ class Form {
|
|
|
137
151
|
* if validation failes - returns error object with detail per field description
|
|
138
152
|
* of errors
|
|
139
153
|
* @param {object} data input data for validation
|
|
140
|
-
* @returns {Promise<
|
|
154
|
+
* @returns {Promise<undefined>} resolves or throwing notValidationError or notError if reason is unknown
|
|
141
155
|
**/
|
|
142
156
|
async validate(data) {
|
|
143
157
|
try {
|
|
@@ -205,7 +219,7 @@ class Form {
|
|
|
205
219
|
|
|
206
220
|
/**
|
|
207
221
|
* Returns array of validators
|
|
208
|
-
* @return {
|
|
222
|
+
* @return {Array<Object>}
|
|
209
223
|
**/
|
|
210
224
|
getValidatorsForField(fieldName) {
|
|
211
225
|
return this.#SCHEMA.fields[fieldName];
|
|
@@ -255,7 +269,7 @@ class Form {
|
|
|
255
269
|
/**
|
|
256
270
|
* Validates form data or throws
|
|
257
271
|
* @param {Object} data form data
|
|
258
|
-
* @return {Object}
|
|
272
|
+
* @return {Promise<Object>}
|
|
259
273
|
* @throws {notValidationError}
|
|
260
274
|
**/
|
|
261
275
|
async #_validate(data) {
|
|
@@ -363,6 +377,11 @@ class Form {
|
|
|
363
377
|
}
|
|
364
378
|
}
|
|
365
379
|
|
|
380
|
+
/**
|
|
381
|
+
*
|
|
382
|
+
* @param {import('../types').notNodeExpressRequest} req Express Request
|
|
383
|
+
* @returns {Array<string>|Array<Array<string>>}
|
|
384
|
+
*/
|
|
366
385
|
extractActionFieldsFromRequest(req) {
|
|
367
386
|
if (
|
|
368
387
|
req?.notRouteData?.actionData?.fields &&
|
|
@@ -396,6 +415,13 @@ class Form {
|
|
|
396
415
|
return result;
|
|
397
416
|
}
|
|
398
417
|
|
|
418
|
+
/**
|
|
419
|
+
*
|
|
420
|
+
* @param {import('express').Request} req
|
|
421
|
+
* @param {Array<string>} mainInstruction
|
|
422
|
+
* @param {object} exceptions
|
|
423
|
+
* @returns
|
|
424
|
+
*/
|
|
399
425
|
extractByInstructionsFromRouteActionFields(
|
|
400
426
|
req,
|
|
401
427
|
mainInstruction = ["fromBody", "xss"],
|
|
@@ -411,6 +437,7 @@ class Form {
|
|
|
411
437
|
|
|
412
438
|
/**
|
|
413
439
|
* Value transformers
|
|
440
|
+
* @param {object} transformers
|
|
414
441
|
*/
|
|
415
442
|
#addTransformers(transformers = {}) {
|
|
416
443
|
if (transformers) {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
//DB related validation tools
|
|
2
2
|
const Form = require("../form/form");
|
|
3
3
|
const { firstLetterToUpper } = require("../common");
|
|
4
|
-
//not-node
|
|
5
|
-
const { getIP } = require("../auth");
|
|
6
4
|
//form
|
|
7
5
|
const FIELDS = [
|
|
8
6
|
["activeUserId", { required: true }, "not-node//objectId"],
|
|
@@ -10,18 +8,18 @@ const FIELDS = [
|
|
|
10
8
|
["ip", "not-node//ip"],
|
|
11
9
|
];
|
|
12
10
|
|
|
13
|
-
module.exports = ({ MODULE_NAME, actionName }) => {
|
|
14
|
-
const FORM_NAME = `${MODULE_NAME}:${firstLetterToUpper(
|
|
11
|
+
module.exports = ({ MODULE_NAME, MODEL_NAME, actionName }) => {
|
|
12
|
+
const FORM_NAME = `${MODULE_NAME}:${MODEL_NAME}:${firstLetterToUpper(
|
|
13
|
+
actionName
|
|
14
|
+
)}Form`;
|
|
15
15
|
return class extends Form {
|
|
16
16
|
constructor({ app }) {
|
|
17
17
|
super({ FIELDS, FORM_NAME, app });
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
extract(req) {
|
|
20
|
+
async extract(req) {
|
|
21
21
|
return {
|
|
22
|
-
|
|
23
|
-
activeUserId: req?.user._id,
|
|
24
|
-
ip: getIP(req),
|
|
22
|
+
...this.extractRequestEnvs(req),
|
|
25
23
|
};
|
|
26
24
|
}
|
|
27
25
|
};
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
//DB related validation tools
|
|
2
2
|
const Form = require("../form/form");
|
|
3
|
-
const { firstLetterToUpper
|
|
4
|
-
//not-node
|
|
5
|
-
const { getIP } = require("../auth");
|
|
3
|
+
const { firstLetterToUpper } = require("../common");
|
|
6
4
|
//form
|
|
7
5
|
const FIELDS = [
|
|
8
6
|
["targetID", { required: true }, "not-node//ID"],
|
|
@@ -12,19 +10,19 @@ const FIELDS = [
|
|
|
12
10
|
];
|
|
13
11
|
|
|
14
12
|
module.exports = ({ MODULE_NAME, MODEL_NAME, actionName }) => {
|
|
15
|
-
const FORM_NAME = `${MODULE_NAME}:${firstLetterToUpper(
|
|
13
|
+
const FORM_NAME = `${MODULE_NAME}:${MODEL_NAME}:${firstLetterToUpper(
|
|
14
|
+
actionName
|
|
15
|
+
)}Form`;
|
|
16
16
|
return class extends Form {
|
|
17
17
|
constructor({ app }) {
|
|
18
18
|
super({ FIELDS, FORM_NAME, app });
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
extract(req) {
|
|
22
|
-
const
|
|
21
|
+
async extract(req) {
|
|
22
|
+
const envs = this.extractRequestEnvs(req);
|
|
23
23
|
return {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
activeUserId: req?.user._id,
|
|
27
|
-
ip: getIP(req),
|
|
24
|
+
...envs,
|
|
25
|
+
targetId: envs.modelNameID,
|
|
28
26
|
};
|
|
29
27
|
}
|
|
30
28
|
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
//DB related validation tools
|
|
2
2
|
const Form = require("../form/form");
|
|
3
3
|
const { firstLetterToUpper } = require("../common");
|
|
4
|
-
|
|
5
|
-
const { getIP } = require("../auth");
|
|
4
|
+
|
|
6
5
|
//form
|
|
7
6
|
const FIELDS = [
|
|
8
7
|
["targetId", { required: true }, "not-node//objectId"],
|
|
@@ -11,19 +10,19 @@ const FIELDS = [
|
|
|
11
10
|
["ip", "not-node//ip"],
|
|
12
11
|
];
|
|
13
12
|
|
|
14
|
-
module.exports = ({ MODULE_NAME, actionName }) => {
|
|
15
|
-
const FORM_NAME = `${MODULE_NAME}:${firstLetterToUpper(
|
|
13
|
+
module.exports = ({ MODULE_NAME, MODEL_NAME, actionName }) => {
|
|
14
|
+
const FORM_NAME = `${MODULE_NAME}:${MODEL_NAME}:${firstLetterToUpper(
|
|
15
|
+
actionName
|
|
16
|
+
)}Form`;
|
|
16
17
|
return class extends Form {
|
|
17
18
|
constructor({ app }) {
|
|
18
19
|
super({ FIELDS, FORM_NAME, app });
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
extract(req) {
|
|
22
|
+
async extract(req) {
|
|
23
|
+
const envs = this.extractRequestEnvs(req);
|
|
22
24
|
return {
|
|
23
|
-
|
|
24
|
-
activeUser: req?.user,
|
|
25
|
-
activeUserId: req?.user._id,
|
|
26
|
-
ip: getIP(req),
|
|
25
|
+
...envs,
|
|
27
26
|
};
|
|
28
27
|
}
|
|
29
28
|
};
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
const Form = require("../form/form");
|
|
2
2
|
const { firstLetterToUpper } = require("../common");
|
|
3
|
-
const { getIP } = require("../auth");
|
|
4
3
|
const notFilter = require("not-filter");
|
|
5
|
-
const getApp = require("../getApp");
|
|
6
4
|
|
|
7
5
|
const FIELDS = [
|
|
8
6
|
["query", `not-filter//_filterQuery`],
|
|
@@ -11,42 +9,46 @@ const FIELDS = [
|
|
|
11
9
|
["ip", "not-node//ip"],
|
|
12
10
|
];
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Generates generic form to get perform list and count action
|
|
14
|
+
*
|
|
15
|
+
* @param {object} params
|
|
16
|
+
* @param {string} params.MODULE_NAME //module name
|
|
17
|
+
* @param {string} params.MODEL_NAME //model name
|
|
18
|
+
* @param {string} params.actionName //action name
|
|
19
|
+
* @return {Form} form class definition
|
|
20
|
+
*/
|
|
21
|
+
const FactoryFormListAndCount = ({ MODULE_NAME, MODEL_NAME, actionName }) => {
|
|
15
22
|
const FORM_NAME = `${MODULE_NAME}:${MODEL_NAME}:${firstLetterToUpper(
|
|
16
23
|
actionName
|
|
17
24
|
)}Form`;
|
|
25
|
+
|
|
18
26
|
return class extends Form {
|
|
19
27
|
constructor({ app }) {
|
|
20
28
|
super({ FIELDS, FORM_NAME, app });
|
|
21
29
|
}
|
|
22
30
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
*
|
|
34
|
+
* @param {import('../types').notNodeExpressRequest} req
|
|
35
|
+
* @return {Promise<import('../types').PreparedData>}
|
|
36
|
+
*/
|
|
37
|
+
async extract(req) {
|
|
38
|
+
const envs = this.extractRequestEnvs(req);
|
|
32
39
|
if (!req.user.isRoot() && !req.user.isAdmin()) {
|
|
33
|
-
filter = notFilter.filter.modifyRules(
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
envs.query.filter = notFilter.filter.modifyRules(
|
|
41
|
+
envs.query.filter,
|
|
42
|
+
{
|
|
43
|
+
owner: req.user._id,
|
|
44
|
+
}
|
|
45
|
+
);
|
|
36
46
|
}
|
|
37
|
-
|
|
38
47
|
return {
|
|
39
|
-
|
|
40
|
-
skip,
|
|
41
|
-
size,
|
|
42
|
-
sorter,
|
|
43
|
-
filter,
|
|
44
|
-
search,
|
|
45
|
-
},
|
|
46
|
-
activeUser: req?.user,
|
|
47
|
-
activeUserId: req?.user._id,
|
|
48
|
-
ip: getIP(req),
|
|
48
|
+
...envs,
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
52
|
};
|
|
53
|
+
|
|
54
|
+
module.exports = FactoryFormListAndCount;
|
package/src/generic/logic.js
CHANGED
|
@@ -58,6 +58,11 @@ module.exports = ({
|
|
|
58
58
|
static isOwner = isOwner;
|
|
59
59
|
static ownerFieldName = ownerFieldName;
|
|
60
60
|
|
|
61
|
+
/**
|
|
62
|
+
*
|
|
63
|
+
* @param {import('../types').PreparedData} prepared
|
|
64
|
+
* @returns {Promise<Object>}
|
|
65
|
+
*/
|
|
61
66
|
static async _create({
|
|
62
67
|
action,
|
|
63
68
|
data,
|
|
@@ -92,11 +97,7 @@ module.exports = ({
|
|
|
92
97
|
|
|
93
98
|
/**
|
|
94
99
|
* create item
|
|
95
|
-
* @param {
|
|
96
|
-
* @param {Object} prepared.data data extracted from request
|
|
97
|
-
* @param {Object} prepared.activeUser current user info
|
|
98
|
-
* @param {string} prepared.ip current user ip
|
|
99
|
-
* @param {boolean} prepared.root current user is root
|
|
100
|
+
* @param {import('../types').PreparedData} prepared
|
|
100
101
|
* @returns {Promise<Object>} new document
|
|
101
102
|
**/
|
|
102
103
|
static async create({ data, activeUser, ip, root = false }) {
|
|
@@ -112,11 +113,7 @@ module.exports = ({
|
|
|
112
113
|
|
|
113
114
|
/**
|
|
114
115
|
* create item and own it
|
|
115
|
-
* @param {
|
|
116
|
-
* @param {Object} prepared.data data extracted from request
|
|
117
|
-
* @param {Object} prepared.activeUser current user info
|
|
118
|
-
* @param {string} prepared.ip current user ip
|
|
119
|
-
* @param {boolean} prepared.root current user is root
|
|
116
|
+
* @param {import('../types').PreparedData} prepared
|
|
120
117
|
* @returns {Promise<Object>} new document
|
|
121
118
|
**/
|
|
122
119
|
static async createOwn({ data, activeUser, ip, root = false }) {
|
|
@@ -130,6 +127,11 @@ module.exports = ({
|
|
|
130
127
|
});
|
|
131
128
|
}
|
|
132
129
|
|
|
130
|
+
/**
|
|
131
|
+
*
|
|
132
|
+
* @param {import('../types').PreparedData} prepared
|
|
133
|
+
* @returns {Promise<Object>}
|
|
134
|
+
*/
|
|
133
135
|
static async _updateOne({
|
|
134
136
|
targetId,
|
|
135
137
|
data,
|
|
@@ -169,12 +171,7 @@ module.exports = ({
|
|
|
169
171
|
|
|
170
172
|
/**
|
|
171
173
|
* update item
|
|
172
|
-
* @param {
|
|
173
|
-
* @param {Object} prepared.targetId target item _id
|
|
174
|
-
* @param {Object} prepared.data data extracted from request
|
|
175
|
-
* @param {Object} prepared.activeUser current user info
|
|
176
|
-
* @param {string} prepared.ip current user ip
|
|
177
|
-
* @param {boolean} prepared.root current user is root
|
|
174
|
+
* @param {import('../types').PreparedData} prepared
|
|
178
175
|
* @returns {Promise<Object>} updated document
|
|
179
176
|
**/
|
|
180
177
|
static async update({ targetId, data, activeUser, ip, root = false }) {
|
|
@@ -191,12 +188,7 @@ module.exports = ({
|
|
|
191
188
|
|
|
192
189
|
/**
|
|
193
190
|
* update own item
|
|
194
|
-
* @param {
|
|
195
|
-
* @param {Object} prepared.targetId target item _id
|
|
196
|
-
* @param {Object} prepared.data data extracted from request
|
|
197
|
-
* @param {Object} prepared.activeUser current user info
|
|
198
|
-
* @param {string} prepared.ip current user ip
|
|
199
|
-
* @param {boolean} prepared.root current user is root
|
|
191
|
+
* @param {import('../types').PreparedData} prepared
|
|
200
192
|
* @returns {Promise<Object>} updated document
|
|
201
193
|
**/
|
|
202
194
|
static async updateOwn({
|
|
@@ -219,12 +211,7 @@ module.exports = ({
|
|
|
219
211
|
|
|
220
212
|
/**
|
|
221
213
|
* get item with populated sub-documents
|
|
222
|
-
* @param {
|
|
223
|
-
* @param {Object} prepared.targetId target item _id
|
|
224
|
-
* @param {Object} prepared.activeUser current user info
|
|
225
|
-
* @param {string} prepared.ip current user ip
|
|
226
|
-
* @param {boolean} prepared.root current user is root
|
|
227
|
-
* @param {boolean} prepared.shouldOwn if user should be owner of target
|
|
214
|
+
* @param {import('../types').PreparedData} prepared
|
|
228
215
|
* @returns {Promise<Object>} requested document
|
|
229
216
|
**/
|
|
230
217
|
static async _getOne({
|
|
@@ -269,11 +256,7 @@ module.exports = ({
|
|
|
269
256
|
|
|
270
257
|
/**
|
|
271
258
|
* get item with populated sub-documents
|
|
272
|
-
* @param {
|
|
273
|
-
* @param {Object} prepared.targetId target item _id
|
|
274
|
-
* @param {Object} prepared.activeUser current user info
|
|
275
|
-
* @param {string} prepared.ip current user ip
|
|
276
|
-
* @param {boolean} prepared.root current user is root
|
|
259
|
+
* @param {import('../types').PreparedData} prepared
|
|
277
260
|
* @returns {Promise<Object>} requested document
|
|
278
261
|
**/
|
|
279
262
|
static async get({ targetId, activeUser, ip, root = false }) {
|
|
@@ -289,11 +272,7 @@ module.exports = ({
|
|
|
289
272
|
|
|
290
273
|
/**
|
|
291
274
|
* get activeUser own item with populated sub-documents
|
|
292
|
-
* @param {
|
|
293
|
-
* @param {Object} prepared.targetId target item _id
|
|
294
|
-
* @param {Object} prepared.activeUser current user info
|
|
295
|
-
* @param {string} prepared.ip current user ip
|
|
296
|
-
* @param {boolean} prepared.root current user is root
|
|
275
|
+
* @param {import('../types').PreparedData} prepared
|
|
297
276
|
* @returns {Promise<Object>} requested document
|
|
298
277
|
**/
|
|
299
278
|
static async getOwn({ targetId, activeUser, ip, root = false }) {
|
|
@@ -309,12 +288,7 @@ module.exports = ({
|
|
|
309
288
|
|
|
310
289
|
/**
|
|
311
290
|
* get item with populated sub-documents
|
|
312
|
-
* @param {
|
|
313
|
-
* @param {Object} prepared.targetID target item ID
|
|
314
|
-
* @param {Object} prepared.activeUser current user info
|
|
315
|
-
* @param {string} prepared.ip current user ip
|
|
316
|
-
* @param {boolean} prepared.root current user is root
|
|
317
|
-
* @param {boolean} prepared.shouldOwn if user should be owner of target
|
|
291
|
+
* @param {import('../types').PreparedData} prepared
|
|
318
292
|
* @returns {Promise<Object>} requested document
|
|
319
293
|
**/
|
|
320
294
|
static async _getOneByID({
|
|
@@ -363,11 +337,7 @@ module.exports = ({
|
|
|
363
337
|
|
|
364
338
|
/**
|
|
365
339
|
* get item with populated sub-documents
|
|
366
|
-
* @param {
|
|
367
|
-
* @param {Object} prepared.targetID target item ID
|
|
368
|
-
* @param {Object} prepared.activeUser current user info
|
|
369
|
-
* @param {string} prepared.ip current user ip
|
|
370
|
-
* @param {boolean} prepared.root current user is root
|
|
340
|
+
* @param {import('../types').PreparedData} prepared
|
|
371
341
|
* @returns {Promise<Object>} requested document
|
|
372
342
|
**/
|
|
373
343
|
static async getByID({ targetID, activeUser, ip, root = false }) {
|
|
@@ -383,11 +353,7 @@ module.exports = ({
|
|
|
383
353
|
|
|
384
354
|
/**
|
|
385
355
|
* get activeUser own item with populated sub-documents
|
|
386
|
-
* @param {
|
|
387
|
-
* @param {Object} prepared.targetID target item ID
|
|
388
|
-
* @param {Object} prepared.activeUser current user info
|
|
389
|
-
* @param {string} prepared.ip current user ip
|
|
390
|
-
* @param {boolean} prepared.root current user is root
|
|
356
|
+
* @param {import('../types').PreparedData} prepared
|
|
391
357
|
* @returns {Promise<Object>} requested document
|
|
392
358
|
**/
|
|
393
359
|
static async getByIDOwn({ targetID, activeUser, ip, root = false }) {
|
|
@@ -403,12 +369,7 @@ module.exports = ({
|
|
|
403
369
|
|
|
404
370
|
/**
|
|
405
371
|
* get item without populated sub-documents
|
|
406
|
-
* @param {
|
|
407
|
-
* @param {Object} prepared.targetId target item _id
|
|
408
|
-
* @param {Object} prepared.activeUser current user info
|
|
409
|
-
* @param {string} prepared.ip current user ip
|
|
410
|
-
* @param {boolean} prepared.root current user is root
|
|
411
|
-
* @param {boolean} prepared.shouldOwn if user should be owner of target
|
|
372
|
+
* @param {import('../types').PreparedData} prepared
|
|
412
373
|
* @returns {Promise<Object>} requested document
|
|
413
374
|
**/
|
|
414
375
|
static async _getOneRaw({
|
|
@@ -448,11 +409,7 @@ module.exports = ({
|
|
|
448
409
|
|
|
449
410
|
/**
|
|
450
411
|
* get item without populated sub-documents
|
|
451
|
-
* @param {
|
|
452
|
-
* @param {Object} prepared.targetId target item _id
|
|
453
|
-
* @param {Object} prepared.activeUser current user info
|
|
454
|
-
* @param {string} prepared.ip current user ip
|
|
455
|
-
* @param {boolean} prepared.root current user is root
|
|
412
|
+
* @param {import('../types').PreparedData} prepared
|
|
456
413
|
* @returns {Promise<Object>} requested document
|
|
457
414
|
**/
|
|
458
415
|
static async getRaw({ targetId, activeUser, ip, root = false }) {
|
|
@@ -468,11 +425,7 @@ module.exports = ({
|
|
|
468
425
|
|
|
469
426
|
/**
|
|
470
427
|
* get item without populated sub-documents, if it's owned by activeUser
|
|
471
|
-
* @param {
|
|
472
|
-
* @param {Object} prepared.targetId target item _id
|
|
473
|
-
* @param {Object} prepared.activeUser current user info
|
|
474
|
-
* @param {string} prepared.ip current user ip
|
|
475
|
-
* @param {boolean} prepared.root current user is root
|
|
428
|
+
* @param {import('../types').PreparedData} prepared
|
|
476
429
|
* @returns {Promise<Object>} requested document
|
|
477
430
|
**/
|
|
478
431
|
static async getOwnRaw({ targetId, activeUser, ip, root = false }) {
|
|
@@ -488,11 +441,7 @@ module.exports = ({
|
|
|
488
441
|
|
|
489
442
|
/**
|
|
490
443
|
* removes item by id, if activeUser is its owner
|
|
491
|
-
* @param {
|
|
492
|
-
* @param {Object} prepared.targetId target item _id
|
|
493
|
-
* @param {Object} prepared.activeUser current user info
|
|
494
|
-
* @param {string} prepared.ip current user ip
|
|
495
|
-
* @param {boolean} prepared.root current user is root
|
|
444
|
+
* @param {import('../types').PreparedData} prepared
|
|
496
445
|
* @returns {Promise<Object>} requested document
|
|
497
446
|
**/
|
|
498
447
|
static async _delete({
|
|
@@ -562,11 +511,7 @@ module.exports = ({
|
|
|
562
511
|
|
|
563
512
|
/**
|
|
564
513
|
* removes item by id
|
|
565
|
-
* @param {
|
|
566
|
-
* @param {Object} prepared.targetId target item _id
|
|
567
|
-
* @param {Object} prepared.activeUser current user info
|
|
568
|
-
* @param {string} prepared.ip current user ip
|
|
569
|
-
* @param {boolean} prepared.root current user is root
|
|
514
|
+
* @param {import('../types').PreparedData} prepared
|
|
570
515
|
* @returns {Promise<Object>} requested document
|
|
571
516
|
**/
|
|
572
517
|
static async delete({ targetId, activeUser, ip, root = false }) {
|
|
@@ -582,11 +527,7 @@ module.exports = ({
|
|
|
582
527
|
|
|
583
528
|
/**
|
|
584
529
|
* removes item by id, if activeUser is its owner
|
|
585
|
-
* @param {
|
|
586
|
-
* @param {Object} prepared.targetId target item _id
|
|
587
|
-
* @param {Object} prepared.activeUser current user info
|
|
588
|
-
* @param {string} prepared.ip current user ip
|
|
589
|
-
* @param {boolean} prepared.root current user is root
|
|
530
|
+
* @param {import('../types').PreparedData} prepared
|
|
590
531
|
* @returns {Promise<Object>} requested document
|
|
591
532
|
**/
|
|
592
533
|
static async deleteOwn({ targetId, activeUser, ip, root = false }) {
|
|
@@ -600,6 +541,11 @@ module.exports = ({
|
|
|
600
541
|
});
|
|
601
542
|
}
|
|
602
543
|
|
|
544
|
+
/**
|
|
545
|
+
*
|
|
546
|
+
* @param {import('../types').PreparedData} prepared
|
|
547
|
+
* @returns {Promise<Array<Object>>}
|
|
548
|
+
*/
|
|
603
549
|
static async _listAll({
|
|
604
550
|
activeUser,
|
|
605
551
|
ip,
|
package/src/identity/index.js
CHANGED
|
@@ -14,8 +14,8 @@ module.exports = class notAppIdentity {
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Collects various authentification and authorization data from request object
|
|
17
|
-
* @
|
|
18
|
-
*
|
|
17
|
+
* @param {import('../types').notNodeExpressRequest} req ExpressRequest
|
|
18
|
+
* @return {object} various authentification data for actor { root:boolean, auth: boolean, role: [string], uid: ObjectId, sid: string, ip:string }
|
|
19
19
|
*/
|
|
20
20
|
static extractAuthData(req) {
|
|
21
21
|
const identity = this.#identity.of(req);
|
|
@@ -30,6 +30,10 @@ module.exports = class notAppIdentity {
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param {import('../types').notNodeExpressRequest} req
|
|
36
|
+
*/
|
|
33
37
|
constructor(req) {
|
|
34
38
|
return notAppIdentity.identity.of(req);
|
|
35
39
|
}
|
|
@@ -41,16 +41,18 @@ module.exports = class IdentityProviderSession {
|
|
|
41
41
|
**/
|
|
42
42
|
getPrimaryRole() {
|
|
43
43
|
const roles = this.getRole();
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
44
|
+
if (Array.isArray(roles)) {
|
|
45
|
+
for (let role of roles) {
|
|
46
|
+
if (
|
|
47
|
+
Array.isArray(
|
|
48
|
+
IdentityProviderSession.#getOptions().primaryRoles
|
|
49
|
+
) &&
|
|
50
|
+
IdentityProviderSession.#getOptions().primaryRoles.includes(
|
|
51
|
+
role
|
|
52
|
+
)
|
|
53
|
+
) {
|
|
54
|
+
return role;
|
|
55
|
+
}
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
return CONST.DEFAULT_USER_ROLE_FOR_GUEST;
|
|
@@ -58,7 +60,7 @@ module.exports = class IdentityProviderSession {
|
|
|
58
60
|
|
|
59
61
|
/**
|
|
60
62
|
* Returns user role from request object
|
|
61
|
-
* @return {Array<string
|
|
63
|
+
* @return {Array<string>|undefined} user role
|
|
62
64
|
**/
|
|
63
65
|
getRole() {
|
|
64
66
|
const req = this.req;
|
|
@@ -133,7 +135,7 @@ module.exports = class IdentityProviderSession {
|
|
|
133
135
|
/**
|
|
134
136
|
* Set auth data in session, user id and role
|
|
135
137
|
* @param {string} id user id
|
|
136
|
-
* @param {string} role user role
|
|
138
|
+
* @param {Array<string>} role user role
|
|
137
139
|
**/
|
|
138
140
|
setAuth(id, role) {
|
|
139
141
|
this.setUserId(id);
|