@budibase/backend-core 2.29.25 → 2.29.26
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/dist/index.js +56 -21
- package/dist/index.js.map +4 -4
- package/dist/index.js.meta.json +1 -1
- package/dist/package.json +4 -4
- package/dist/plugins.js +1 -0
- package/dist/plugins.js.map +2 -2
- package/dist/plugins.js.meta.json +1 -1
- package/dist/src/db/views.d.ts +1 -1
- package/dist/src/db/views.js +4 -2
- package/dist/src/db/views.js.map +1 -1
- package/dist/src/platform/users.d.ts +2 -1
- package/dist/src/platform/users.js +7 -0
- package/dist/src/platform/users.js.map +1 -1
- package/dist/src/users/db.js +14 -0
- package/dist/src/users/db.js.map +1 -1
- package/dist/src/users/lookup.d.ts +2 -1
- package/dist/src/users/lookup.js +14 -12
- package/dist/src/users/lookup.js.map +1 -1
- package/dist/src/users/utils.js +1 -1
- package/dist/src/users/utils.js.map +1 -1
- package/dist/tests/core/utilities/jestUtils.d.ts +3 -3
- package/package.json +4 -4
- package/src/db/views.ts +5 -4
- package/src/platform/users.ts +5 -0
- package/src/users/db.ts +31 -1
- package/src/users/lookup.ts +15 -22
- package/src/users/utils.ts +2 -2
- package/tests/core/utilities/jestUtils.ts +4 -4
package/dist/src/users/lookup.js
CHANGED
|
@@ -33,7 +33,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
35
|
exports.searchExistingEmails = searchExistingEmails;
|
|
36
|
-
exports.
|
|
36
|
+
exports.getPlatformUsers = getPlatformUsers;
|
|
37
|
+
exports.getFirstPlatformUser = getFirstPlatformUser;
|
|
37
38
|
exports.getExistingTenantUsers = getExistingTenantUsers;
|
|
38
39
|
exports.getExistingPlatformUsers = getExistingPlatformUsers;
|
|
39
40
|
exports.getExistingAccounts = getExistingAccounts;
|
|
@@ -62,14 +63,21 @@ function searchExistingEmails(emails) {
|
|
|
62
63
|
});
|
|
63
64
|
}
|
|
64
65
|
// lookup, could be email or userId, either will return a doc
|
|
65
|
-
function
|
|
66
|
+
function getPlatformUsers(identifier) {
|
|
66
67
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
68
|
// use the view here and allow to find anyone regardless of casing
|
|
68
69
|
// Use lowercase to ensure email login is case insensitive
|
|
69
|
-
return
|
|
70
|
+
return yield dbUtils.queryPlatformView(constants_1.ViewName.PLATFORM_USERS_LOWERCASE, {
|
|
70
71
|
keys: [identifier.toLowerCase()],
|
|
71
72
|
include_docs: true,
|
|
72
|
-
})
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function getFirstPlatformUser(identifier) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
var _a;
|
|
79
|
+
const platformUserDocs = yield getPlatformUsers(identifier);
|
|
80
|
+
return (_a = platformUserDocs[0]) !== null && _a !== void 0 ? _a : null;
|
|
73
81
|
});
|
|
74
82
|
}
|
|
75
83
|
function getExistingTenantUsers(emails) {
|
|
@@ -92,10 +100,7 @@ function getExistingPlatformUsers(emails) {
|
|
|
92
100
|
keys: lcEmails,
|
|
93
101
|
include_docs: true,
|
|
94
102
|
};
|
|
95
|
-
|
|
96
|
-
arrayResponse: true,
|
|
97
|
-
};
|
|
98
|
-
return (yield dbUtils.queryPlatformView(constants_1.ViewName.PLATFORM_USERS_LOWERCASE, params, opts));
|
|
103
|
+
return yield dbUtils.queryPlatformView(constants_1.ViewName.PLATFORM_USERS_LOWERCASE, params);
|
|
99
104
|
});
|
|
100
105
|
}
|
|
101
106
|
function getExistingAccounts(emails) {
|
|
@@ -105,10 +110,7 @@ function getExistingAccounts(emails) {
|
|
|
105
110
|
keys: lcEmails,
|
|
106
111
|
include_docs: true,
|
|
107
112
|
};
|
|
108
|
-
|
|
109
|
-
arrayResponse: true,
|
|
110
|
-
};
|
|
111
|
-
return (yield dbUtils.queryPlatformView(constants_1.ViewName.ACCOUNT_BY_EMAIL, params, opts));
|
|
113
|
+
return yield dbUtils.queryPlatformView(constants_1.ViewName.ACCOUNT_BY_EMAIL, params);
|
|
112
114
|
});
|
|
113
115
|
}
|
|
114
116
|
//# sourceMappingURL=lookup.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lookup.js","sourceRoot":"","sources":["../../../src/users/lookup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,oDAgBC;AAGD,
|
|
1
|
+
{"version":3,"file":"lookup.js","sourceRoot":"","sources":["../../../src/users/lookup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,oDAgBC;AAGD,4CASC;AAED,oDAKC;AAED,wDAmBC;AAED,4DAYC;AAED,kDASC;AA5FD,+CAAgC;AAChC,4CAAuC;AACvC,4CAAoD;AAEpD;;;;;;GAMG;AACH,SAAsB,oBAAoB,CAAC,MAAgB;;QACzD,IAAI,aAAa,GAAa,EAAE,CAAA;QAEhC,MAAM,mBAAmB,GAAG,MAAM,sBAAsB,CAAC,MAAM,CAAC,CAAA;QAChE,aAAa,CAAC,IAAI,CAAC,GAAG,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;QAElE,MAAM,qBAAqB,GAAG,MAAM,wBAAwB,CAAC,MAAM,CAAC,CAAA;QACpE,aAAa,CAAC,IAAI,CAAC,GAAG,qBAAqB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,GAAI,CAAC,CAAC,CAAA;QAEnE,MAAM,gBAAgB,GAAG,MAAM,mBAAmB,CAAC,MAAM,CAAC,CAAA;QAC1D,aAAa,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;QAErE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AwB,CAC5C,MAAgB;;QAEhB,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAA;QACzD,MAAM,MAAM,GAAG;YACb,IAAI,EAAE,QAAQ;YACd,YAAY,EAAE,IAAI;SACnB,CAAA;QACD,OAAO,MAAM,OAAO,CAAC,iBAAiB,CACpC,oBAAQ,CAAC,wBAAwB,EACjC,MAAM,CACP,CAAA;IACH,CAAC;CAAA;AAED,SAAsB,mBAAmB,CACvC,MAAgB;;QAEhB,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAA;QACzD,MAAM,MAAM,GAAG;YACb,IAAI,EAAE,QAAQ;YACd,YAAY,EAAE,IAAI;SACnB,CAAA;QACD,OAAO,MAAM,OAAO,CAAC,iBAAiB,CAAC,oBAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAA;IAC3E,CAAC;CAAA"}
|
package/dist/src/users/utils.js
CHANGED
|
@@ -91,7 +91,7 @@ function validateUniqueUser(email, tenantId) {
|
|
|
91
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
92
|
// check budibase users in other tenants
|
|
93
93
|
if (environment_1.default.MULTI_TENANCY) {
|
|
94
|
-
const tenantUser = yield (0, lookup_1.
|
|
94
|
+
const tenantUser = yield (0, lookup_1.getFirstPlatformUser)(email);
|
|
95
95
|
if (tenantUser != null && tenantUser.tenantId !== tenantId) {
|
|
96
96
|
throw new errors_1.EmailUnavailableError(email);
|
|
97
97
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/users/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,8BAMC;AAwBD,gDAgBC;AAKD,kEAeC;AArFD,wDAAyC;AACzC,iEA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AAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;gBACjE,MAAM,IAAI,8BAAqB,CAAC,KAAK,CAAC,CAAA;YACxC,CAAC;QACH,CAAC;IACH,CAAC;CAAA;AAED;;GAEG;AACH,SAAsB,2BAA2B,CAC/C,OAAiB;;QAEjB,IAAI,CAAC,qBAAG,CAAC,WAAW,IAAI,CAAC,qBAAG,CAAC,sBAAsB,EAAE,CAAC;YACpD,MAAM,QAAQ,GAAG,IAAA,qBAAW,GAAE,CAAA;YAC9B,MAAM,OAAO,GAAG,MAAM,IAAA,+BAAoB,EAAC,QAAQ,CAAC,CAAA;YACpD,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,MAAM,IAAI,KAAK,CAAC,kCAAkC,QAAQ,EAAE,CAAC,CAAA;YAC/D,CAAC;YAED,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,CAAA;YAC7C,IAAI,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;gBACrC,OAAO,OAAO,CAAA;YAChB,CAAC;QACH,CAAC;IACH,CAAC;CAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PROTECTED_EXTERNAL_COLUMNS, PROTECTED_INTERNAL_COLUMNS } from "@budibase/shared-core";
|
|
2
2
|
export declare function expectFunctionWasCalledTimesWith(jestFunction: any, times: number, argument: any): void;
|
|
3
3
|
export declare const expectAnyInternalColsAttributes: {
|
|
4
|
-
[K in (typeof
|
|
4
|
+
[K in (typeof PROTECTED_INTERNAL_COLUMNS)[number]]: any;
|
|
5
5
|
};
|
|
6
6
|
export declare const expectAnyExternalColsAttributes: {
|
|
7
|
-
[K in (typeof
|
|
7
|
+
[K in (typeof PROTECTED_EXTERNAL_COLUMNS)[number]]: any;
|
|
8
8
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/backend-core",
|
|
3
|
-
"version": "2.29.
|
|
3
|
+
"version": "2.29.26",
|
|
4
4
|
"description": "Budibase backend core libraries used in server and worker",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@budibase/nano": "10.1.5",
|
|
25
25
|
"@budibase/pouchdb-replication-stream": "1.2.11",
|
|
26
|
-
"@budibase/shared-core": "2.29.
|
|
27
|
-
"@budibase/types": "2.29.
|
|
26
|
+
"@budibase/shared-core": "2.29.26",
|
|
27
|
+
"@budibase/types": "2.29.26",
|
|
28
28
|
"aws-cloudfront-sign": "3.0.2",
|
|
29
29
|
"aws-sdk": "2.1030.0",
|
|
30
30
|
"bcrypt": "5.1.0",
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
},
|
|
98
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "ad792906287ae2fd32fe1c24369d9a25dbdebd64"
|
|
99
99
|
}
|
package/src/db/views.ts
CHANGED
|
@@ -199,9 +199,8 @@ export const createPlatformUserView = async () => {
|
|
|
199
199
|
|
|
200
200
|
export const queryPlatformView = async <T extends Document>(
|
|
201
201
|
viewName: ViewName,
|
|
202
|
-
params: DatabaseQueryOpts
|
|
203
|
-
|
|
204
|
-
): Promise<T[] | T> => {
|
|
202
|
+
params: DatabaseQueryOpts
|
|
203
|
+
): Promise<T[]> => {
|
|
205
204
|
const CreateFuncByName: any = {
|
|
206
205
|
[ViewName.ACCOUNT_BY_EMAIL]: createPlatformAccountEmailView,
|
|
207
206
|
[ViewName.PLATFORM_USERS_LOWERCASE]: createPlatformUserView,
|
|
@@ -209,7 +208,9 @@ export const queryPlatformView = async <T extends Document>(
|
|
|
209
208
|
|
|
210
209
|
return doWithDB(StaticDatabases.PLATFORM_INFO.name, async (db: Database) => {
|
|
211
210
|
const createFn = CreateFuncByName[viewName]
|
|
212
|
-
return queryView(viewName, params, db, createFn,
|
|
211
|
+
return queryView(viewName, params, db, createFn, {
|
|
212
|
+
arrayResponse: true,
|
|
213
|
+
}) as Promise<T[]>
|
|
213
214
|
})
|
|
214
215
|
}
|
|
215
216
|
|
package/src/platform/users.ts
CHANGED
|
@@ -25,6 +25,11 @@ export async function getUserDoc(emailOrId: string): Promise<PlatformUser> {
|
|
|
25
25
|
return db.get(emailOrId)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
export async function updateUserDoc(platformUser: PlatformUserById) {
|
|
29
|
+
const db = getPlatformDB()
|
|
30
|
+
await db.put(platformUser)
|
|
31
|
+
}
|
|
32
|
+
|
|
28
33
|
// CREATE
|
|
29
34
|
|
|
30
35
|
function newUserIdDoc(id: string, tenantId: string): PlatformUserById {
|
package/src/users/db.ts
CHANGED
|
@@ -18,6 +18,9 @@ import {
|
|
|
18
18
|
User,
|
|
19
19
|
UserStatus,
|
|
20
20
|
UserGroup,
|
|
21
|
+
PlatformUserBySsoId,
|
|
22
|
+
PlatformUserById,
|
|
23
|
+
AnyDocument,
|
|
21
24
|
} from "@budibase/types"
|
|
22
25
|
import {
|
|
23
26
|
getAccountHolderFromUserIds,
|
|
@@ -25,7 +28,11 @@ import {
|
|
|
25
28
|
isCreator,
|
|
26
29
|
validateUniqueUser,
|
|
27
30
|
} from "./utils"
|
|
28
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
getFirstPlatformUser,
|
|
33
|
+
getPlatformUsers,
|
|
34
|
+
searchExistingEmails,
|
|
35
|
+
} from "./lookup"
|
|
29
36
|
import { hash } from "../utils"
|
|
30
37
|
import { validatePassword } from "../security"
|
|
31
38
|
|
|
@@ -446,9 +453,32 @@ export class UserDB {
|
|
|
446
453
|
creator => !!creator
|
|
447
454
|
).length
|
|
448
455
|
|
|
456
|
+
const ssoUsersToDelete: AnyDocument[] = []
|
|
449
457
|
for (let user of usersToDelete) {
|
|
458
|
+
const platformUser = (await getFirstPlatformUser(
|
|
459
|
+
user._id!
|
|
460
|
+
)) as PlatformUserById
|
|
461
|
+
const ssoId = platformUser.ssoId
|
|
462
|
+
if (ssoId) {
|
|
463
|
+
// Need to get the _rev of the SSO user doc to delete it. The view also returns docs that have the ssoId property, so we need to ignore those.
|
|
464
|
+
const ssoUsers = (await getPlatformUsers(
|
|
465
|
+
ssoId
|
|
466
|
+
)) as PlatformUserBySsoId[]
|
|
467
|
+
ssoUsers
|
|
468
|
+
.filter(user => user.ssoId == null)
|
|
469
|
+
.forEach(user => {
|
|
470
|
+
ssoUsersToDelete.push({
|
|
471
|
+
...user,
|
|
472
|
+
_deleted: true,
|
|
473
|
+
})
|
|
474
|
+
})
|
|
475
|
+
}
|
|
450
476
|
await bulkDeleteProcessing(user)
|
|
451
477
|
}
|
|
478
|
+
|
|
479
|
+
// Delete any associated SSO user docs
|
|
480
|
+
await platform.getPlatformDB().bulkDocs(ssoUsersToDelete)
|
|
481
|
+
|
|
452
482
|
await UserDB.quotas.removeUsers(toDelete.length, creatorsToDeleteCount)
|
|
453
483
|
|
|
454
484
|
// Build Response
|
package/src/users/lookup.ts
CHANGED
|
@@ -34,15 +34,22 @@ export async function searchExistingEmails(emails: string[]) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
// lookup, could be email or userId, either will return a doc
|
|
37
|
-
export async function
|
|
37
|
+
export async function getPlatformUsers(
|
|
38
38
|
identifier: string
|
|
39
|
-
): Promise<PlatformUser
|
|
39
|
+
): Promise<PlatformUser[]> {
|
|
40
40
|
// use the view here and allow to find anyone regardless of casing
|
|
41
41
|
// Use lowercase to ensure email login is case insensitive
|
|
42
|
-
return
|
|
42
|
+
return await dbUtils.queryPlatformView(ViewName.PLATFORM_USERS_LOWERCASE, {
|
|
43
43
|
keys: [identifier.toLowerCase()],
|
|
44
44
|
include_docs: true,
|
|
45
|
-
})
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function getFirstPlatformUser(
|
|
49
|
+
identifier: string
|
|
50
|
+
): Promise<PlatformUser | null> {
|
|
51
|
+
const platformUserDocs = await getPlatformUsers(identifier)
|
|
52
|
+
return platformUserDocs[0] ?? null
|
|
46
53
|
}
|
|
47
54
|
|
|
48
55
|
export async function getExistingTenantUsers(
|
|
@@ -74,15 +81,10 @@ export async function getExistingPlatformUsers(
|
|
|
74
81
|
keys: lcEmails,
|
|
75
82
|
include_docs: true,
|
|
76
83
|
}
|
|
77
|
-
|
|
78
|
-
const opts = {
|
|
79
|
-
arrayResponse: true,
|
|
80
|
-
}
|
|
81
|
-
return (await dbUtils.queryPlatformView(
|
|
84
|
+
return await dbUtils.queryPlatformView(
|
|
82
85
|
ViewName.PLATFORM_USERS_LOWERCASE,
|
|
83
|
-
params
|
|
84
|
-
|
|
85
|
-
)) as PlatformUserByEmail[]
|
|
86
|
+
params
|
|
87
|
+
)
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
export async function getExistingAccounts(
|
|
@@ -93,14 +95,5 @@ export async function getExistingAccounts(
|
|
|
93
95
|
keys: lcEmails,
|
|
94
96
|
include_docs: true,
|
|
95
97
|
}
|
|
96
|
-
|
|
97
|
-
const opts = {
|
|
98
|
-
arrayResponse: true,
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return (await dbUtils.queryPlatformView(
|
|
102
|
-
ViewName.ACCOUNT_BY_EMAIL,
|
|
103
|
-
params,
|
|
104
|
-
opts
|
|
105
|
-
)) as AccountMetadata[]
|
|
98
|
+
return await dbUtils.queryPlatformView(ViewName.ACCOUNT_BY_EMAIL, params)
|
|
106
99
|
}
|
package/src/users/utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CloudAccount, ContextUser, User, UserGroup } from "@budibase/types"
|
|
2
2
|
import * as accountSdk from "../accounts"
|
|
3
3
|
import env from "../environment"
|
|
4
|
-
import {
|
|
4
|
+
import { getFirstPlatformUser } from "./lookup"
|
|
5
5
|
import { EmailUnavailableError } from "../errors"
|
|
6
6
|
import { getTenantId } from "../context"
|
|
7
7
|
import { sdk } from "@budibase/shared-core"
|
|
@@ -51,7 +51,7 @@ async function isCreatorByGroupMembership(user?: User | ContextUser) {
|
|
|
51
51
|
export async function validateUniqueUser(email: string, tenantId: string) {
|
|
52
52
|
// check budibase users in other tenants
|
|
53
53
|
if (env.MULTI_TENANCY) {
|
|
54
|
-
const tenantUser = await
|
|
54
|
+
const tenantUser = await getFirstPlatformUser(email)
|
|
55
55
|
if (tenantUser != null && tenantUser.tenantId !== tenantId) {
|
|
56
56
|
throw new EmailUnavailableError(email)
|
|
57
57
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
PROTECTED_EXTERNAL_COLUMNS,
|
|
3
|
+
PROTECTED_INTERNAL_COLUMNS,
|
|
4
4
|
} from "@budibase/shared-core"
|
|
5
5
|
|
|
6
6
|
export function expectFunctionWasCalledTimesWith(
|
|
@@ -14,7 +14,7 @@ export function expectFunctionWasCalledTimesWith(
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export const expectAnyInternalColsAttributes: {
|
|
17
|
-
[K in (typeof
|
|
17
|
+
[K in (typeof PROTECTED_INTERNAL_COLUMNS)[number]]: any
|
|
18
18
|
} = {
|
|
19
19
|
tableId: expect.anything(),
|
|
20
20
|
type: expect.anything(),
|
|
@@ -25,7 +25,7 @@ export const expectAnyInternalColsAttributes: {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export const expectAnyExternalColsAttributes: {
|
|
28
|
-
[K in (typeof
|
|
28
|
+
[K in (typeof PROTECTED_EXTERNAL_COLUMNS)[number]]: any
|
|
29
29
|
} = {
|
|
30
30
|
tableId: expect.anything(),
|
|
31
31
|
_id: expect.anything(),
|