@budibase/backend-core 2.11.40 → 2.11.42
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 +273 -319
- package/dist/index.js.map +3 -3
- package/dist/index.js.meta.json +1 -1
- package/dist/package.json +4 -4
- package/dist/plugins.js.map +1 -1
- package/dist/plugins.js.meta.json +1 -1
- package/dist/src/cache/writethrough.d.ts +1 -1
- package/dist/src/cache/writethrough.js +2 -2
- package/dist/src/cache/writethrough.js.map +1 -1
- package/dist/src/users/db.d.ts +5 -2
- package/dist/src/users/db.js +8 -15
- package/dist/src/users/db.js.map +1 -1
- package/dist/src/users/users.d.ts +2 -3
- package/dist/src/users/users.js +6 -23
- package/dist/src/users/users.js.map +1 -1
- package/dist/src/users/utils.d.ts +0 -1
- package/dist/src/users/utils.js +1 -2
- package/dist/src/users/utils.js.map +1 -1
- package/dist/tests/core/utilities/structures/licenses.js +0 -13
- package/dist/tests/core/utilities/structures/licenses.js.map +1 -1
- package/dist/tests/core/utilities/structures/quotas.d.ts +1 -1
- package/dist/tests/core/utilities/structures/quotas.js +2 -3
- package/dist/tests/core/utilities/structures/quotas.js.map +1 -1
- package/package.json +4 -4
- package/src/cache/writethrough.ts +2 -2
- package/src/users/db.ts +51 -67
- package/src/users/users.ts +8 -19
- package/src/users/utils.ts +0 -1
- package/tests/core/utilities/structures/licenses.ts +0 -13
- package/tests/core/utilities/structures/quotas.ts +2 -3
- package/tests/core/users/users.spec.js +0 -54
package/dist/index.js
CHANGED
|
@@ -2141,8 +2141,8 @@ var init_pouchDB = __esm({
|
|
|
2141
2141
|
import_pouchdb.default.adapter("writableStream", replicationStream.adapters.writableStream);
|
|
2142
2142
|
}
|
|
2143
2143
|
if (opts.find) {
|
|
2144
|
-
const
|
|
2145
|
-
import_pouchdb.default.plugin(
|
|
2144
|
+
const find = require("pouchdb-find");
|
|
2145
|
+
import_pouchdb.default.plugin(find);
|
|
2146
2146
|
}
|
|
2147
2147
|
return import_pouchdb.default.defaults(POUCH_DB_DEFAULTS);
|
|
2148
2148
|
};
|
|
@@ -2581,12 +2581,12 @@ function getAppId() {
|
|
|
2581
2581
|
return foundId;
|
|
2582
2582
|
}
|
|
2583
2583
|
}
|
|
2584
|
-
function doInEnvironmentContext(
|
|
2585
|
-
if (!
|
|
2584
|
+
function doInEnvironmentContext(values, task) {
|
|
2585
|
+
if (!values) {
|
|
2586
2586
|
throw new Error("Must supply environment variables.");
|
|
2587
2587
|
}
|
|
2588
2588
|
const updates = {
|
|
2589
|
-
environmentVariables:
|
|
2589
|
+
environmentVariables: values
|
|
2590
2590
|
};
|
|
2591
2591
|
return newContext(updates, task);
|
|
2592
2592
|
}
|
|
@@ -6254,7 +6254,6 @@ __export(users_exports3, {
|
|
|
6254
6254
|
getAccountHolderFromUserIds: () => getAccountHolderFromUserIds,
|
|
6255
6255
|
getAllUserIds: () => getAllUserIds,
|
|
6256
6256
|
getById: () => getById,
|
|
6257
|
-
getCreatorCount: () => getCreatorCount,
|
|
6258
6257
|
getExistingAccounts: () => getExistingAccounts,
|
|
6259
6258
|
getExistingPlatformUsers: () => getExistingPlatformUsers,
|
|
6260
6259
|
getExistingTenantUsers: () => getExistingTenantUsers,
|
|
@@ -6268,7 +6267,6 @@ __export(users_exports3, {
|
|
|
6268
6267
|
isAdmin: () => isAdmin2,
|
|
6269
6268
|
isAdminOrBuilder: () => isAdminOrBuilder2,
|
|
6270
6269
|
isBuilder: () => isBuilder2,
|
|
6271
|
-
isCreator: () => isCreator2,
|
|
6272
6270
|
isGlobalBuilder: () => isGlobalBuilder2,
|
|
6273
6271
|
isSupportedUserSearch: () => isSupportedUserSearch,
|
|
6274
6272
|
paginatedUsers: () => paginatedUsers,
|
|
@@ -6285,6 +6283,224 @@ init_db4();
|
|
|
6285
6283
|
init_src();
|
|
6286
6284
|
init_context2();
|
|
6287
6285
|
init_context2();
|
|
6286
|
+
function removeUserPassword(users) {
|
|
6287
|
+
if (Array.isArray(users)) {
|
|
6288
|
+
return users.map((user) => {
|
|
6289
|
+
if (user) {
|
|
6290
|
+
delete user.password;
|
|
6291
|
+
return user;
|
|
6292
|
+
}
|
|
6293
|
+
});
|
|
6294
|
+
} else if (users) {
|
|
6295
|
+
delete users.password;
|
|
6296
|
+
return users;
|
|
6297
|
+
}
|
|
6298
|
+
return users;
|
|
6299
|
+
}
|
|
6300
|
+
var isSupportedUserSearch = (query) => {
|
|
6301
|
+
const allowed = [
|
|
6302
|
+
{ op: "string" /* STRING */, key: "email" },
|
|
6303
|
+
{ op: "equal" /* EQUAL */, key: "_id" }
|
|
6304
|
+
];
|
|
6305
|
+
for (let [key, operation] of Object.entries(query)) {
|
|
6306
|
+
if (typeof operation !== "object") {
|
|
6307
|
+
return false;
|
|
6308
|
+
}
|
|
6309
|
+
const fields = Object.keys(operation || {});
|
|
6310
|
+
if (fields.length === 0) {
|
|
6311
|
+
continue;
|
|
6312
|
+
}
|
|
6313
|
+
const allowedOperation = allowed.find(
|
|
6314
|
+
(allow) => allow.op === key && fields.length === 1 && fields[0] === allow.key
|
|
6315
|
+
);
|
|
6316
|
+
if (!allowedOperation) {
|
|
6317
|
+
return false;
|
|
6318
|
+
}
|
|
6319
|
+
}
|
|
6320
|
+
return true;
|
|
6321
|
+
};
|
|
6322
|
+
var bulkGetGlobalUsersById = async (userIds, opts) => {
|
|
6323
|
+
const db = getGlobalDB();
|
|
6324
|
+
let users = (await db.allDocs({
|
|
6325
|
+
keys: userIds,
|
|
6326
|
+
include_docs: true
|
|
6327
|
+
})).rows.map((row) => row.doc);
|
|
6328
|
+
if (opts?.cleanup) {
|
|
6329
|
+
users = removeUserPassword(users);
|
|
6330
|
+
}
|
|
6331
|
+
return users;
|
|
6332
|
+
};
|
|
6333
|
+
var getAllUserIds = async () => {
|
|
6334
|
+
const db = getGlobalDB();
|
|
6335
|
+
const startKey = `${"us" /* USER */}${SEPARATOR}`;
|
|
6336
|
+
const response = await db.allDocs({
|
|
6337
|
+
startkey: startKey,
|
|
6338
|
+
endkey: `${startKey}${UNICODE_MAX}`
|
|
6339
|
+
});
|
|
6340
|
+
return response.rows.map((row) => row.id);
|
|
6341
|
+
};
|
|
6342
|
+
var bulkUpdateGlobalUsers = async (users) => {
|
|
6343
|
+
const db = getGlobalDB();
|
|
6344
|
+
return await db.bulkDocs(users);
|
|
6345
|
+
};
|
|
6346
|
+
async function getById(id, opts) {
|
|
6347
|
+
const db = getGlobalDB();
|
|
6348
|
+
let user = await db.get(id);
|
|
6349
|
+
if (opts?.cleanup) {
|
|
6350
|
+
user = removeUserPassword(user);
|
|
6351
|
+
}
|
|
6352
|
+
return user;
|
|
6353
|
+
}
|
|
6354
|
+
var getGlobalUserByEmail = async (email, opts) => {
|
|
6355
|
+
if (email == null) {
|
|
6356
|
+
throw "Must supply an email address to view";
|
|
6357
|
+
}
|
|
6358
|
+
const response = await queryGlobalView("by_email2" /* USER_BY_EMAIL */, {
|
|
6359
|
+
key: email.toLowerCase(),
|
|
6360
|
+
include_docs: true
|
|
6361
|
+
});
|
|
6362
|
+
if (Array.isArray(response)) {
|
|
6363
|
+
throw new Error(`Multiple users found with email address: ${email}`);
|
|
6364
|
+
}
|
|
6365
|
+
let user = response;
|
|
6366
|
+
if (opts?.cleanup) {
|
|
6367
|
+
user = removeUserPassword(user);
|
|
6368
|
+
}
|
|
6369
|
+
return user;
|
|
6370
|
+
};
|
|
6371
|
+
var searchGlobalUsersByApp = async (appId, opts, getOpts) => {
|
|
6372
|
+
if (typeof appId !== "string") {
|
|
6373
|
+
throw new Error("Must provide a string based app ID");
|
|
6374
|
+
}
|
|
6375
|
+
const params2 = getUsersByAppParams(appId, {
|
|
6376
|
+
include_docs: true
|
|
6377
|
+
});
|
|
6378
|
+
params2.startkey = opts && opts.startkey ? opts.startkey : params2.startkey;
|
|
6379
|
+
let response = await queryGlobalView("by_app" /* USER_BY_APP */, params2);
|
|
6380
|
+
if (!response) {
|
|
6381
|
+
response = [];
|
|
6382
|
+
}
|
|
6383
|
+
let users = Array.isArray(response) ? response : [response];
|
|
6384
|
+
if (getOpts?.cleanup) {
|
|
6385
|
+
users = removeUserPassword(users);
|
|
6386
|
+
}
|
|
6387
|
+
return users;
|
|
6388
|
+
};
|
|
6389
|
+
var searchGlobalUsersByAppAccess = async (appId, opts) => {
|
|
6390
|
+
const roleSelector = `roles.${appId}`;
|
|
6391
|
+
let orQuery = [
|
|
6392
|
+
{
|
|
6393
|
+
"builder.global": true
|
|
6394
|
+
},
|
|
6395
|
+
{
|
|
6396
|
+
"admin.global": true
|
|
6397
|
+
}
|
|
6398
|
+
];
|
|
6399
|
+
if (appId) {
|
|
6400
|
+
const roleCheck = {
|
|
6401
|
+
[roleSelector]: {
|
|
6402
|
+
$exists: true
|
|
6403
|
+
}
|
|
6404
|
+
};
|
|
6405
|
+
orQuery.push(roleCheck);
|
|
6406
|
+
}
|
|
6407
|
+
let searchOptions = {
|
|
6408
|
+
selector: {
|
|
6409
|
+
$or: orQuery,
|
|
6410
|
+
_id: {
|
|
6411
|
+
$regex: "^us_"
|
|
6412
|
+
}
|
|
6413
|
+
},
|
|
6414
|
+
limit: opts?.limit || 50
|
|
6415
|
+
};
|
|
6416
|
+
const resp = await directCouchFind(getGlobalDBName(), searchOptions);
|
|
6417
|
+
return resp?.rows;
|
|
6418
|
+
};
|
|
6419
|
+
var getGlobalUserByAppPage = (appId, user) => {
|
|
6420
|
+
if (!user) {
|
|
6421
|
+
return;
|
|
6422
|
+
}
|
|
6423
|
+
return generateAppUserID(getProdAppID(appId), user._id);
|
|
6424
|
+
};
|
|
6425
|
+
var searchGlobalUsersByEmail = async (email, opts, getOpts) => {
|
|
6426
|
+
if (typeof email !== "string") {
|
|
6427
|
+
throw new Error("Must provide a string to search by");
|
|
6428
|
+
}
|
|
6429
|
+
const lcEmail = email.toLowerCase();
|
|
6430
|
+
const startkey = opts && opts.startkey ? opts.startkey : lcEmail;
|
|
6431
|
+
let response = await queryGlobalView("by_email2" /* USER_BY_EMAIL */, {
|
|
6432
|
+
...opts,
|
|
6433
|
+
startkey,
|
|
6434
|
+
endkey: `${lcEmail}${UNICODE_MAX}`
|
|
6435
|
+
});
|
|
6436
|
+
if (!response) {
|
|
6437
|
+
response = [];
|
|
6438
|
+
}
|
|
6439
|
+
let users = Array.isArray(response) ? response : [response];
|
|
6440
|
+
if (getOpts?.cleanup) {
|
|
6441
|
+
users = removeUserPassword(users);
|
|
6442
|
+
}
|
|
6443
|
+
return users;
|
|
6444
|
+
};
|
|
6445
|
+
var PAGE_LIMIT = 8;
|
|
6446
|
+
var paginatedUsers = async ({
|
|
6447
|
+
bookmark,
|
|
6448
|
+
query,
|
|
6449
|
+
appId,
|
|
6450
|
+
limit
|
|
6451
|
+
} = {}) => {
|
|
6452
|
+
const db = getGlobalDB();
|
|
6453
|
+
const pageLimit = limit ? limit + 1 : PAGE_LIMIT + 1;
|
|
6454
|
+
const opts = {
|
|
6455
|
+
include_docs: true,
|
|
6456
|
+
limit: pageLimit
|
|
6457
|
+
};
|
|
6458
|
+
if (bookmark) {
|
|
6459
|
+
opts.startkey = bookmark;
|
|
6460
|
+
}
|
|
6461
|
+
let userList, property = "_id", getKey;
|
|
6462
|
+
if (query?.equal?._id) {
|
|
6463
|
+
userList = [await getById(query.equal._id)];
|
|
6464
|
+
} else if (appId) {
|
|
6465
|
+
userList = await searchGlobalUsersByApp(appId, opts);
|
|
6466
|
+
getKey = (doc) => getGlobalUserByAppPage(appId, doc);
|
|
6467
|
+
} else if (query?.string?.email) {
|
|
6468
|
+
userList = await searchGlobalUsersByEmail(query?.string?.email, opts);
|
|
6469
|
+
property = "email";
|
|
6470
|
+
} else {
|
|
6471
|
+
const response = await db.allDocs(getGlobalUserParams(null, opts));
|
|
6472
|
+
userList = response.rows.map((row) => row.doc);
|
|
6473
|
+
}
|
|
6474
|
+
return pagination(userList, pageLimit, {
|
|
6475
|
+
paginate: true,
|
|
6476
|
+
property,
|
|
6477
|
+
getKey
|
|
6478
|
+
});
|
|
6479
|
+
};
|
|
6480
|
+
async function getUserCount() {
|
|
6481
|
+
const response = await queryGlobalViewRaw("by_email2" /* USER_BY_EMAIL */, {
|
|
6482
|
+
limit: 0,
|
|
6483
|
+
// to be as fast as possible - we just want the total rows count
|
|
6484
|
+
include_docs: false
|
|
6485
|
+
});
|
|
6486
|
+
return response.total_rows;
|
|
6487
|
+
}
|
|
6488
|
+
function removePortalUserPermissions(user) {
|
|
6489
|
+
delete user.admin;
|
|
6490
|
+
delete user.builder;
|
|
6491
|
+
return user;
|
|
6492
|
+
}
|
|
6493
|
+
function cleanseUserObject(user, base) {
|
|
6494
|
+
delete user.admin;
|
|
6495
|
+
delete user.builder;
|
|
6496
|
+
delete user.roles;
|
|
6497
|
+
if (base) {
|
|
6498
|
+
user.admin = base.admin;
|
|
6499
|
+
user.builder = base.builder;
|
|
6500
|
+
user.roles = base.roles;
|
|
6501
|
+
}
|
|
6502
|
+
return user;
|
|
6503
|
+
}
|
|
6288
6504
|
|
|
6289
6505
|
// src/users/utils.ts
|
|
6290
6506
|
init_environment2();
|
|
@@ -6571,17 +6787,14 @@ __export(users_exports2, {
|
|
|
6571
6787
|
getGlobalUserID: () => getGlobalUserID,
|
|
6572
6788
|
hasAdminPermissions: () => hasAdminPermissions,
|
|
6573
6789
|
hasAppBuilderPermissions: () => hasAppBuilderPermissions,
|
|
6574
|
-
hasAppCreatorPermissions: () => hasAppCreatorPermissions,
|
|
6575
6790
|
hasBuilderPermissions: () => hasBuilderPermissions,
|
|
6576
6791
|
isAdmin: () => isAdmin,
|
|
6577
6792
|
isAdminOrBuilder: () => isAdminOrBuilder,
|
|
6578
6793
|
isAdminOrGlobalBuilder: () => isAdminOrGlobalBuilder,
|
|
6579
6794
|
isBuilder: () => isBuilder,
|
|
6580
|
-
isCreator: () => isCreator,
|
|
6581
6795
|
isGlobalBuilder: () => isGlobalBuilder
|
|
6582
6796
|
});
|
|
6583
6797
|
init_src();
|
|
6584
|
-
var _ = __toESM(require("lodash/fp"));
|
|
6585
6798
|
function isBuilder(user, appId) {
|
|
6586
6799
|
if (!user) {
|
|
6587
6800
|
return false;
|
|
@@ -6616,17 +6829,6 @@ function hasAppBuilderPermissions(user) {
|
|
|
6616
6829
|
const isGlobalBuilder3 = !!user.builder?.global;
|
|
6617
6830
|
return !isGlobalBuilder3 && appLength != null && appLength > 0;
|
|
6618
6831
|
}
|
|
6619
|
-
function hasAppCreatorPermissions(user) {
|
|
6620
|
-
if (!user) {
|
|
6621
|
-
return false;
|
|
6622
|
-
}
|
|
6623
|
-
return _.flow(
|
|
6624
|
-
_.get("roles"),
|
|
6625
|
-
_.values,
|
|
6626
|
-
_.find((x) => ["CREATOR", "ADMIN"].includes(x)),
|
|
6627
|
-
(x) => !!x
|
|
6628
|
-
)(user);
|
|
6629
|
-
}
|
|
6630
6832
|
function hasBuilderPermissions(user) {
|
|
6631
6833
|
if (!user) {
|
|
6632
6834
|
return false;
|
|
@@ -6639,12 +6841,6 @@ function hasAdminPermissions(user) {
|
|
|
6639
6841
|
}
|
|
6640
6842
|
return !!user.admin?.global;
|
|
6641
6843
|
}
|
|
6642
|
-
function isCreator(user) {
|
|
6643
|
-
if (!user) {
|
|
6644
|
-
return false;
|
|
6645
|
-
}
|
|
6646
|
-
return isGlobalBuilder(user) || hasAdminPermissions(user) || hasAppBuilderPermissions(user) || hasAppCreatorPermissions(user);
|
|
6647
|
-
}
|
|
6648
6844
|
function getGlobalUserID(userId) {
|
|
6649
6845
|
if (typeof userId !== "string") {
|
|
6650
6846
|
return userId;
|
|
@@ -6704,7 +6900,6 @@ var allowSortColumnByType = {
|
|
|
6704
6900
|
// src/users/utils.ts
|
|
6705
6901
|
var isBuilder2 = sdk_exports.users.isBuilder;
|
|
6706
6902
|
var isAdmin2 = sdk_exports.users.isAdmin;
|
|
6707
|
-
var isCreator2 = sdk_exports.users.isCreator;
|
|
6708
6903
|
var isGlobalBuilder2 = sdk_exports.users.isGlobalBuilder;
|
|
6709
6904
|
var isAdminOrBuilder2 = sdk_exports.users.isAdminOrBuilder;
|
|
6710
6905
|
var hasAdminPermissions2 = sdk_exports.users.hasAdminPermissions;
|
|
@@ -6738,236 +6933,6 @@ async function getAccountHolderFromUserIds(userIds) {
|
|
|
6738
6933
|
}
|
|
6739
6934
|
}
|
|
6740
6935
|
|
|
6741
|
-
// src/users/users.ts
|
|
6742
|
-
function removeUserPassword(users) {
|
|
6743
|
-
if (Array.isArray(users)) {
|
|
6744
|
-
return users.map((user) => {
|
|
6745
|
-
if (user) {
|
|
6746
|
-
delete user.password;
|
|
6747
|
-
return user;
|
|
6748
|
-
}
|
|
6749
|
-
});
|
|
6750
|
-
} else if (users) {
|
|
6751
|
-
delete users.password;
|
|
6752
|
-
return users;
|
|
6753
|
-
}
|
|
6754
|
-
return users;
|
|
6755
|
-
}
|
|
6756
|
-
var isSupportedUserSearch = (query) => {
|
|
6757
|
-
const allowed = [
|
|
6758
|
-
{ op: "string" /* STRING */, key: "email" },
|
|
6759
|
-
{ op: "equal" /* EQUAL */, key: "_id" }
|
|
6760
|
-
];
|
|
6761
|
-
for (let [key, operation] of Object.entries(query)) {
|
|
6762
|
-
if (typeof operation !== "object") {
|
|
6763
|
-
return false;
|
|
6764
|
-
}
|
|
6765
|
-
const fields = Object.keys(operation || {});
|
|
6766
|
-
if (fields.length === 0) {
|
|
6767
|
-
continue;
|
|
6768
|
-
}
|
|
6769
|
-
const allowedOperation = allowed.find(
|
|
6770
|
-
(allow) => allow.op === key && fields.length === 1 && fields[0] === allow.key
|
|
6771
|
-
);
|
|
6772
|
-
if (!allowedOperation) {
|
|
6773
|
-
return false;
|
|
6774
|
-
}
|
|
6775
|
-
}
|
|
6776
|
-
return true;
|
|
6777
|
-
};
|
|
6778
|
-
var bulkGetGlobalUsersById = async (userIds, opts) => {
|
|
6779
|
-
const db = getGlobalDB();
|
|
6780
|
-
let users = (await db.allDocs({
|
|
6781
|
-
keys: userIds,
|
|
6782
|
-
include_docs: true
|
|
6783
|
-
})).rows.map((row) => row.doc);
|
|
6784
|
-
if (opts?.cleanup) {
|
|
6785
|
-
users = removeUserPassword(users);
|
|
6786
|
-
}
|
|
6787
|
-
return users;
|
|
6788
|
-
};
|
|
6789
|
-
var getAllUserIds = async () => {
|
|
6790
|
-
const db = getGlobalDB();
|
|
6791
|
-
const startKey = `${"us" /* USER */}${SEPARATOR}`;
|
|
6792
|
-
const response = await db.allDocs({
|
|
6793
|
-
startkey: startKey,
|
|
6794
|
-
endkey: `${startKey}${UNICODE_MAX}`
|
|
6795
|
-
});
|
|
6796
|
-
return response.rows.map((row) => row.id);
|
|
6797
|
-
};
|
|
6798
|
-
var bulkUpdateGlobalUsers = async (users) => {
|
|
6799
|
-
const db = getGlobalDB();
|
|
6800
|
-
return await db.bulkDocs(users);
|
|
6801
|
-
};
|
|
6802
|
-
async function getById(id, opts) {
|
|
6803
|
-
const db = getGlobalDB();
|
|
6804
|
-
let user = await db.get(id);
|
|
6805
|
-
if (opts?.cleanup) {
|
|
6806
|
-
user = removeUserPassword(user);
|
|
6807
|
-
}
|
|
6808
|
-
return user;
|
|
6809
|
-
}
|
|
6810
|
-
var getGlobalUserByEmail = async (email, opts) => {
|
|
6811
|
-
if (email == null) {
|
|
6812
|
-
throw "Must supply an email address to view";
|
|
6813
|
-
}
|
|
6814
|
-
const response = await queryGlobalView("by_email2" /* USER_BY_EMAIL */, {
|
|
6815
|
-
key: email.toLowerCase(),
|
|
6816
|
-
include_docs: true
|
|
6817
|
-
});
|
|
6818
|
-
if (Array.isArray(response)) {
|
|
6819
|
-
throw new Error(`Multiple users found with email address: ${email}`);
|
|
6820
|
-
}
|
|
6821
|
-
let user = response;
|
|
6822
|
-
if (opts?.cleanup) {
|
|
6823
|
-
user = removeUserPassword(user);
|
|
6824
|
-
}
|
|
6825
|
-
return user;
|
|
6826
|
-
};
|
|
6827
|
-
var searchGlobalUsersByApp = async (appId, opts, getOpts) => {
|
|
6828
|
-
if (typeof appId !== "string") {
|
|
6829
|
-
throw new Error("Must provide a string based app ID");
|
|
6830
|
-
}
|
|
6831
|
-
const params2 = getUsersByAppParams(appId, {
|
|
6832
|
-
include_docs: true
|
|
6833
|
-
});
|
|
6834
|
-
params2.startkey = opts && opts.startkey ? opts.startkey : params2.startkey;
|
|
6835
|
-
let response = await queryGlobalView("by_app" /* USER_BY_APP */, params2);
|
|
6836
|
-
if (!response) {
|
|
6837
|
-
response = [];
|
|
6838
|
-
}
|
|
6839
|
-
let users = Array.isArray(response) ? response : [response];
|
|
6840
|
-
if (getOpts?.cleanup) {
|
|
6841
|
-
users = removeUserPassword(users);
|
|
6842
|
-
}
|
|
6843
|
-
return users;
|
|
6844
|
-
};
|
|
6845
|
-
var searchGlobalUsersByAppAccess = async (appId, opts) => {
|
|
6846
|
-
const roleSelector = `roles.${appId}`;
|
|
6847
|
-
let orQuery = [
|
|
6848
|
-
{
|
|
6849
|
-
"builder.global": true
|
|
6850
|
-
},
|
|
6851
|
-
{
|
|
6852
|
-
"admin.global": true
|
|
6853
|
-
}
|
|
6854
|
-
];
|
|
6855
|
-
if (appId) {
|
|
6856
|
-
const roleCheck = {
|
|
6857
|
-
[roleSelector]: {
|
|
6858
|
-
$exists: true
|
|
6859
|
-
}
|
|
6860
|
-
};
|
|
6861
|
-
orQuery.push(roleCheck);
|
|
6862
|
-
}
|
|
6863
|
-
let searchOptions = {
|
|
6864
|
-
selector: {
|
|
6865
|
-
$or: orQuery,
|
|
6866
|
-
_id: {
|
|
6867
|
-
$regex: "^us_"
|
|
6868
|
-
}
|
|
6869
|
-
},
|
|
6870
|
-
limit: opts?.limit || 50
|
|
6871
|
-
};
|
|
6872
|
-
const resp = await directCouchFind(getGlobalDBName(), searchOptions);
|
|
6873
|
-
return resp?.rows;
|
|
6874
|
-
};
|
|
6875
|
-
var getGlobalUserByAppPage = (appId, user) => {
|
|
6876
|
-
if (!user) {
|
|
6877
|
-
return;
|
|
6878
|
-
}
|
|
6879
|
-
return generateAppUserID(getProdAppID(appId), user._id);
|
|
6880
|
-
};
|
|
6881
|
-
var searchGlobalUsersByEmail = async (email, opts, getOpts) => {
|
|
6882
|
-
if (typeof email !== "string") {
|
|
6883
|
-
throw new Error("Must provide a string to search by");
|
|
6884
|
-
}
|
|
6885
|
-
const lcEmail = email.toLowerCase();
|
|
6886
|
-
const startkey = opts && opts.startkey ? opts.startkey : lcEmail;
|
|
6887
|
-
let response = await queryGlobalView("by_email2" /* USER_BY_EMAIL */, {
|
|
6888
|
-
...opts,
|
|
6889
|
-
startkey,
|
|
6890
|
-
endkey: `${lcEmail}${UNICODE_MAX}`
|
|
6891
|
-
});
|
|
6892
|
-
if (!response) {
|
|
6893
|
-
response = [];
|
|
6894
|
-
}
|
|
6895
|
-
let users = Array.isArray(response) ? response : [response];
|
|
6896
|
-
if (getOpts?.cleanup) {
|
|
6897
|
-
users = removeUserPassword(users);
|
|
6898
|
-
}
|
|
6899
|
-
return users;
|
|
6900
|
-
};
|
|
6901
|
-
var PAGE_LIMIT = 8;
|
|
6902
|
-
var paginatedUsers = async ({
|
|
6903
|
-
bookmark,
|
|
6904
|
-
query,
|
|
6905
|
-
appId
|
|
6906
|
-
} = {}) => {
|
|
6907
|
-
const db = getGlobalDB();
|
|
6908
|
-
const opts = {
|
|
6909
|
-
include_docs: true,
|
|
6910
|
-
limit: PAGE_LIMIT + 1
|
|
6911
|
-
};
|
|
6912
|
-
if (bookmark) {
|
|
6913
|
-
opts.startkey = bookmark;
|
|
6914
|
-
}
|
|
6915
|
-
let userList, property = "_id", getKey;
|
|
6916
|
-
if (query?.equal?._id) {
|
|
6917
|
-
userList = [await getById(query.equal._id)];
|
|
6918
|
-
} else if (appId) {
|
|
6919
|
-
userList = await searchGlobalUsersByApp(appId, opts);
|
|
6920
|
-
getKey = (doc) => getGlobalUserByAppPage(appId, doc);
|
|
6921
|
-
} else if (query?.string?.email) {
|
|
6922
|
-
userList = await searchGlobalUsersByEmail(query?.string?.email, opts);
|
|
6923
|
-
property = "email";
|
|
6924
|
-
} else {
|
|
6925
|
-
const response = await db.allDocs(getGlobalUserParams(null, opts));
|
|
6926
|
-
userList = response.rows.map((row) => row.doc);
|
|
6927
|
-
}
|
|
6928
|
-
return pagination(userList, PAGE_LIMIT, {
|
|
6929
|
-
paginate: true,
|
|
6930
|
-
property,
|
|
6931
|
-
getKey
|
|
6932
|
-
});
|
|
6933
|
-
};
|
|
6934
|
-
async function getUserCount() {
|
|
6935
|
-
const response = await queryGlobalViewRaw("by_email2" /* USER_BY_EMAIL */, {
|
|
6936
|
-
limit: 0,
|
|
6937
|
-
// to be as fast as possible - we just want the total rows count
|
|
6938
|
-
include_docs: false
|
|
6939
|
-
});
|
|
6940
|
-
return response.total_rows;
|
|
6941
|
-
}
|
|
6942
|
-
async function getCreatorCount() {
|
|
6943
|
-
let creators = 0;
|
|
6944
|
-
async function iterate(startPage) {
|
|
6945
|
-
const page = await paginatedUsers({ bookmark: startPage });
|
|
6946
|
-
creators += page.data.filter(isCreator2).length;
|
|
6947
|
-
if (page.hasNextPage) {
|
|
6948
|
-
await iterate(page.nextPage);
|
|
6949
|
-
}
|
|
6950
|
-
}
|
|
6951
|
-
await iterate();
|
|
6952
|
-
return creators;
|
|
6953
|
-
}
|
|
6954
|
-
function removePortalUserPermissions(user) {
|
|
6955
|
-
delete user.admin;
|
|
6956
|
-
delete user.builder;
|
|
6957
|
-
return user;
|
|
6958
|
-
}
|
|
6959
|
-
function cleanseUserObject(user, base) {
|
|
6960
|
-
delete user.admin;
|
|
6961
|
-
delete user.builder;
|
|
6962
|
-
delete user.roles;
|
|
6963
|
-
if (base) {
|
|
6964
|
-
user.admin = base.admin;
|
|
6965
|
-
user.builder = base.builder;
|
|
6966
|
-
user.roles = base.roles;
|
|
6967
|
-
}
|
|
6968
|
-
return user;
|
|
6969
|
-
}
|
|
6970
|
-
|
|
6971
6936
|
// src/users/db.ts
|
|
6972
6937
|
init_environment2();
|
|
6973
6938
|
|
|
@@ -9885,14 +9850,14 @@ var UserDB = class _UserDB {
|
|
|
9885
9850
|
userCount: response.length
|
|
9886
9851
|
};
|
|
9887
9852
|
}
|
|
9888
|
-
static async getUsersByAppAccess(
|
|
9889
|
-
const
|
|
9853
|
+
static async getUsersByAppAccess(opts) {
|
|
9854
|
+
const params2 = {
|
|
9890
9855
|
include_docs: true,
|
|
9891
|
-
limit: 50
|
|
9856
|
+
limit: opts.limit || 50
|
|
9892
9857
|
};
|
|
9893
9858
|
let response = await searchGlobalUsersByAppAccess(
|
|
9894
|
-
appId,
|
|
9895
|
-
|
|
9859
|
+
opts.appId,
|
|
9860
|
+
params2
|
|
9896
9861
|
);
|
|
9897
9862
|
return response;
|
|
9898
9863
|
}
|
|
@@ -9953,8 +9918,7 @@ var UserDB = class _UserDB {
|
|
|
9953
9918
|
}
|
|
9954
9919
|
}
|
|
9955
9920
|
const change = dbUser ? 0 : 1;
|
|
9956
|
-
|
|
9957
|
-
return _UserDB.quotas.addUsers(change, creatorsChange, async () => {
|
|
9921
|
+
return _UserDB.quotas.addUsers(change, async () => {
|
|
9958
9922
|
await validateUniqueUser(email, tenantId);
|
|
9959
9923
|
let builtUser = await _UserDB.buildUser(user, opts, tenantId, dbUser);
|
|
9960
9924
|
if (opts.currentUserId && opts.currentUserId === dbUser?._id) {
|
|
@@ -9998,7 +9962,6 @@ var UserDB = class _UserDB {
|
|
|
9998
9962
|
const tenantId = getTenantId();
|
|
9999
9963
|
let usersToSave = [];
|
|
10000
9964
|
let newUsers = [];
|
|
10001
|
-
let newCreators = [];
|
|
10002
9965
|
const emails = newUsersRequested.map((user) => user.email);
|
|
10003
9966
|
const existingEmails = await searchExistingEmails(emails);
|
|
10004
9967
|
const unsuccessful = [];
|
|
@@ -10014,56 +9977,49 @@ var UserDB = class _UserDB {
|
|
|
10014
9977
|
}
|
|
10015
9978
|
newUser.userGroups = groups;
|
|
10016
9979
|
newUsers.push(newUser);
|
|
10017
|
-
if (isCreator2(newUser)) {
|
|
10018
|
-
newCreators.push(newUser);
|
|
10019
|
-
}
|
|
10020
9980
|
}
|
|
10021
9981
|
const account = await getAccountByTenantId(tenantId);
|
|
10022
|
-
return _UserDB.quotas.addUsers(
|
|
10023
|
-
newUsers.
|
|
10024
|
-
|
|
10025
|
-
|
|
10026
|
-
|
|
10027
|
-
|
|
10028
|
-
|
|
10029
|
-
user
|
|
10030
|
-
|
|
10031
|
-
|
|
10032
|
-
|
|
10033
|
-
|
|
10034
|
-
|
|
10035
|
-
|
|
10036
|
-
|
|
10037
|
-
|
|
10038
|
-
|
|
10039
|
-
|
|
10040
|
-
|
|
10041
|
-
|
|
10042
|
-
await
|
|
10043
|
-
|
|
10044
|
-
|
|
10045
|
-
await handleSaveEvents(user, void 0);
|
|
10046
|
-
}
|
|
10047
|
-
const saved = usersToBulkSave.map((user) => {
|
|
10048
|
-
return {
|
|
10049
|
-
_id: user._id,
|
|
10050
|
-
email: user.email
|
|
10051
|
-
};
|
|
10052
|
-
});
|
|
10053
|
-
if (Array.isArray(saved) && groups) {
|
|
10054
|
-
const groupPromises = [];
|
|
10055
|
-
const createdUserIds = saved.map((user) => user._id);
|
|
10056
|
-
for (let groupId of groups) {
|
|
10057
|
-
groupPromises.push(_UserDB.groups.addUsers(groupId, createdUserIds));
|
|
10058
|
-
}
|
|
10059
|
-
await Promise.all(groupPromises);
|
|
10060
|
-
}
|
|
9982
|
+
return _UserDB.quotas.addUsers(newUsers.length, async () => {
|
|
9983
|
+
newUsers.forEach((user) => {
|
|
9984
|
+
usersToSave.push(
|
|
9985
|
+
_UserDB.buildUser(
|
|
9986
|
+
user,
|
|
9987
|
+
{
|
|
9988
|
+
hashPassword: true,
|
|
9989
|
+
requirePassword: user.requirePassword
|
|
9990
|
+
},
|
|
9991
|
+
tenantId,
|
|
9992
|
+
void 0,
|
|
9993
|
+
// no dbUser
|
|
9994
|
+
account
|
|
9995
|
+
)
|
|
9996
|
+
);
|
|
9997
|
+
});
|
|
9998
|
+
const usersToBulkSave = await Promise.all(usersToSave);
|
|
9999
|
+
await bulkUpdateGlobalUsers(usersToBulkSave);
|
|
10000
|
+
for (const user of usersToBulkSave) {
|
|
10001
|
+
await users_exports.addUser(tenantId, user._id, user.email);
|
|
10002
|
+
await handleSaveEvents(user, void 0);
|
|
10003
|
+
}
|
|
10004
|
+
const saved = usersToBulkSave.map((user) => {
|
|
10061
10005
|
return {
|
|
10062
|
-
|
|
10063
|
-
|
|
10006
|
+
_id: user._id,
|
|
10007
|
+
email: user.email
|
|
10064
10008
|
};
|
|
10009
|
+
});
|
|
10010
|
+
if (Array.isArray(saved) && groups) {
|
|
10011
|
+
const groupPromises = [];
|
|
10012
|
+
const createdUserIds = saved.map((user) => user._id);
|
|
10013
|
+
for (let groupId of groups) {
|
|
10014
|
+
groupPromises.push(_UserDB.groups.addUsers(groupId, createdUserIds));
|
|
10015
|
+
}
|
|
10016
|
+
await Promise.all(groupPromises);
|
|
10065
10017
|
}
|
|
10066
|
-
|
|
10018
|
+
return {
|
|
10019
|
+
successful: saved,
|
|
10020
|
+
unsuccessful
|
|
10021
|
+
};
|
|
10022
|
+
});
|
|
10067
10023
|
}
|
|
10068
10024
|
static async bulkDelete(userIds) {
|
|
10069
10025
|
const db = getGlobalDB();
|
|
@@ -10094,11 +10050,10 @@ var UserDB = class _UserDB {
|
|
|
10094
10050
|
_deleted: true
|
|
10095
10051
|
}));
|
|
10096
10052
|
const dbResponse = await bulkUpdateGlobalUsers(toDelete);
|
|
10097
|
-
|
|
10053
|
+
await _UserDB.quotas.removeUsers(toDelete.length);
|
|
10098
10054
|
for (let user of usersToDelete) {
|
|
10099
10055
|
await bulkDeleteProcessing(user);
|
|
10100
10056
|
}
|
|
10101
|
-
await _UserDB.quotas.removeUsers(toDelete.length, creatorsToDelete.length);
|
|
10102
10057
|
const userIndex = {};
|
|
10103
10058
|
usersToDelete.reduce((prev, current) => {
|
|
10104
10059
|
prev[current._id] = current;
|
|
@@ -10135,8 +10090,7 @@ var UserDB = class _UserDB {
|
|
|
10135
10090
|
}
|
|
10136
10091
|
await users_exports.removeUser(dbUser);
|
|
10137
10092
|
await db.remove(userId, dbUser._rev);
|
|
10138
|
-
|
|
10139
|
-
await _UserDB.quotas.removeUsers(1, creatorsToDelete);
|
|
10093
|
+
await _UserDB.quotas.removeUsers(1);
|
|
10140
10094
|
await handleDeleteEvents(dbUser);
|
|
10141
10095
|
await user_exports.invalidateUser(userId);
|
|
10142
10096
|
await invalidateSessions(userId, { reason: "deletion" });
|
|
@@ -10313,7 +10267,7 @@ async function put(db, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
|
10313
10267
|
}
|
|
10314
10268
|
return { ok: true, id: output._id, rev: output._rev };
|
|
10315
10269
|
}
|
|
10316
|
-
async function
|
|
10270
|
+
async function get2(db, id) {
|
|
10317
10271
|
const cache = await getCache();
|
|
10318
10272
|
const cacheKey = makeCacheKey(db, id);
|
|
10319
10273
|
let cacheItem = await cache.get(cacheKey);
|
|
@@ -10342,11 +10296,11 @@ var Writethrough = class {
|
|
|
10342
10296
|
this.db = db;
|
|
10343
10297
|
this.writeRateMs = writeRateMs;
|
|
10344
10298
|
}
|
|
10345
|
-
async put(doc
|
|
10346
|
-
return put(this.db, doc, writeRateMs);
|
|
10299
|
+
async put(doc) {
|
|
10300
|
+
return put(this.db, doc, this.writeRateMs);
|
|
10347
10301
|
}
|
|
10348
10302
|
async get(id) {
|
|
10349
|
-
return
|
|
10303
|
+
return get2(this.db, id);
|
|
10350
10304
|
}
|
|
10351
10305
|
async remove(docOrId, rev) {
|
|
10352
10306
|
return remove(this.db, docOrId, rev);
|