From 4e13dde65748826b5c5881f68ff915b6e9ac9878 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 3 Aug 2021 17:14:17 +0100 Subject: [PATCH] Fixing some issues highlighted by worker test cases. --- packages/auth/src/tenancy/context.js | 4 ---- packages/worker/src/api/controllers/global/users.js | 3 +-- .../src/api/routes/tests/utilities/TestConfiguration.js | 9 +++++++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/auth/src/tenancy/context.js b/packages/auth/src/tenancy/context.js index aa63309928..f3f1f541e9 100644 --- a/packages/auth/src/tenancy/context.js +++ b/packages/auth/src/tenancy/context.js @@ -23,10 +23,6 @@ exports.doInTenant = (tenantId, task) => { // invoke the task const result = task() - // clear down the tenant id manually for extra safety - // this should also happen automatically when the call exits - cls.setOnContext(TENANT_ID, null) - return result }) } diff --git a/packages/worker/src/api/controllers/global/users.js b/packages/worker/src/api/controllers/global/users.js index f43195a1de..24b00fe3a6 100644 --- a/packages/worker/src/api/controllers/global/users.js +++ b/packages/worker/src/api/controllers/global/users.js @@ -268,6 +268,7 @@ exports.invite = async ctx => { if (!userInfo) { userInfo = {} } + userInfo.tenantId = getTenantId() await sendEmail(email, EmailTemplatePurpose.INVITATION, { subject: "{{ company }} platform invitation", info: userInfo, @@ -292,8 +293,6 @@ exports.inviteAccept = async ctx => { }, info.tenantId ) - // this will flesh out the body response - await exports.save(ctx) } catch (err) { ctx.throw(400, "Unable to create new user, invitation invalid.") } diff --git a/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js b/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js index 3bc9c397d3..7f84de6b7d 100644 --- a/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js +++ b/packages/worker/src/api/routes/tests/utilities/TestConfiguration.js @@ -10,6 +10,7 @@ const { newid } = require("../../../../../../auth/src/hashing") const { TENANT_ID } = require("./structures") const auth = require("@budibase/auth") const CouchDB = require("../../../../db") +const { doInTenant } = require("@budibase/auth/tenancy") auth.init(CouchDB) class TestConfiguration { @@ -40,7 +41,9 @@ class TestConfiguration { if (params) { request.params = params } - await controlFunc(request) + await doInTenant(TENANT_ID, () => { + return controlFunc(request) + }) return request.body } @@ -96,7 +99,9 @@ class TestConfiguration { } async getUser(email) { - return getGlobalUserByEmail(email, TENANT_ID) + return doInTenant(TENANT_ID, () => { + return getGlobalUserByEmail(email) + }) } async createUser(email = "test@test.com", password = "test") {