@budibase/server 2.5.6-alpha.1 → 2.5.6-alpha.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/builder/assets/{index.1fe52b59.js → index.80d32454.js} +223 -223
- package/builder/index.html +1 -1
- package/dist/api/controllers/user.js +1 -83
- package/dist/api/routes/user.js +0 -1
- package/dist/events/docUpdates/index.js +17 -0
- package/dist/events/docUpdates/processors.js +18 -0
- package/dist/events/docUpdates/syncUsers.js +49 -0
- package/dist/events/index.js +3 -0
- package/dist/package.json +7 -7
- package/dist/sdk/app/applications/sync.js +117 -23
- package/dist/sdk/users/utils.js +21 -4
- package/dist/startup.js +2 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utilities/global.js +17 -12
- package/package.json +8 -8
- package/src/api/controllers/row/internal.ts +9 -10
- package/src/api/controllers/row/utils.ts +2 -2
- package/src/api/controllers/user.ts +10 -96
- package/src/api/routes/tests/user.spec.js +0 -37
- package/src/api/routes/user.ts +0 -5
- package/src/events/docUpdates/index.ts +1 -0
- package/src/events/docUpdates/processors.ts +14 -0
- package/src/events/docUpdates/syncUsers.ts +35 -0
- package/src/events/index.ts +1 -0
- package/src/sdk/app/applications/sync.ts +129 -22
- package/src/sdk/app/applications/tests/sync.spec.ts +137 -0
- package/src/sdk/users/tests/utils.spec.ts +1 -32
- package/src/sdk/users/utils.ts +23 -5
- package/src/startup.ts +2 -1
- package/src/tests/utilities/TestConfiguration.ts +28 -0
- package/src/utilities/global.ts +21 -16
package/builder/index.html
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<link rel="preconnect" href="https://fonts.gstatic.com" />
|
|
9
9
|
<link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@400;600;700&display=swap"
|
|
10
10
|
rel="stylesheet" />
|
|
11
|
-
<script type="module" crossorigin src="/builder/assets/index.
|
|
11
|
+
<script type="module" crossorigin src="/builder/assets/index.80d32454.js"></script>
|
|
12
12
|
<link rel="stylesheet" href="/builder/assets/index.841e62d8.css">
|
|
13
13
|
</head>
|
|
14
14
|
|
|
@@ -12,95 +12,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getFlags = exports.setFlag = exports.findMetadata = exports.destroyMetadata = exports.updateMetadata = exports.updateSelfMetadata = exports.fetchMetadata =
|
|
15
|
+
exports.getFlags = exports.setFlag = exports.findMetadata = exports.destroyMetadata = exports.updateMetadata = exports.updateSelfMetadata = exports.fetchMetadata = void 0;
|
|
16
16
|
const utils_1 = require("../../db/utils");
|
|
17
17
|
const utils_2 = require("../../db/utils");
|
|
18
18
|
const global_1 = require("../../utilities/global");
|
|
19
19
|
const users_1 = require("../../utilities/users");
|
|
20
20
|
const backend_core_1 = require("@budibase/backend-core");
|
|
21
21
|
const sdk_1 = __importDefault(require("../../sdk"));
|
|
22
|
-
function syncUser(ctx) {
|
|
23
|
-
var _a;
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
let deleting = false, user;
|
|
26
|
-
const userId = ctx.params.id;
|
|
27
|
-
const previousUser = (_a = ctx.request.body) === null || _a === void 0 ? void 0 : _a.previousUser;
|
|
28
|
-
try {
|
|
29
|
-
user = (yield (0, global_1.getRawGlobalUser)(userId));
|
|
30
|
-
}
|
|
31
|
-
catch (err) {
|
|
32
|
-
if (err && err.status === 404) {
|
|
33
|
-
user = {};
|
|
34
|
-
deleting = true;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
throw err;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
let previousApps = previousUser
|
|
41
|
-
? Object.keys(previousUser.roles).map(appId => appId)
|
|
42
|
-
: [];
|
|
43
|
-
const roles = deleting ? {} : user.roles;
|
|
44
|
-
// remove props which aren't useful to metadata
|
|
45
|
-
delete user.password;
|
|
46
|
-
delete user.forceResetPassword;
|
|
47
|
-
delete user.roles;
|
|
48
|
-
// run through all production appIDs in the users roles
|
|
49
|
-
let prodAppIds;
|
|
50
|
-
// if they are a builder then get all production app IDs
|
|
51
|
-
if ((user.builder && user.builder.global) || deleting) {
|
|
52
|
-
prodAppIds = yield backend_core_1.db.getProdAppIDs();
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
prodAppIds = Object.entries(roles)
|
|
56
|
-
.filter(entry => entry[1] !== backend_core_1.roles.BUILTIN_ROLE_IDS.PUBLIC)
|
|
57
|
-
.map(([appId]) => appId);
|
|
58
|
-
}
|
|
59
|
-
for (let prodAppId of new Set([...prodAppIds, ...previousApps])) {
|
|
60
|
-
const roleId = roles[prodAppId];
|
|
61
|
-
const deleteFromApp = !roleId;
|
|
62
|
-
const devAppId = backend_core_1.db.getDevelopmentAppID(prodAppId);
|
|
63
|
-
for (let appId of [prodAppId, devAppId]) {
|
|
64
|
-
if (!(yield backend_core_1.db.dbExists(appId))) {
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
yield backend_core_1.context.doInAppContext(appId, () => __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
const db = backend_core_1.context.getAppDB();
|
|
69
|
-
const metadataId = (0, utils_1.generateUserMetadataID)(userId);
|
|
70
|
-
let metadata;
|
|
71
|
-
try {
|
|
72
|
-
metadata = yield db.get(metadataId);
|
|
73
|
-
}
|
|
74
|
-
catch (err) {
|
|
75
|
-
if (deleteFromApp) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
metadata = {
|
|
79
|
-
tableId: utils_2.InternalTables.USER_METADATA,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
if (deleteFromApp) {
|
|
83
|
-
yield db.remove(metadata);
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
// assign the roleId for the metadata doc
|
|
87
|
-
if (roleId) {
|
|
88
|
-
metadata.roleId = roleId;
|
|
89
|
-
}
|
|
90
|
-
let combined = sdk_1.default.users.combineMetadataAndUser(user, metadata);
|
|
91
|
-
// if its null then there was no updates required
|
|
92
|
-
if (combined) {
|
|
93
|
-
yield db.put(combined);
|
|
94
|
-
}
|
|
95
|
-
}));
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
ctx.body = {
|
|
99
|
-
message: "User synced.",
|
|
100
|
-
};
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
exports.syncUser = syncUser;
|
|
104
22
|
function fetchMetadata(ctx) {
|
|
105
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
24
|
const global = yield (0, global_1.getGlobalUsers)();
|
package/dist/api/routes/user.js
CHANGED
|
@@ -38,7 +38,6 @@ router
|
|
|
38
38
|
.put("/api/users/metadata", (0, authorized_1.default)(PermissionType.USER, PermissionLevel.WRITE), controller.updateMetadata)
|
|
39
39
|
.post("/api/users/metadata/self", (0, authorized_1.default)(PermissionType.USER, PermissionLevel.WRITE), controller.updateSelfMetadata)
|
|
40
40
|
.delete("/api/users/metadata/:id", (0, authorized_1.default)(PermissionType.USER, PermissionLevel.WRITE), controller.destroyMetadata)
|
|
41
|
-
.post("/api/users/metadata/sync/:id", (0, authorized_1.default)(PermissionType.USER, PermissionLevel.WRITE), controller.syncUser)
|
|
42
41
|
.post("/api/users/flags", (0, authorized_1.default)(PermissionType.USER, PermissionLevel.WRITE), controller.setFlag)
|
|
43
42
|
.get("/api/users/flags", (0, authorized_1.default)(PermissionType.USER, PermissionLevel.READ), controller.getFlags);
|
|
44
43
|
exports.default = router;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./processors"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.init = void 0;
|
|
7
|
+
const syncUsers_1 = __importDefault(require("./syncUsers"));
|
|
8
|
+
const backend_core_1 = require("@budibase/backend-core");
|
|
9
|
+
let started = false;
|
|
10
|
+
function init(updateCb) {
|
|
11
|
+
if (started) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const processors = [(0, syncUsers_1.default)(updateCb)];
|
|
15
|
+
backend_core_1.docUpdates.init(processors);
|
|
16
|
+
started = true;
|
|
17
|
+
}
|
|
18
|
+
exports.init = init;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const backend_core_1 = require("@budibase/backend-core");
|
|
13
|
+
const pro_1 = require("@budibase/pro");
|
|
14
|
+
const types_1 = require("@budibase/types");
|
|
15
|
+
const sync_1 = require("../../sdk/app/applications/sync");
|
|
16
|
+
function process(updateCb) {
|
|
17
|
+
const processor = (update) => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
var _a;
|
|
19
|
+
try {
|
|
20
|
+
const docId = update.id;
|
|
21
|
+
const isGroup = docId.startsWith(backend_core_1.constants.DocumentType.GROUP);
|
|
22
|
+
let userIds;
|
|
23
|
+
if (isGroup) {
|
|
24
|
+
const group = yield pro_1.sdk.groups.get(docId);
|
|
25
|
+
userIds = ((_a = group.users) === null || _a === void 0 ? void 0 : _a.map(user => user._id)) || [];
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
userIds = [docId];
|
|
29
|
+
}
|
|
30
|
+
if (userIds.length > 0) {
|
|
31
|
+
yield (0, sync_1.syncUsersToAllApps)(userIds);
|
|
32
|
+
}
|
|
33
|
+
if (updateCb) {
|
|
34
|
+
updateCb(docId);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
// if something not found - no changes to perform
|
|
39
|
+
if ((err === null || err === void 0 ? void 0 : err.status) === 404) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
backend_core_1.logging.logAlert("Failed to perform user/group app sync", err);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return { events: types_1.UserGroupSyncEvents, processor };
|
|
48
|
+
}
|
|
49
|
+
exports.default = process;
|
package/dist/events/index.js
CHANGED
|
@@ -3,6 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.init = void 0;
|
|
6
7
|
const BudibaseEmitter_1 = __importDefault(require("./BudibaseEmitter"));
|
|
7
8
|
const emitter = new BudibaseEmitter_1.default();
|
|
9
|
+
var docUpdates_1 = require("./docUpdates");
|
|
10
|
+
Object.defineProperty(exports, "init", { enumerable: true, get: function () { return docUpdates_1.init; } });
|
|
8
11
|
exports.default = emitter;
|
package/dist/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/server",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "2.5.6-alpha.
|
|
4
|
+
"version": "2.5.6-alpha.1",
|
|
5
5
|
"description": "Budibase Web Server",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -45,12 +45,12 @@
|
|
|
45
45
|
"license": "GPL-3.0",
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@apidevtools/swagger-parser": "10.0.3",
|
|
48
|
-
"@budibase/backend-core": "2.5.
|
|
49
|
-
"@budibase/client": "2.5.
|
|
50
|
-
"@budibase/pro": "2.5.
|
|
51
|
-
"@budibase/shared-core": "2.5.
|
|
52
|
-
"@budibase/string-templates": "2.5.
|
|
53
|
-
"@budibase/types": "2.5.
|
|
48
|
+
"@budibase/backend-core": "2.5.6-alpha.1",
|
|
49
|
+
"@budibase/client": "2.5.6-alpha.1",
|
|
50
|
+
"@budibase/pro": "2.5.6-alpha.1",
|
|
51
|
+
"@budibase/shared-core": "2.5.6-alpha.1",
|
|
52
|
+
"@budibase/string-templates": "2.5.6-alpha.1",
|
|
53
|
+
"@budibase/types": "2.5.6-alpha.1",
|
|
54
54
|
"@bull-board/api": "3.7.0",
|
|
55
55
|
"@bull-board/koa": "3.9.4",
|
|
56
56
|
"@elastic/elasticsearch": "7.10.0",
|
|
@@ -12,10 +12,108 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.syncApp = void 0;
|
|
15
|
+
exports.syncApp = exports.syncUsersToAllApps = void 0;
|
|
16
16
|
const environment_1 = __importDefault(require("../../../environment"));
|
|
17
17
|
const backend_core_1 = require("@budibase/backend-core");
|
|
18
|
+
const pro_1 = require("@budibase/pro");
|
|
18
19
|
const __1 = __importDefault(require("../../"));
|
|
20
|
+
const global_1 = require("../../../utilities/global");
|
|
21
|
+
const utils_1 = require("../../../db/utils");
|
|
22
|
+
function syncUsersToApp(appId, users, groups) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
if (!(yield backend_core_1.db.dbExists(appId))) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
yield backend_core_1.context.doInAppContext(appId, () => __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const db = backend_core_1.context.getAppDB();
|
|
29
|
+
for (let user of users) {
|
|
30
|
+
let ctxUser = user;
|
|
31
|
+
let deletedUser = false;
|
|
32
|
+
const metadataId = (0, utils_1.generateUserMetadataID)(user._id);
|
|
33
|
+
if (user.deleted) {
|
|
34
|
+
deletedUser = true;
|
|
35
|
+
}
|
|
36
|
+
// make sure role is correct
|
|
37
|
+
if (!deletedUser) {
|
|
38
|
+
ctxUser = yield (0, global_1.processUser)(ctxUser, { appId, groups });
|
|
39
|
+
}
|
|
40
|
+
let roleId = ctxUser.roleId;
|
|
41
|
+
if (roleId === backend_core_1.roles.BUILTIN_ROLE_IDS.PUBLIC) {
|
|
42
|
+
roleId = undefined;
|
|
43
|
+
}
|
|
44
|
+
let metadata;
|
|
45
|
+
try {
|
|
46
|
+
metadata = yield db.get(metadataId);
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
if (err.status !== 404) {
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
// no metadata and user is to be deleted, can skip
|
|
53
|
+
// no role - user isn't in app anyway
|
|
54
|
+
if (!roleId) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
else if (!deletedUser) {
|
|
58
|
+
// doesn't exist yet, creating it
|
|
59
|
+
metadata = {
|
|
60
|
+
tableId: utils_1.InternalTables.USER_METADATA,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// the user doesn't exist, or doesn't have a role anymore
|
|
65
|
+
// get rid of their metadata
|
|
66
|
+
if (deletedUser || !roleId) {
|
|
67
|
+
yield db.remove(metadata);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
// assign the roleId for the metadata doc
|
|
71
|
+
if (roleId) {
|
|
72
|
+
metadata.roleId = roleId;
|
|
73
|
+
}
|
|
74
|
+
let combined = __1.default.users.combineMetadataAndUser(ctxUser, metadata);
|
|
75
|
+
// if no combined returned, there are no updates to make
|
|
76
|
+
if (combined) {
|
|
77
|
+
yield db.put(combined);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}));
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function syncUsersToAllApps(userIds) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
// list of users, if one has been deleted it will be undefined in array
|
|
86
|
+
const users = (yield (0, global_1.getGlobalUsers)(userIds, {
|
|
87
|
+
noProcessing: true,
|
|
88
|
+
}));
|
|
89
|
+
const groups = yield pro_1.sdk.groups.fetch();
|
|
90
|
+
const finalUsers = [];
|
|
91
|
+
for (let userId of userIds) {
|
|
92
|
+
const user = users.find(user => user._id === userId);
|
|
93
|
+
if (!user) {
|
|
94
|
+
finalUsers.push({ _id: userId, deleted: true });
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
finalUsers.push(user);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const devAppIds = yield backend_core_1.db.getDevAppIDs();
|
|
101
|
+
let promises = [];
|
|
102
|
+
for (let devAppId of devAppIds) {
|
|
103
|
+
const prodAppId = backend_core_1.db.getProdAppID(devAppId);
|
|
104
|
+
for (let appId of [prodAppId, devAppId]) {
|
|
105
|
+
promises.push(syncUsersToApp(appId, finalUsers, groups));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const resp = yield Promise.allSettled(promises);
|
|
109
|
+
const failed = resp.filter(promise => promise.status === "rejected");
|
|
110
|
+
if (failed.length > 0) {
|
|
111
|
+
const reasons = failed.map(fail => fail.reason);
|
|
112
|
+
backend_core_1.logging.logAlert("Failed to sync users to apps", reasons);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
exports.syncUsersToAllApps = syncUsersToAllApps;
|
|
19
117
|
function syncApp(appId, opts) {
|
|
20
118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
119
|
if (environment_1.default.DISABLE_AUTO_PROD_APP_SYNC) {
|
|
@@ -31,31 +129,27 @@ function syncApp(appId, opts) {
|
|
|
31
129
|
// specific case, want to make sure setup is skipped
|
|
32
130
|
const prodDb = backend_core_1.context.getProdAppDB({ skip_setup: true });
|
|
33
131
|
const exists = yield prodDb.exists();
|
|
34
|
-
if (!exists) {
|
|
35
|
-
// the database doesn't exist. Don't replicate
|
|
36
|
-
return {
|
|
37
|
-
message: "App sync not required, app not deployed.",
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
const replication = new backend_core_1.db.Replication({
|
|
41
|
-
source: prodAppId,
|
|
42
|
-
target: appId,
|
|
43
|
-
});
|
|
44
132
|
let error;
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
133
|
+
if (exists) {
|
|
134
|
+
const replication = new backend_core_1.db.Replication({
|
|
135
|
+
source: prodAppId,
|
|
136
|
+
target: appId,
|
|
137
|
+
});
|
|
138
|
+
try {
|
|
139
|
+
const replOpts = replication.appReplicateOpts();
|
|
140
|
+
if (opts === null || opts === void 0 ? void 0 : opts.automationOnly) {
|
|
141
|
+
replOpts.filter = (doc) => doc._id.startsWith(backend_core_1.db.DocumentType.AUTOMATION);
|
|
142
|
+
}
|
|
143
|
+
yield replication.replicate(replOpts);
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
error = err;
|
|
147
|
+
}
|
|
148
|
+
finally {
|
|
149
|
+
yield replication.close();
|
|
49
150
|
}
|
|
50
|
-
yield replication.replicate(replOpts);
|
|
51
|
-
}
|
|
52
|
-
catch (err) {
|
|
53
|
-
error = err;
|
|
54
|
-
}
|
|
55
|
-
finally {
|
|
56
|
-
yield replication.close();
|
|
57
151
|
}
|
|
58
|
-
// sync the users
|
|
152
|
+
// sync the users - kept for safe keeping
|
|
59
153
|
yield __1.default.users.syncGlobalUsers();
|
|
60
154
|
if (error) {
|
|
61
155
|
throw error;
|
package/dist/sdk/users/utils.js
CHANGED
|
@@ -34,6 +34,10 @@ function combineMetadataAndUser(user, metadata) {
|
|
|
34
34
|
if (found) {
|
|
35
35
|
newDoc._rev = found._rev;
|
|
36
36
|
}
|
|
37
|
+
// clear fields that shouldn't be in metadata
|
|
38
|
+
delete newDoc.password;
|
|
39
|
+
delete newDoc.forceResetPassword;
|
|
40
|
+
delete newDoc.roles;
|
|
37
41
|
if (found == null || !(0, lodash_1.isEqual)(newDoc, found)) {
|
|
38
42
|
return Object.assign(Object.assign({}, found), newDoc);
|
|
39
43
|
}
|
|
@@ -53,10 +57,9 @@ function syncGlobalUsers() {
|
|
|
53
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
58
|
// sync user metadata
|
|
55
59
|
const db = backend_core_1.context.getAppDB();
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
]);
|
|
60
|
+
const resp = yield Promise.all([(0, global_1.getGlobalUsers)(), rawUserMetadata()]);
|
|
61
|
+
const users = resp[0];
|
|
62
|
+
const metadata = resp[1];
|
|
60
63
|
const toWrite = [];
|
|
61
64
|
for (let user of users) {
|
|
62
65
|
const combined = combineMetadataAndUser(user, metadata);
|
|
@@ -64,6 +67,20 @@ function syncGlobalUsers() {
|
|
|
64
67
|
toWrite.push(combined);
|
|
65
68
|
}
|
|
66
69
|
}
|
|
70
|
+
let foundEmails = [];
|
|
71
|
+
for (let data of metadata) {
|
|
72
|
+
if (!data._id) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const alreadyExisting = data.email && foundEmails.indexOf(data.email) !== -1;
|
|
76
|
+
const globalId = (0, utils_1.getGlobalIDFromUserMetadataID)(data._id);
|
|
77
|
+
if (!users.find(user => user._id === globalId) || alreadyExisting) {
|
|
78
|
+
toWrite.push(Object.assign(Object.assign({}, data), { _deleted: true }));
|
|
79
|
+
}
|
|
80
|
+
if (data.email) {
|
|
81
|
+
foundEmails.push(data.email);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
67
84
|
yield db.bulkDocs(toWrite);
|
|
68
85
|
});
|
|
69
86
|
}
|
package/dist/startup.js
CHANGED
|
@@ -44,7 +44,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
44
44
|
const watch_1 = require("./watch");
|
|
45
45
|
const automations = __importStar(require("./automations"));
|
|
46
46
|
const fileSystem = __importStar(require("./utilities/fileSystem"));
|
|
47
|
-
const events_1 =
|
|
47
|
+
const events_1 = __importStar(require("./events"));
|
|
48
48
|
const migrations = __importStar(require("./migrations"));
|
|
49
49
|
const bullboard = __importStar(require("./automations/bullboard"));
|
|
50
50
|
const pro = __importStar(require("@budibase/pro"));
|
|
@@ -96,6 +96,7 @@ function startup(app, server) {
|
|
|
96
96
|
events_1.default.emitPort(environment_1.default.PORT);
|
|
97
97
|
fileSystem.init();
|
|
98
98
|
yield redis.init();
|
|
99
|
+
(0, events_1.init)();
|
|
99
100
|
// run migrations on startup if not done via http
|
|
100
101
|
// not recommended in a clustered environment
|
|
101
102
|
if (!environment_1.default.HTTP_MIGRATIONS && !environment_1.default.isTest()) {
|