@budibase/worker 1.3.21 → 1.3.22-alpha.0
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/package.json +6 -6
- package/scripts/localdomain.js +3 -1
- package/src/api/controllers/global/self.js +19 -3
- package/src/api/routes/global/tests/self.spec.ts +7 -1
- package/src/environment.ts +1 -0
- package/src/sdk/users/events.ts +5 -1
- package/src/sdk/users/users.ts +21 -46
- package/src/tests/api/users.ts +1 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/worker",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.22-alpha.0",
|
|
5
5
|
"description": "Budibase background service",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"author": "Budibase",
|
|
37
37
|
"license": "GPL-3.0",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@budibase/backend-core": "
|
|
40
|
-
"@budibase/pro": "1.3.
|
|
41
|
-
"@budibase/string-templates": "
|
|
42
|
-
"@budibase/types": "
|
|
39
|
+
"@budibase/backend-core": "1.3.22-alpha.0",
|
|
40
|
+
"@budibase/pro": "1.3.21",
|
|
41
|
+
"@budibase/string-templates": "1.3.22-alpha.0",
|
|
42
|
+
"@budibase/types": "1.3.22-alpha.0",
|
|
43
43
|
"@koa/router": "8.0.8",
|
|
44
44
|
"@sentry/node": "6.17.7",
|
|
45
45
|
"@techpass/passport-openidconnect": "0.3.2",
|
|
@@ -104,5 +104,5 @@
|
|
|
104
104
|
"./scripts/jestSetup.js"
|
|
105
105
|
]
|
|
106
106
|
},
|
|
107
|
-
"gitHead": "
|
|
107
|
+
"gitHead": "a3ecd6c8bd5acee4c08441dd61d5331115bc3c6e"
|
|
108
108
|
}
|
package/scripts/localdomain.js
CHANGED
|
@@ -17,7 +17,9 @@ const arg = process.argv.slice(2)[0]
|
|
|
17
17
|
*/
|
|
18
18
|
updateDotEnv({
|
|
19
19
|
ACCOUNT_PORTAL_URL:
|
|
20
|
-
arg === "enable"
|
|
20
|
+
arg === "enable"
|
|
21
|
+
? "http://account.local.com:10001"
|
|
22
|
+
: "http://localhost:10001",
|
|
21
23
|
COOKIE_DOMAIN: arg === "enable" ? ".local.com" : "",
|
|
22
24
|
PLATFORM_URL:
|
|
23
25
|
arg === "enable" ? "http://local.com:10000" : "http://localhost:10000",
|
|
@@ -16,6 +16,11 @@ const { newid } = require("@budibase/backend-core/utils")
|
|
|
16
16
|
const { users } = require("../../../sdk")
|
|
17
17
|
const { Cookies } = require("@budibase/backend-core/constants")
|
|
18
18
|
const { events, featureFlags } = require("@budibase/backend-core")
|
|
19
|
+
const env = require("../../../environment")
|
|
20
|
+
|
|
21
|
+
function newTestApiKey() {
|
|
22
|
+
return env.ENCRYPTED_TEST_PUBLIC_API_KEY
|
|
23
|
+
}
|
|
19
24
|
|
|
20
25
|
function newApiKey() {
|
|
21
26
|
return encrypt(`${getTenantId()}${SEPARATOR}${newid()}`)
|
|
@@ -29,15 +34,25 @@ function cleanupDevInfo(info) {
|
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
exports.generateAPIKey = async ctx => {
|
|
37
|
+
let userId
|
|
38
|
+
let apiKey
|
|
39
|
+
if (env.isTest() && ctx.request.body.userId) {
|
|
40
|
+
userId = ctx.request.body.userId
|
|
41
|
+
apiKey = newTestApiKey()
|
|
42
|
+
} else {
|
|
43
|
+
userId = ctx.user._id
|
|
44
|
+
apiKey = newApiKey()
|
|
45
|
+
}
|
|
46
|
+
|
|
32
47
|
const db = getGlobalDB()
|
|
33
|
-
const id = generateDevInfoID(
|
|
48
|
+
const id = generateDevInfoID(userId)
|
|
34
49
|
let devInfo
|
|
35
50
|
try {
|
|
36
51
|
devInfo = await db.get(id)
|
|
37
52
|
} catch (err) {
|
|
38
|
-
devInfo = { _id: id, userId
|
|
53
|
+
devInfo = { _id: id, userId }
|
|
39
54
|
}
|
|
40
|
-
devInfo.apiKey = await
|
|
55
|
+
devInfo.apiKey = await apiKey
|
|
41
56
|
await db.put(devInfo)
|
|
42
57
|
ctx.body = cleanupDevInfo(devInfo)
|
|
43
58
|
}
|
|
@@ -141,6 +156,7 @@ exports.updateSelf = async ctx => {
|
|
|
141
156
|
}
|
|
142
157
|
|
|
143
158
|
// remove the old password from the user before sending events
|
|
159
|
+
user._rev = response.rev
|
|
144
160
|
delete user.password
|
|
145
161
|
await events.user.updated(user)
|
|
146
162
|
if (passwordChange) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
jest.mock("nodemailer")
|
|
2
|
-
import { TestConfiguration, API } from "../../../../tests"
|
|
2
|
+
import { TestConfiguration, API, mocks } from "../../../../tests"
|
|
3
3
|
import { events } from "@budibase/backend-core"
|
|
4
4
|
|
|
5
5
|
describe("/api/global/self", () => {
|
|
@@ -26,6 +26,9 @@ describe("/api/global/self", () => {
|
|
|
26
26
|
delete user.password
|
|
27
27
|
const res = await api.self.updateSelf(user)
|
|
28
28
|
|
|
29
|
+
const dbUser = await config.getUser(user.email)
|
|
30
|
+
user._rev = dbUser._rev
|
|
31
|
+
user.dayPassRecordedAt = mocks.date.MOCK_DATE.toISOString()
|
|
29
32
|
expect(res.body._id).toBe(user._id)
|
|
30
33
|
expect(events.user.updated).toBeCalledTimes(1)
|
|
31
34
|
expect(events.user.updated).toBeCalledWith(user)
|
|
@@ -39,6 +42,9 @@ describe("/api/global/self", () => {
|
|
|
39
42
|
user.password = "newPassword"
|
|
40
43
|
const res = await api.self.updateSelf(user)
|
|
41
44
|
|
|
45
|
+
const dbUser = await config.getUser(user.email)
|
|
46
|
+
user._rev = dbUser._rev
|
|
47
|
+
user.dayPassRecordedAt = mocks.date.MOCK_DATE.toISOString()
|
|
42
48
|
delete user.password
|
|
43
49
|
expect(res.body._id).toBe(user._id)
|
|
44
50
|
expect(events.user.updated).toBeCalledTimes(1)
|
package/src/environment.ts
CHANGED
|
@@ -63,6 +63,7 @@ const env = {
|
|
|
63
63
|
// other
|
|
64
64
|
CHECKLIST_CACHE_TTL: parseIntSafe(process.env.CHECKLIST_CACHE_TTL) || 3600,
|
|
65
65
|
SESSION_UPDATE_PERIOD: process.env.SESSION_UPDATE_PERIOD,
|
|
66
|
+
ENCRYPTED_TEST_PUBLIC_API_KEY: process.env.ENCRYPTED_TEST_PUBLIC_API_KEY,
|
|
66
67
|
_set(key: any, value: any) {
|
|
67
68
|
process.env[key] = value
|
|
68
69
|
module.exports[key] = value
|
package/src/sdk/users/events.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import env from "../../environment"
|
|
2
2
|
import { events, accounts, tenancy } from "@budibase/backend-core"
|
|
3
3
|
import { User, UserRoles, CloudAccount } from "@budibase/types"
|
|
4
|
+
import { users as pro } from "@budibase/pro"
|
|
4
5
|
|
|
5
6
|
export const handleDeleteEvents = async (user: any) => {
|
|
6
7
|
await events.user.deleted(user)
|
|
@@ -51,7 +52,10 @@ const handleAppRoleEvents = async (user: any, existingUser: any) => {
|
|
|
51
52
|
await unassignAppRoleEvents(user, roles, existingRoles)
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
export const handleSaveEvents = async (
|
|
55
|
+
export const handleSaveEvents = async (
|
|
56
|
+
user: User,
|
|
57
|
+
existingUser: User | undefined
|
|
58
|
+
) => {
|
|
55
59
|
const tenantId = tenancy.getTenantId()
|
|
56
60
|
let tenantAccount: CloudAccount | undefined
|
|
57
61
|
if (!env.SELF_HOSTED && !env.DISABLE_ACCOUNT_PORTAL) {
|
package/src/sdk/users/users.ts
CHANGED
|
@@ -1,37 +1,35 @@
|
|
|
1
1
|
import env from "../../environment"
|
|
2
|
-
import { quotas } from "@budibase/pro"
|
|
3
2
|
import * as apps from "../../utilities/appService"
|
|
4
3
|
import * as eventHelpers from "./events"
|
|
5
4
|
import {
|
|
6
|
-
|
|
7
|
-
utils,
|
|
8
|
-
db as dbUtils,
|
|
9
|
-
constants,
|
|
5
|
+
accounts,
|
|
10
6
|
cache,
|
|
11
|
-
|
|
7
|
+
constants,
|
|
8
|
+
db as dbUtils,
|
|
12
9
|
deprovisioning,
|
|
13
|
-
|
|
10
|
+
events,
|
|
14
11
|
HTTPError,
|
|
15
|
-
accounts,
|
|
16
12
|
migrations,
|
|
17
|
-
|
|
13
|
+
sessions,
|
|
14
|
+
tenancy,
|
|
15
|
+
users as usersCore,
|
|
16
|
+
utils,
|
|
18
17
|
ViewName,
|
|
19
|
-
events,
|
|
20
18
|
} from "@budibase/backend-core"
|
|
21
19
|
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
User,
|
|
20
|
+
AccountMetadata,
|
|
21
|
+
AllDocsResponse,
|
|
25
22
|
BulkCreateUsersResponse,
|
|
26
|
-
CreateUserResponse,
|
|
27
23
|
BulkDeleteUsersResponse,
|
|
28
|
-
CloudAccount,
|
|
29
|
-
AllDocsResponse,
|
|
30
|
-
RowResponse,
|
|
31
24
|
BulkDocsResponse,
|
|
32
|
-
|
|
25
|
+
CloudAccount,
|
|
26
|
+
CreateUserResponse,
|
|
33
27
|
InviteUsersRequest,
|
|
34
28
|
InviteUsersResponse,
|
|
29
|
+
MigrationType,
|
|
30
|
+
PlatformUserByEmail,
|
|
31
|
+
RowResponse,
|
|
32
|
+
User,
|
|
35
33
|
} from "@budibase/types"
|
|
36
34
|
import { groups as groupUtils } from "@budibase/pro"
|
|
37
35
|
import { sendEmail } from "../../utilities/email"
|
|
@@ -120,7 +118,7 @@ interface SaveUserOpts {
|
|
|
120
118
|
}
|
|
121
119
|
|
|
122
120
|
const buildUser = async (
|
|
123
|
-
user:
|
|
121
|
+
user: User,
|
|
124
122
|
opts: SaveUserOpts = {
|
|
125
123
|
hashPassword: true,
|
|
126
124
|
requirePassword: true,
|
|
@@ -230,16 +228,7 @@ export const save = async (
|
|
|
230
228
|
|
|
231
229
|
try {
|
|
232
230
|
// save the user to db
|
|
233
|
-
let response
|
|
234
|
-
const putUserFn = () => {
|
|
235
|
-
return db.put(builtUser)
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
if (eventHelpers.isAddingBuilder(builtUser, dbUser)) {
|
|
239
|
-
response = await quotas.addDeveloper(putUserFn)
|
|
240
|
-
} else {
|
|
241
|
-
response = await putUserFn()
|
|
242
|
-
}
|
|
231
|
+
let response = await db.put(builtUser)
|
|
243
232
|
builtUser._rev = response.rev
|
|
244
233
|
|
|
245
234
|
await eventHelpers.handleSaveEvents(builtUser, dbUser)
|
|
@@ -388,13 +377,8 @@ export const bulkCreate = async (
|
|
|
388
377
|
newUsers.push(newUser)
|
|
389
378
|
}
|
|
390
379
|
|
|
391
|
-
//
|
|
392
|
-
// array that will be called by bulkDocs
|
|
393
|
-
let builderCount = 0
|
|
380
|
+
// create the promises array that will be called by bulkDocs
|
|
394
381
|
newUsers.forEach((user: any) => {
|
|
395
|
-
if (eventHelpers.isAddingBuilder(user, null)) {
|
|
396
|
-
builderCount++
|
|
397
|
-
}
|
|
398
382
|
usersToSave.push(
|
|
399
383
|
buildUser(
|
|
400
384
|
user,
|
|
@@ -408,14 +392,14 @@ export const bulkCreate = async (
|
|
|
408
392
|
})
|
|
409
393
|
|
|
410
394
|
const usersToBulkSave = await Promise.all(usersToSave)
|
|
411
|
-
await
|
|
395
|
+
await db.bulkDocs(usersToBulkSave)
|
|
412
396
|
|
|
413
397
|
// Post processing of bulk added users, i.e events and cache operations
|
|
414
398
|
for (const user of usersToBulkSave) {
|
|
415
399
|
// TODO: Refactor to bulk insert users into the info db
|
|
416
400
|
// instead of relying on looping tenant creation
|
|
417
401
|
await addTenant(tenantId, user._id, user.email)
|
|
418
|
-
await eventHelpers.handleSaveEvents(user,
|
|
402
|
+
await eventHelpers.handleSaveEvents(user, undefined)
|
|
419
403
|
await apps.syncUserInApps(user._id)
|
|
420
404
|
}
|
|
421
405
|
|
|
@@ -475,8 +459,6 @@ export const bulkDelete = async (
|
|
|
475
459
|
}
|
|
476
460
|
|
|
477
461
|
let groupsToModify: any = {}
|
|
478
|
-
let builderCount = 0
|
|
479
|
-
|
|
480
462
|
// Get users and delete
|
|
481
463
|
const allDocsResponse: AllDocsResponse<User> = await db.allDocs({
|
|
482
464
|
include_docs: true,
|
|
@@ -497,11 +479,6 @@ export const bulkDelete = async (
|
|
|
497
479
|
}
|
|
498
480
|
}
|
|
499
481
|
|
|
500
|
-
// Also figure out how many builders are being deleted
|
|
501
|
-
if (eventHelpers.isAddingBuilder(user.doc, null)) {
|
|
502
|
-
builderCount++
|
|
503
|
-
}
|
|
504
|
-
|
|
505
482
|
return user.doc
|
|
506
483
|
}
|
|
507
484
|
)
|
|
@@ -519,7 +496,6 @@ export const bulkDelete = async (
|
|
|
519
496
|
for (let user of usersToDelete) {
|
|
520
497
|
await bulkDeleteProcessing(user)
|
|
521
498
|
}
|
|
522
|
-
await quotas.removeDevelopers(builderCount)
|
|
523
499
|
|
|
524
500
|
// Build Response
|
|
525
501
|
// index users by id
|
|
@@ -574,7 +550,6 @@ export const destroy = async (id: string, currentUser: any) => {
|
|
|
574
550
|
}
|
|
575
551
|
|
|
576
552
|
await eventHelpers.handleDeleteEvents(dbUser)
|
|
577
|
-
await quotas.removeUser(dbUser)
|
|
578
553
|
await cache.user.invalidateUser(userId)
|
|
579
554
|
await sessions.invalidateSessions(userId, { reason: "deletion" })
|
|
580
555
|
// let server know to sync user
|
package/src/tests/api/users.ts
CHANGED
|
@@ -2,10 +2,9 @@ import {
|
|
|
2
2
|
BulkCreateUsersRequest,
|
|
3
3
|
BulkCreateUsersResponse,
|
|
4
4
|
BulkDeleteUsersRequest,
|
|
5
|
-
|
|
5
|
+
BulkDeleteUsersResponse,
|
|
6
6
|
InviteUsersRequest,
|
|
7
7
|
User,
|
|
8
|
-
UserDetails,
|
|
9
8
|
} from "@budibase/types"
|
|
10
9
|
import TestConfiguration from "../TestConfiguration"
|
|
11
10
|
|