From 1fc704511d1879e9c5cc15bfa0aa835b95f0847e Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Mon, 5 Sep 2022 16:17:58 +0100 Subject: [PATCH] Clear quota cache on deprovision + gracefully handle account metadata doc deletion --- packages/worker/src/api/controllers/system/tenants.js | 2 ++ .../src/api/routes/system/tests/accounts.spec.ts | 5 +---- packages/worker/src/sdk/accounts/accounts.ts | 10 ++++++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/worker/src/api/controllers/system/tenants.js b/packages/worker/src/api/controllers/system/tenants.js index 8c0e3c5bfd..c54a3d9834 100644 --- a/packages/worker/src/api/controllers/system/tenants.js +++ b/packages/worker/src/api/controllers/system/tenants.js @@ -1,6 +1,7 @@ const { StaticDatabases, doWithDB } = require("@budibase/backend-core/db") const { getTenantId } = require("@budibase/backend-core/tenancy") const { deleteTenant } = require("@budibase/backend-core/deprovision") +const { quotas } = require("@budibase/pro") exports.exists = async ctx => { const tenantId = ctx.request.params @@ -48,6 +49,7 @@ exports.delete = async ctx => { try { await deleteTenant(tenantId) + await quotas.bustCache() ctx.status = 204 } catch (err) { ctx.log.error(err) diff --git a/packages/worker/src/api/routes/system/tests/accounts.spec.ts b/packages/worker/src/api/routes/system/tests/accounts.spec.ts index b20b7a6472..e3a6141cb7 100644 --- a/packages/worker/src/api/routes/system/tests/accounts.spec.ts +++ b/packages/worker/src/api/routes/system/tests/accounts.spec.ts @@ -47,10 +47,7 @@ describe("accounts", () => { const response = await api.accounts.destroyMetadata(id) - expect(response.status).toBe(404) - expect(response.body.message).toBe( - `id=${accounts.formatAccountMetadataId(id)} does not exist` - ) + expect(response.status).toBe(204) }) }) }) diff --git a/packages/worker/src/sdk/accounts/accounts.ts b/packages/worker/src/sdk/accounts/accounts.ts index d18317aeb2..e43285087b 100644 --- a/packages/worker/src/sdk/accounts/accounts.ts +++ b/packages/worker/src/sdk/accounts/accounts.ts @@ -46,8 +46,14 @@ export const destroyMetadata = async (accountId: string) => { await db.doWithDB(StaticDatabases.PLATFORM_INFO.name, async (db: any) => { const metadata = await getMetadata(accountId) if (!metadata) { - throw new HTTPError(`id=${accountId} does not exist`, 404) + return + } + try { + await db.remove(accountId, metadata._rev) + } catch (e: any) { + if (e.status !== 404) { + throw e + } } - await db.remove(accountId, metadata._rev) }) }