diff --git a/packages/auth/src/db/utils.js b/packages/auth/src/db/utils.js index 7850a03fff..4650b6f122 100644 --- a/packages/auth/src/db/utils.js +++ b/packages/auth/src/db/utils.js @@ -209,11 +209,10 @@ exports.getDeployedAppID = appId => { * different users/companies apps as there is no security around it - all apps are returned. * @return {Promise} returns the app information document stored in each app database. */ -exports.getAllApps = async ({ tenantId, dev, all } = {}) => { +exports.getAllApps = async (CouchDB, { tenantId, dev, all } = {}) => { if (!tenantId) { tenantId = DEFAULT_TENANT_ID } - const CouchDB = getCouch() let allDbs = await CouchDB.allDbs() const appDbNames = allDbs.filter(dbName => { const split = dbName.split(SEPARATOR) diff --git a/packages/builder/src/pages/builder/auth/org.svelte b/packages/builder/src/pages/builder/auth/org.svelte index caf31b2654..0e0fd27c78 100644 --- a/packages/builder/src/pages/builder/auth/org.svelte +++ b/packages/builder/src/pages/builder/auth/org.svelte @@ -7,6 +7,7 @@ import { onMount } from "svelte" let tenantId = get(auth).tenantSet ? get(auth).tenantId : "" + $: multiTenancyEnabled = $admin.multiTenancy async function setOrg() { if (tenantId == null || tenantId === "") { @@ -24,6 +25,9 @@ onMount(() => { auth.checkQueryString() + if (!multiTenancyEnabled) { + $goto("../") + } }) diff --git a/packages/server/scripts/dev/manage.js b/packages/server/scripts/dev/manage.js index 96c2674317..c24d0057f0 100644 --- a/packages/server/scripts/dev/manage.js +++ b/packages/server/scripts/dev/manage.js @@ -47,7 +47,7 @@ async function init() { COUCH_DB_PASSWORD: "budibase", COUCH_DB_USER: "budibase", SELF_HOSTED: 1, - MULTI_TENANCY: 0, + MULTI_TENANCY: "", } let envFile = "" Object.keys(envFileJson).forEach(key => { diff --git a/packages/server/src/api/controllers/application.js b/packages/server/src/api/controllers/application.js index 4e13851cfe..15c4c9bf7a 100644 --- a/packages/server/src/api/controllers/application.js +++ b/packages/server/src/api/controllers/application.js @@ -129,7 +129,7 @@ exports.fetch = async function (ctx) { const dev = ctx.query && ctx.query.status === AppStatus.DEV const all = ctx.query && ctx.query.status === AppStatus.ALL const tenantId = ctx.user.tenantId - const apps = await getAllApps({ tenantId, dev, all }) + const apps = await getAllApps(CouchDB, { tenantId, dev, all }) // get the locks for all the dev apps if (dev || all) { @@ -226,7 +226,8 @@ exports.create = async function (ctx) { updatedAt: new Date().toISOString(), createdAt: new Date().toISOString(), } - await db.put(newApplication, { force: true }) + const response = await db.put(newApplication, { force: true }) + newApplication._rev = response.rev await createEmptyAppPackage(ctx, newApplication) /* istanbul ignore next */ diff --git a/packages/server/src/api/routes/application.js b/packages/server/src/api/routes/application.js index c2eb19e101..c1d39acbd5 100644 --- a/packages/server/src/api/routes/application.js +++ b/packages/server/src/api/routes/application.js @@ -6,11 +6,11 @@ const { BUILDER } = require("@budibase/auth/permissions") const router = Router() router + .post("/api/applications", authorized(BUILDER), controller.create) .get("/api/applications/:appId/definition", controller.fetchAppDefinition) .get("/api/applications", controller.fetch) .get("/api/applications/:appId/appPackage", controller.fetchAppPackage) .put("/api/applications/:appId", authorized(BUILDER), controller.update) - .post("/api/applications", authorized(BUILDER), controller.create) .post( "/api/applications/:appId/client/update", authorized(BUILDER), diff --git a/packages/worker/scripts/dev/manage.js b/packages/worker/scripts/dev/manage.js index dbc2f424d4..682c28feae 100644 --- a/packages/worker/scripts/dev/manage.js +++ b/packages/worker/scripts/dev/manage.js @@ -16,7 +16,8 @@ async function init() { REDIS_PASSWORD: "budibase", MINIO_URL: "http://localhost:10000/", COUCH_DB_URL: "http://budibase:budibase@localhost:10000/db/", - MULTI_TENANCY: 0, + // empty string is false + MULTI_TENANCY: "", } let envFile = "" Object.keys(envFileJson).forEach(key => { diff --git a/packages/worker/src/api/controllers/app.js b/packages/worker/src/api/controllers/app.js index fc3d3535c3..a7b6c5032c 100644 --- a/packages/worker/src/api/controllers/app.js +++ b/packages/worker/src/api/controllers/app.js @@ -1,10 +1,11 @@ const { getAllApps } = require("@budibase/auth/db") +const CouchDB = require("../../db") const URL_REGEX_SLASH = /\/|\\/g exports.getApps = async ctx => { const tenantId = ctx.user.tenantId - const apps = await getAllApps({ tenantId }) + const apps = await getAllApps(CouchDB, { tenantId }) const body = {} for (let app of apps) { diff --git a/packages/worker/src/api/controllers/global/configs.js b/packages/worker/src/api/controllers/global/configs.js index b48de48fef..1eb2064b8a 100644 --- a/packages/worker/src/api/controllers/global/configs.js +++ b/packages/worker/src/api/controllers/global/configs.js @@ -10,6 +10,7 @@ const { const { Configs } = require("../../../constants") const email = require("../../../utilities/email") const { upload, ObjectStoreBuckets } = require("@budibase/auth").objectStore +const CouchDB = require("../../../db") exports.save = async function (ctx) { const db = getGlobalDBFromCtx(ctx) @@ -224,7 +225,7 @@ exports.configChecklist = async function (ctx) { // TODO: Watch get started video // Apps exist - const apps = await getAllApps({ tenantId }) + const apps = await getAllApps(CouchDB, { tenantId }) // They have set up SMTP const smtpConfig = await getScopedFullConfig(db, { diff --git a/packages/worker/src/api/controllers/global/roles.js b/packages/worker/src/api/controllers/global/roles.js index b00741eada..1aae07241e 100644 --- a/packages/worker/src/api/controllers/global/roles.js +++ b/packages/worker/src/api/controllers/global/roles.js @@ -9,7 +9,7 @@ const CouchDB = require("../../../db") exports.fetch = async ctx => { const tenantId = ctx.user.tenantId // always use the dev apps as they'll be most up to date (true) - const apps = await getAllApps({ tenantId, all: true }) + const apps = await getAllApps(CouchDB, { tenantId, all: true }) const promises = [] for (let app of apps) { // use dev app IDs