@budibase/worker 2.8.29 → 2.8.31-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/jest.config.ts +0 -2
- package/nodemon.json +9 -6
- package/package.json +12 -27
- package/scripts/test.sh +2 -2
- package/src/api/controllers/global/auth.ts +5 -5
- package/src/api/controllers/global/configs.ts +3 -3
- package/src/api/controllers/global/email.ts +3 -3
- package/src/api/controllers/global/roles.ts +7 -7
- package/src/api/controllers/global/self.ts +4 -4
- package/src/api/controllers/global/users.ts +14 -14
- package/src/api/controllers/system/logs.ts +13 -0
- package/src/api/routes/global/tests/appBuilder.spec.ts +62 -0
- package/src/api/routes/global/tests/auth.spec.ts +3 -3
- package/src/api/routes/global/tests/scim.spec.ts +2 -2
- package/src/api/routes/global/tests/self.spec.ts +2 -2
- package/src/api/routes/global/tests/users.spec.ts +2 -2
- package/src/api/routes/index.ts +8 -0
- package/src/api/routes/system/logs.ts +9 -0
- package/src/api/routes/system/tests/status.spec.ts +7 -4
- package/src/environment.ts +5 -1
- package/src/initPro.ts +1 -8
- package/src/migrations/functions/globalInfoSyncUsers.ts +1 -1
- package/src/sdk/auth/auth.ts +8 -9
- package/src/sdk/users/index.ts +5 -0
- package/src/sdk/users/tests/users.spec.ts +8 -8
- package/src/sdk/users/users.ts +7 -590
- package/src/tests/TestConfiguration.ts +4 -4
- package/src/tests/api/users.ts +20 -0
- package/src/tests/mocks/index.ts +1 -1
- package/tsconfig.json +2 -4
- package/src/sdk/users/events.ts +0 -176
package/src/sdk/auth/auth.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
auth as authCore,
|
|
3
|
-
|
|
4
|
-
utils as coreUtils,
|
|
5
|
-
sessions,
|
|
3
|
+
env as coreEnv,
|
|
6
4
|
events,
|
|
7
5
|
HTTPError,
|
|
8
|
-
|
|
6
|
+
sessions,
|
|
7
|
+
tenancy,
|
|
8
|
+
utils as coreUtils,
|
|
9
9
|
} from "@budibase/backend-core"
|
|
10
10
|
import { PlatformLogoutOpts, User } from "@budibase/types"
|
|
11
11
|
import jwt from "jsonwebtoken"
|
|
@@ -20,7 +20,7 @@ export async function loginUser(user: User) {
|
|
|
20
20
|
const sessionId = coreUtils.newid()
|
|
21
21
|
const tenantId = tenancy.getTenantId()
|
|
22
22
|
await sessions.createASession(user._id!, { sessionId, tenantId })
|
|
23
|
-
|
|
23
|
+
return jwt.sign(
|
|
24
24
|
{
|
|
25
25
|
userId: user._id,
|
|
26
26
|
sessionId,
|
|
@@ -28,7 +28,6 @@ export async function loginUser(user: User) {
|
|
|
28
28
|
},
|
|
29
29
|
coreEnv.JWT_SECRET!
|
|
30
30
|
)
|
|
31
|
-
return token
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
export async function logout(opts: PlatformLogoutOpts) {
|
|
@@ -58,7 +57,7 @@ export const reset = async (email: string) => {
|
|
|
58
57
|
}
|
|
59
58
|
|
|
60
59
|
// exit if user has sso
|
|
61
|
-
if (await userSdk.isPreventPasswordActions(user)) {
|
|
60
|
+
if (await userSdk.db.isPreventPasswordActions(user)) {
|
|
62
61
|
return
|
|
63
62
|
}
|
|
64
63
|
|
|
@@ -76,9 +75,9 @@ export const reset = async (email: string) => {
|
|
|
76
75
|
export const resetUpdate = async (resetCode: string, password: string) => {
|
|
77
76
|
const { userId } = await redis.checkResetPasswordCode(resetCode)
|
|
78
77
|
|
|
79
|
-
let user = await userSdk.getUser(userId)
|
|
78
|
+
let user = await userSdk.db.getUser(userId)
|
|
80
79
|
user.password = password
|
|
81
|
-
user = await userSdk.save(user)
|
|
80
|
+
user = await userSdk.db.save(user)
|
|
82
81
|
|
|
83
82
|
// remove password from the user before sending events
|
|
84
83
|
delete user.password
|
package/src/sdk/users/index.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
export * from "./users"
|
|
2
|
+
import { users } from "@budibase/backend-core"
|
|
3
|
+
import * as pro from "@budibase/pro"
|
|
4
|
+
// pass in the components which are specific to the worker/the parts of pro which backend-core cannot access
|
|
5
|
+
users.UserDB.init(pro.quotas, pro.groups, pro.features)
|
|
6
|
+
export const db = users.UserDB
|
|
2
7
|
export { users as core } from "@budibase/backend-core"
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { structures, mocks } from "../../../tests"
|
|
2
2
|
import { env, context } from "@budibase/backend-core"
|
|
3
3
|
import * as users from "../users"
|
|
4
|
+
import { db as userDb } from "../"
|
|
4
5
|
import { CloudAccount } from "@budibase/types"
|
|
5
|
-
import { isPreventPasswordActions } from "../users"
|
|
6
6
|
|
|
7
7
|
describe("users", () => {
|
|
8
8
|
beforeEach(() => {
|
|
@@ -13,7 +13,7 @@ describe("users", () => {
|
|
|
13
13
|
it("returns false for non sso user", async () => {
|
|
14
14
|
await context.doInTenant(structures.tenant.id(), async () => {
|
|
15
15
|
const user = structures.users.user()
|
|
16
|
-
const result = await
|
|
16
|
+
const result = await userDb.isPreventPasswordActions(user)
|
|
17
17
|
expect(result).toBe(false)
|
|
18
18
|
})
|
|
19
19
|
})
|
|
@@ -24,7 +24,7 @@ describe("users", () => {
|
|
|
24
24
|
const account = structures.accounts.ssoAccount() as CloudAccount
|
|
25
25
|
account.email = user.email
|
|
26
26
|
mocks.accounts.getAccountByTenantId.mockResolvedValueOnce(account)
|
|
27
|
-
const result = await
|
|
27
|
+
const result = await userDb.isPreventPasswordActions(user)
|
|
28
28
|
expect(result).toBe(true)
|
|
29
29
|
})
|
|
30
30
|
})
|
|
@@ -34,7 +34,7 @@ describe("users", () => {
|
|
|
34
34
|
const user = structures.users.user()
|
|
35
35
|
const account = structures.accounts.ssoAccount() as CloudAccount
|
|
36
36
|
mocks.accounts.getAccountByTenantId.mockResolvedValueOnce(account)
|
|
37
|
-
const result = await
|
|
37
|
+
const result = await userDb.isPreventPasswordActions(user)
|
|
38
38
|
expect(result).toBe(false)
|
|
39
39
|
})
|
|
40
40
|
})
|
|
@@ -42,7 +42,7 @@ describe("users", () => {
|
|
|
42
42
|
it("returns true for sso user", async () => {
|
|
43
43
|
await context.doInTenant(structures.tenant.id(), async () => {
|
|
44
44
|
const user = structures.users.ssoUser()
|
|
45
|
-
const result = await
|
|
45
|
+
const result = await userDb.isPreventPasswordActions(user)
|
|
46
46
|
expect(result).toBe(true)
|
|
47
47
|
})
|
|
48
48
|
})
|
|
@@ -52,7 +52,7 @@ describe("users", () => {
|
|
|
52
52
|
await context.doInTenant(structures.tenant.id(), async () => {
|
|
53
53
|
const user = structures.users.user()
|
|
54
54
|
mocks.pro.features.isSSOEnforced.mockResolvedValueOnce(true)
|
|
55
|
-
const result = await
|
|
55
|
+
const result = await userDb.isPreventPasswordActions(user)
|
|
56
56
|
expect(result).toBe(true)
|
|
57
57
|
})
|
|
58
58
|
})
|
|
@@ -70,7 +70,7 @@ describe("users", () => {
|
|
|
70
70
|
describe("non-admin user", () => {
|
|
71
71
|
it("returns true", async () => {
|
|
72
72
|
const user = structures.users.ssoUser()
|
|
73
|
-
const result = await
|
|
73
|
+
const result = await userDb.isPreventPasswordActions(user)
|
|
74
74
|
expect(result).toBe(true)
|
|
75
75
|
})
|
|
76
76
|
})
|
|
@@ -80,7 +80,7 @@ describe("users", () => {
|
|
|
80
80
|
const user = structures.users.ssoUser({
|
|
81
81
|
user: structures.users.adminUser(),
|
|
82
82
|
})
|
|
83
|
-
const result = await
|
|
83
|
+
const result = await userDb.isPreventPasswordActions(user)
|
|
84
84
|
expect(result).toBe(false)
|
|
85
85
|
})
|
|
86
86
|
})
|