diff --git a/packages/builder/src/stores/portal/admin.js b/packages/builder/src/stores/portal/admin.js index 2985bd23fa..96e67ea84b 100644 --- a/packages/builder/src/stores/portal/admin.js +++ b/packages/builder/src/stores/portal/admin.js @@ -38,9 +38,9 @@ export function createAdminStore() { async function multiTenancyEnabled() { let enabled = false try { - const response = await api.get(`/api/global/tenants/enabled`) + const response = await api.get(`/api/global/flags`) const json = await response.json() - enabled = json.enabled + enabled = json.multiTenancy } catch (err) { // just let it stay disabled } diff --git a/packages/server/scripts/integrations/postgres/init.sql b/packages/server/scripts/integrations/postgres/init.sql index 5a99520c1e..cc2fc734f8 100644 --- a/packages/server/scripts/integrations/postgres/init.sql +++ b/packages/server/scripts/integrations/postgres/init.sql @@ -10,10 +10,11 @@ CREATE TABLE Persons ( CREATE TABLE Tasks ( TaskID SERIAL PRIMARY KEY, PersonID INT, + Completed BOOLEAN, TaskName varchar(255), CONSTRAINT fkPersons FOREIGN KEY(PersonID) - REFERENCES Persons(PersonID) + REFERENCES Persons(PersonID) ); CREATE TABLE Products ( ProductID SERIAL PRIMARY KEY, @@ -24,15 +25,15 @@ CREATE TABLE Products_Tasks ( TaskID INT NOT NULL, CONSTRAINT fkProducts FOREIGN KEY(ProductID) - REFERENCES Products(ProductID), + REFERENCES Products(ProductID), CONSTRAINT fkTasks FOREIGN KEY(TaskID) - REFERENCES Tasks(TaskID), + REFERENCES Tasks(TaskID), PRIMARY KEY (ProductID, TaskID) ); INSERT INTO Persons (FirstName, LastName, Address, City) VALUES ('Mike', 'Hughes', '123 Fake Street', 'Belfast'); -INSERT INTO Tasks (PersonID, TaskName) VALUES (1, 'assembling'); -INSERT INTO Tasks (PersonID, TaskName) VALUES (1, 'processing'); +INSERT INTO Tasks (PersonID, TaskName, Completed) VALUES (1, 'assembling', TRUE); +INSERT INTO Tasks (PersonID, TaskName, Completed) VALUES (1, 'processing', FALSE); INSERT INTO Products (ProductName) VALUES ('Computers'); INSERT INTO Products (ProductName) VALUES ('Laptops'); INSERT INTO Products (ProductName) VALUES ('Chairs'); diff --git a/packages/worker/src/api/controllers/global/flags.js b/packages/worker/src/api/controllers/global/flags.js new file mode 100644 index 0000000000..26e998e663 --- /dev/null +++ b/packages/worker/src/api/controllers/global/flags.js @@ -0,0 +1,7 @@ +const env = require("../../../environment") + +exports.fetch = async ctx => { + ctx.body = { + multiTenancy: !!env.MULTI_TENANCY, + } +} \ No newline at end of file diff --git a/packages/worker/src/api/controllers/global/tenants.js b/packages/worker/src/api/controllers/global/tenants.js index 677ba5a20f..e053216dd9 100644 --- a/packages/worker/src/api/controllers/global/tenants.js +++ b/packages/worker/src/api/controllers/global/tenants.js @@ -1,13 +1,6 @@ -const env = require("../../../environment") const CouchDB = require("../../../db") const { StaticDatabases } = require("@budibase/auth/db") -exports.multiTenancyEnabled = async ctx => { - ctx.body = { - enabled: false, - } -} - exports.exists = async ctx => { const tenantId = ctx.request.params const db = new CouchDB(StaticDatabases.PLATFORM_INFO.name) diff --git a/packages/worker/src/api/index.js b/packages/worker/src/api/index.js index 8d4f8c5bc9..cfeb3506e5 100644 --- a/packages/worker/src/api/index.js +++ b/packages/worker/src/api/index.js @@ -21,7 +21,7 @@ const PUBLIC_ENDPOINTS = [ method: "GET", }, { - route: "api/global/tenants/enabled", + route: "api/global/flags", method: "GET", }, { diff --git a/packages/worker/src/api/routes/global/flags.js b/packages/worker/src/api/routes/global/flags.js new file mode 100644 index 0000000000..5f63455db9 --- /dev/null +++ b/packages/worker/src/api/routes/global/flags.js @@ -0,0 +1,9 @@ +const Router = require("@koa/router") +const controller = require("../../controllers/global/flags") + +const router = Router() + +router + .get("/api/global/flags", controller.fetch) + +module.exports = router \ No newline at end of file diff --git a/packages/worker/src/api/routes/global/tenants.js b/packages/worker/src/api/routes/global/tenants.js index 0d1dc47afd..432e327115 100644 --- a/packages/worker/src/api/routes/global/tenants.js +++ b/packages/worker/src/api/routes/global/tenants.js @@ -5,7 +5,6 @@ const adminOnly = require("../../../middleware/adminOnly") const router = Router() router - .get("/api/global/tenants/enabled", controller.multiTenancyEnabled) .get("/api/global/tenants/:tenantId/exists", controller.exists) .get("/api/global/tenants", adminOnly, controller.fetch) diff --git a/packages/worker/src/api/routes/index.js b/packages/worker/src/api/routes/index.js index ddccd3db2a..6341dffeb7 100644 --- a/packages/worker/src/api/routes/index.js +++ b/packages/worker/src/api/routes/index.js @@ -7,6 +7,7 @@ const emailRoutes = require("./global/email") const authRoutes = require("./global/auth") const roleRoutes = require("./global/roles") const sessionRoutes = require("./global/sessions") +const flagRoutes = require("./global/flags") const appRoutes = require("./app") exports.routes = [ @@ -20,4 +21,5 @@ exports.routes = [ emailRoutes, sessionRoutes, roleRoutes, + flagRoutes, ]