@nocobase/plugin-users 0.7.1-alpha.5 → 0.7.2-alpha.1
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/lib/middlewares/parseToken.js +37 -2
- package/lib/server.js +25 -4
- package/package.json +5 -4
|
@@ -6,6 +6,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.parseToken = parseToken;
|
|
7
7
|
exports.setCurrentRole = setCurrentRole;
|
|
8
8
|
|
|
9
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
10
|
+
|
|
11
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
12
|
+
|
|
13
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
14
|
+
|
|
15
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
16
|
+
|
|
17
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
18
|
+
|
|
19
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
20
|
+
|
|
21
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
22
|
+
|
|
9
23
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
10
24
|
|
|
11
25
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
@@ -79,11 +93,32 @@ function _findUserByToken() {
|
|
|
79
93
|
const _yield$plugin$jwtServ = yield plugin.jwtService.decode(token),
|
|
80
94
|
userId = _yield$plugin$jwtServ.userId;
|
|
81
95
|
|
|
96
|
+
const collection = ctx.db.getCollection('users');
|
|
97
|
+
const appends = ['roles'];
|
|
98
|
+
|
|
99
|
+
var _iterator = _createForOfIteratorHelper(collection.fields),
|
|
100
|
+
_step;
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
104
|
+
const _step$value = _slicedToArray(_step.value, 2),
|
|
105
|
+
field = _step$value[1];
|
|
106
|
+
|
|
107
|
+
if (field.type === 'belongsTo') {
|
|
108
|
+
appends.push(field.name);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
} catch (err) {
|
|
112
|
+
_iterator.e(err);
|
|
113
|
+
} finally {
|
|
114
|
+
_iterator.f();
|
|
115
|
+
}
|
|
116
|
+
|
|
82
117
|
return yield ctx.db.getRepository('users').findOne({
|
|
118
|
+
appends,
|
|
83
119
|
filter: {
|
|
84
120
|
id: userId
|
|
85
|
-
}
|
|
86
|
-
appends: ['roles']
|
|
121
|
+
}
|
|
87
122
|
});
|
|
88
123
|
} catch (error) {
|
|
89
124
|
return null;
|
package/lib/server.js
CHANGED
|
@@ -25,6 +25,16 @@ function _server() {
|
|
|
25
25
|
return data;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
function _jsonTemplates() {
|
|
29
|
+
const data = _interopRequireDefault(require("json-templates"));
|
|
30
|
+
|
|
31
|
+
_jsonTemplates = function _jsonTemplates() {
|
|
32
|
+
return data;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
|
|
28
38
|
function _path() {
|
|
29
39
|
const data = require("path");
|
|
30
40
|
|
|
@@ -51,6 +61,8 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
51
61
|
|
|
52
62
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
53
63
|
|
|
64
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
65
|
+
|
|
54
66
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
55
67
|
|
|
56
68
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -97,6 +109,17 @@ class UsersPlugin extends _server().Plugin {
|
|
|
97
109
|
return {
|
|
98
110
|
[_database().Op.eq]: (ctx === null || ctx === void 0 ? void 0 : (_ctx$app = ctx.app) === null || _ctx$app === void 0 ? void 0 : (_ctx$app$ctx = _ctx$app.ctx) === null || _ctx$app$ctx === void 0 ? void 0 : (_ctx$app$ctx$state = _ctx$app$ctx.state) === null || _ctx$app$ctx$state === void 0 ? void 0 : (_ctx$app$ctx$state$cu = _ctx$app$ctx$state.currentUser) === null || _ctx$app$ctx$state$cu === void 0 ? void 0 : _ctx$app$ctx$state$cu.id) || -1
|
|
99
111
|
};
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
$isVar(val, ctx) {
|
|
115
|
+
var _ctx$app2, _ctx$app2$ctx;
|
|
116
|
+
|
|
117
|
+
const obj = (0, _jsonTemplates().default)({
|
|
118
|
+
val: `{{${val}}}`
|
|
119
|
+
})(JSON.parse(JSON.stringify(ctx === null || ctx === void 0 ? void 0 : (_ctx$app2 = ctx.app) === null || _ctx$app2 === void 0 ? void 0 : (_ctx$app2$ctx = _ctx$app2.ctx) === null || _ctx$app2$ctx === void 0 ? void 0 : _ctx$app2$ctx.state)));
|
|
120
|
+
return {
|
|
121
|
+
[_database().Op.eq]: obj.val
|
|
122
|
+
};
|
|
100
123
|
}
|
|
101
124
|
|
|
102
125
|
});
|
|
@@ -148,8 +171,7 @@ class UsersPlugin extends _server().Plugin {
|
|
|
148
171
|
dataIndex: 'state.currentUser.id',
|
|
149
172
|
createOnly: true,
|
|
150
173
|
visible: true,
|
|
151
|
-
|
|
152
|
-
onUpdate: 'CASCADE'
|
|
174
|
+
index: true
|
|
153
175
|
});
|
|
154
176
|
collection.setField('createdBy', {
|
|
155
177
|
type: 'belongsTo',
|
|
@@ -165,8 +187,7 @@ class UsersPlugin extends _server().Plugin {
|
|
|
165
187
|
dataType: 'integer',
|
|
166
188
|
dataIndex: 'state.currentUser.id',
|
|
167
189
|
visible: true,
|
|
168
|
-
|
|
169
|
-
onUpdate: 'CASCADE'
|
|
190
|
+
index: true
|
|
170
191
|
});
|
|
171
192
|
collection.setField('updatedBy', {
|
|
172
193
|
type: 'belongsTo',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-users",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2-alpha.1",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"licenses": [
|
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
"jsonwebtoken": "^8.5.1"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@nocobase/test": "0.7.
|
|
17
|
-
"@types/jsonwebtoken": "^8.5.8"
|
|
16
|
+
"@nocobase/test": "0.7.2-alpha.1",
|
|
17
|
+
"@types/jsonwebtoken": "^8.5.8",
|
|
18
|
+
"json-templates": "^4.2.0"
|
|
18
19
|
},
|
|
19
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "2e7958360628d6306845aabcb1e574a8e91d08ad"
|
|
20
21
|
}
|