@budibase/worker 2.8.31 → 2.8.32-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.
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  auth as authCore,
3
- tenancy,
4
- utils as coreUtils,
5
- sessions,
3
+ env as coreEnv,
6
4
  events,
7
5
  HTTPError,
8
- env as coreEnv,
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
- const token = jwt.sign(
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
@@ -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 users.isPreventPasswordActions(user)
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 users.isPreventPasswordActions(user)
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 users.isPreventPasswordActions(user)
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 users.isPreventPasswordActions(user)
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 users.isPreventPasswordActions(user)
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 users.isPreventPasswordActions(user)
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 users.isPreventPasswordActions(user)
83
+ const result = await userDb.isPreventPasswordActions(user)
84
84
  expect(result).toBe(false)
85
85
  })
86
86
  })