@cocreate/users 1.5.2 → 1.5.5
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/CHANGELOG.md +23 -0
- package/CoCreate.config.js +1 -1
- package/demo/index.html +1 -1
- package/package.json +1 -1
- package/src/client.js +8 -13
- package/src/server.js +18 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
## [1.5.5](https://github.com/CoCreate-app/CoCreate-users/compare/v1.5.4...v1.5.5) (2022-05-09)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* client.js - remove adminUI_id and builderUI_id ([88da86d](https://github.com/CoCreate-app/CoCreate-users/commit/88da86d9ecc31a12d3eb5cef0a941c38697828ad))
|
|
7
|
+
* insert returns insertedId instead of [0]._id ([36c83fc](https://github.com/CoCreate-app/CoCreate-users/commit/36c83fc08d0ba70a3a9993b4d06bf8ad3304b2f7))
|
|
8
|
+
|
|
9
|
+
## [1.5.4](https://github.com/CoCreate-app/CoCreate-users/compare/v1.5.3...v1.5.4) (2022-05-08)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* convert user_id object_id to string ([bec7113](https://github.com/CoCreate-app/CoCreate-users/commit/bec711359b99594c0a6207ca478a73968dbc0a41))
|
|
15
|
+
|
|
16
|
+
## [1.5.3](https://github.com/CoCreate-app/CoCreate-users/compare/v1.5.2...v1.5.3) (2022-05-06)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* replace ObjectID with ObjectId due to mongodb depreciation ([0e7f5be](https://github.com/CoCreate-app/CoCreate-users/commit/0e7f5beba78bb71937a97fb3224d63b9c7c711db))
|
|
22
|
+
* update config organization_Id to organization_id ([929f871](https://github.com/CoCreate-app/CoCreate-users/commit/929f871205441c86b4024f07f239338abd52995f))
|
|
23
|
+
|
|
1
24
|
## [1.5.2](https://github.com/CoCreate-app/CoCreate-users/compare/v1.5.1...v1.5.2) (2022-05-03)
|
|
2
25
|
|
|
3
26
|
|
package/CoCreate.config.js
CHANGED
package/demo/index.html
CHANGED
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -7,7 +7,6 @@ import render from '@cocreate/render';
|
|
|
7
7
|
const CONST_PERMISSION_CLASS = 'checkPermission';
|
|
8
8
|
|
|
9
9
|
const CoCreateUser = {
|
|
10
|
-
// masterDB: '5ae0cfac6fb8c4e656fdaf92', // '5ae0cfac6fb8c4e656fdaf92' /** masterDB **/,
|
|
11
10
|
init: function() {
|
|
12
11
|
this.updatedCurrentOrg = false;
|
|
13
12
|
this.initSocket();
|
|
@@ -69,7 +68,7 @@ const CoCreateUser = {
|
|
|
69
68
|
|
|
70
69
|
crud.send('login', {
|
|
71
70
|
"apiKey": window.config.apiKey,
|
|
72
|
-
"organization_id": window.config.
|
|
71
|
+
"organization_id": window.config.organization_id,
|
|
73
72
|
"collection": collection,
|
|
74
73
|
"loginData": loginData
|
|
75
74
|
});
|
|
@@ -79,7 +78,7 @@ const CoCreateUser = {
|
|
|
79
78
|
let { success, status, message, token } = data;
|
|
80
79
|
|
|
81
80
|
if (success) {
|
|
82
|
-
window.localStorage.setItem('organization_id', window.config.
|
|
81
|
+
window.localStorage.setItem('organization_id', window.config.organization_id);
|
|
83
82
|
window.localStorage.setItem("apiKey", window.config.apiKey);
|
|
84
83
|
window.localStorage.setItem("host", window.config.host);
|
|
85
84
|
window.localStorage.setItem('user_id', data['id']);
|
|
@@ -108,7 +107,7 @@ const CoCreateUser = {
|
|
|
108
107
|
getCurrentOrg: function(user_id, collection) {
|
|
109
108
|
crud.send('usersCurrentOrg', {
|
|
110
109
|
"apiKey": window.config.apiKey,
|
|
111
|
-
"organization_id": window.config.
|
|
110
|
+
"organization_id": window.config.organization_id,
|
|
112
111
|
"collection": collection || 'users',
|
|
113
112
|
"user_id": user_id,
|
|
114
113
|
});
|
|
@@ -120,9 +119,6 @@ const CoCreateUser = {
|
|
|
120
119
|
window.localStorage.setItem('organization_id', data['current_org']);
|
|
121
120
|
window.localStorage.setItem('host', window.config.host);
|
|
122
121
|
|
|
123
|
-
// window.localStorage.setItem('adminUI_id', data['adminUI_id']);
|
|
124
|
-
// window.localStorage.setItem('builderUI_id', data['builderUI_id']);
|
|
125
|
-
|
|
126
122
|
document.dispatchEvent(new CustomEvent('logIn'));
|
|
127
123
|
},
|
|
128
124
|
|
|
@@ -264,11 +260,11 @@ const CoCreateUser = {
|
|
|
264
260
|
let newOrg_id = form.querySelector("input[collection='organizations'][name='_id']");
|
|
265
261
|
let user_id = form.querySelector("input[collection='users'][name='_id']");
|
|
266
262
|
|
|
267
|
-
const room = config.
|
|
263
|
+
const room = config.organization_id;
|
|
268
264
|
|
|
269
265
|
crud.send('createUserNew', {
|
|
270
266
|
apiKey: config.apiKey,
|
|
271
|
-
organization_id: config.
|
|
267
|
+
organization_id: config.organization_id,
|
|
272
268
|
collection: 'users',
|
|
273
269
|
newOrg_id: org_id,
|
|
274
270
|
user_id: user_id,
|
|
@@ -300,14 +296,13 @@ const CoCreateUser = {
|
|
|
300
296
|
});
|
|
301
297
|
data['current_org'] = org_id;
|
|
302
298
|
data['connected_orgs'] = [org_id];
|
|
303
|
-
data['organization_id'] = config.
|
|
299
|
+
data['organization_id'] = config.organization_id;
|
|
304
300
|
|
|
305
|
-
const room = config.
|
|
301
|
+
const room = config.organization_id;
|
|
306
302
|
|
|
307
303
|
crud.send('createUser', {
|
|
308
304
|
apiKey: config.apiKey,
|
|
309
|
-
organization_id: config.
|
|
310
|
-
// mdb: this.masterDB,
|
|
305
|
+
organization_id: config.organization_id,
|
|
311
306
|
collection: 'users',
|
|
312
307
|
data: data,
|
|
313
308
|
orgDB: org_id
|
package/src/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {ObjectId} = require("mongodb");
|
|
2
2
|
|
|
3
3
|
class CoCreateUser {
|
|
4
4
|
constructor(wsManager, dbClient) {
|
|
@@ -28,7 +28,7 @@ class CoCreateUser {
|
|
|
28
28
|
const db = this.dbClient.db(req_data['organization_id']);
|
|
29
29
|
const collection = db.collection(req_data["collection"]);
|
|
30
30
|
const query = {
|
|
31
|
-
"_id": new
|
|
31
|
+
"_id": new ObjectId(data["user_id"])
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
collection.find(query).toArray(function(error, result) {
|
|
@@ -37,7 +37,7 @@ class CoCreateUser {
|
|
|
37
37
|
// Create new user in config db users collection
|
|
38
38
|
newOrgDb.insertOne({...result.ops[0], organization_id : newOrg_id}, function(error, result) {
|
|
39
39
|
if(!error && result){
|
|
40
|
-
const response = { ...data, document_id: result.
|
|
40
|
+
const response = { ...data, document_id: `${result.insertedId}`, data: result.ops[0]}
|
|
41
41
|
self.wsManager.send(socket, 'createUserNew', response, data['organization_id']);
|
|
42
42
|
}
|
|
43
43
|
});
|
|
@@ -59,15 +59,22 @@ class CoCreateUser {
|
|
|
59
59
|
collection.insertOne(data.data, function(error, result) {
|
|
60
60
|
if(!error && result){
|
|
61
61
|
const orgDB = data.orgDB;
|
|
62
|
+
data.data['_id'] = result.insertedId;
|
|
62
63
|
// if new orgDb Create new user in new org db users collection
|
|
63
64
|
if (orgDB != data.organization_id) {
|
|
64
65
|
if (orgDB) {
|
|
65
66
|
const anotherCollection = self.dbClient.db(orgDB).collection(data['collection']);
|
|
66
|
-
anotherCollection.insertOne({...
|
|
67
|
+
anotherCollection.insertOne({...data.data, organization_id : orgDB});
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
|
-
const response = { ...data, document_id: result.
|
|
70
|
+
const response = { ...data, document_id: `${result.insertedId}`}
|
|
70
71
|
self.wsManager.send(socket, 'createUser', response, data['organization_id']);
|
|
72
|
+
|
|
73
|
+
// add new user to platformDB
|
|
74
|
+
if (data.organization_id != process.env.organization_id) {
|
|
75
|
+
const platformDB = self.dbClient.db(process.env.organization_id).collection(data['collection']);
|
|
76
|
+
platformDB.insertOne({...data.data, organization_id: process.env.organization_id});
|
|
77
|
+
}
|
|
71
78
|
}
|
|
72
79
|
});
|
|
73
80
|
}catch(error){
|
|
@@ -114,7 +121,8 @@ class CoCreateUser {
|
|
|
114
121
|
if (!error && result && result.length > 0) {
|
|
115
122
|
let token = null;
|
|
116
123
|
if (self.wsManager.authInstance) {
|
|
117
|
-
|
|
124
|
+
console.log('login user_id: ', `${result[0]['_id']}`)
|
|
125
|
+
token = await self.wsManager.authInstance.generateToken({user_id: `${result[0]['_id']}`});
|
|
118
126
|
}
|
|
119
127
|
|
|
120
128
|
response = { ...response,
|
|
@@ -128,7 +136,6 @@ class CoCreateUser {
|
|
|
128
136
|
token
|
|
129
137
|
};
|
|
130
138
|
}
|
|
131
|
-
console.log('before socket', response);
|
|
132
139
|
self.wsManager.send(socket, 'login', response, req_data['organization_id'])
|
|
133
140
|
console.log('success socket', req_data['organization_id']);
|
|
134
141
|
});
|
|
@@ -154,7 +161,7 @@ class CoCreateUser {
|
|
|
154
161
|
|
|
155
162
|
let query = new Object();
|
|
156
163
|
|
|
157
|
-
query['_id'] = new
|
|
164
|
+
query['_id'] = new ObjectId(req_data['user_id']);
|
|
158
165
|
|
|
159
166
|
collection.find(query).toArray(function(error, result) {
|
|
160
167
|
|
|
@@ -164,7 +171,7 @@ class CoCreateUser {
|
|
|
164
171
|
let org_id = result[0]['current_org'];
|
|
165
172
|
const orgCollection = self.dbClient.db(selectedDB).collection('organizations');
|
|
166
173
|
|
|
167
|
-
orgCollection.find({"_id": new
|
|
174
|
+
orgCollection.find({"_id": new ObjectId(org_id),}).toArray(function(err, res) {
|
|
168
175
|
if (!err && res && res.length > 0) {
|
|
169
176
|
self.wsManager.send(socket, 'usersCurrentOrg', {
|
|
170
177
|
id: req_data['id'],
|
|
@@ -173,8 +180,6 @@ class CoCreateUser {
|
|
|
173
180
|
user_id: result[0]['_id'],
|
|
174
181
|
current_org: result[0]['current_org'],
|
|
175
182
|
apiKey: res[0]['apiKey'],
|
|
176
|
-
adminUI_id: res[0]['adminUI_id'],
|
|
177
|
-
builderUI_id: res[0]['builderUI_id'],
|
|
178
183
|
href: req_data['href']
|
|
179
184
|
}, req_data['organization_id'])
|
|
180
185
|
}
|
|
@@ -211,7 +216,7 @@ class CoCreateUser {
|
|
|
211
216
|
const collection = self.dbClient.db(selectedDB).collection(req_data['collection']);
|
|
212
217
|
const user_id = req_data['user_id'];
|
|
213
218
|
const query = {
|
|
214
|
-
"_id": new
|
|
219
|
+
"_id": new ObjectId(user_id),
|
|
215
220
|
}
|
|
216
221
|
|
|
217
222
|
collection.findOne(query, function(error, result) {
|
|
@@ -245,7 +250,7 @@ class CoCreateUser {
|
|
|
245
250
|
const collection = self.dbClient.db(selectedDB).collection('users');
|
|
246
251
|
const user_id = items[1];
|
|
247
252
|
const query = {
|
|
248
|
-
"_id": new
|
|
253
|
+
"_id": new ObjectId(user_id),
|
|
249
254
|
}
|
|
250
255
|
collection.update(query, {$set: {status: status}}, function(err, res) {
|
|
251
256
|
if (!err) {
|