From 0f2bcf581dbc662e833118114416770dd6bb7367 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Sun, 16 May 2021 21:25:37 +0100 Subject: [PATCH 1/5] revert functionality working --- packages/auth/src/db/Replication.js | 9 +- packages/auth/src/db/utils.js | 4 + .../src/builderStore/store/frontend.js | 4 +- .../src/components/deploy/DeployModal.svelte | 110 ++++++++++++++++++ .../src/components/deploy/RevertModal.svelte | 35 ++++++ .../src/components/start/AppCard.svelte | 2 +- .../src/components/start/AppRow.svelte | 2 +- .../components/start/CreateAppModal.svelte | 4 +- .../builder/app/[application]/_layout.svelte | 25 ++-- .../deploy => deploy_old}/_layout.svelte | 2 +- .../deploy => deploy_old}/index.svelte | 0 .../pages/builder/portal/apps/index.svelte | 8 +- packages/builder/src/stores/portal/apps.js | 1 + packages/builder/src/stores/portal/index.js | 2 +- packages/server/scripts/replicateApp.js | 5 +- .../server/src/api/controllers/application.js | 14 +-- .../server/src/api/controllers/component.js | 3 +- .../src/api/controllers/deploy/index.js | 39 ++++--- packages/server/src/api/controllers/dev.js | 37 ++++++ .../src/api/controllers/static/index.js | 5 +- packages/server/src/api/routes/dev.js | 8 +- .../routes/tests/utilities/TestFunctions.js | 2 +- packages/server/src/db/utils.js | 1 + .../src/tests/utilities/TestConfiguration.js | 4 +- packages/server/src/utilities/index.js | 6 +- packages/worker/src/api/controllers/app.js | 7 +- 26 files changed, 266 insertions(+), 73 deletions(-) create mode 100644 packages/builder/src/components/deploy/DeployModal.svelte create mode 100644 packages/builder/src/components/deploy/RevertModal.svelte rename packages/builder/src/pages/builder/app/{[application]/deploy => deploy_old}/_layout.svelte (64%) rename packages/builder/src/pages/builder/app/{[application]/deploy => deploy_old}/index.svelte (100%) diff --git a/packages/auth/src/db/Replication.js b/packages/auth/src/db/Replication.js index 9720776413..931bc3d496 100644 --- a/packages/auth/src/db/Replication.js +++ b/packages/auth/src/db/Replication.js @@ -31,7 +31,7 @@ class Replication { * Two way replication operation, intended to be promise based. * @param {Object} opts - PouchDB replication options */ - sync(opts) { + sync(opts = {}) { this.replication = this.promisify(this.source.sync, opts) return this.replication } @@ -40,7 +40,7 @@ class Replication { * One way replication operation, intended to be promise based. * @param {Object} opts - PouchDB replication options */ - replicate(opts) { + replicate(opts = {}) { this.replication = this.promisify(this.source.replicate.to, opts) return this.replication } @@ -61,8 +61,13 @@ class Replication { }) } + /** + * Rollback the target DB back to the state of the source DB + */ async rollback() { await this.target.destroy() + // Recreate the DB again + this.target = getDB(this.target.name) await this.replicate() } diff --git a/packages/auth/src/db/utils.js b/packages/auth/src/db/utils.js index 44fe1da2db..c4849a6897 100644 --- a/packages/auth/src/db/utils.js +++ b/packages/auth/src/db/utils.js @@ -12,6 +12,9 @@ exports.StaticDatabases = { GLOBAL: { name: "global-db", }, + DEPLOYMENTS: { + name: "deployments", + }, } const DocumentTypes = { @@ -21,6 +24,7 @@ const DocumentTypes = { TEMPLATE: "template", APP: "app", APP_DEV: "app_dev", + APP_METADATA: "app_metadata", } exports.DocumentTypes = DocumentTypes diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index be553066b9..0d80065f2f 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -51,14 +51,14 @@ export const getFrontendStore = () => { store.actions = { initialise: async pkg => { const { layouts, screens, application, clientLibPath } = pkg - const components = await fetchComponentLibDefinitions(application._id) + const components = await fetchComponentLibDefinitions(application.appId) store.update(state => ({ ...state, libraries: application.componentLibraries, components, name: application.name, description: application.description, - appId: application._id, + appId: application.appId, url: application.url, layouts, screens, diff --git a/packages/builder/src/components/deploy/DeployModal.svelte b/packages/builder/src/components/deploy/DeployModal.svelte new file mode 100644 index 0000000000..5fffa4cd55 --- /dev/null +++ b/packages/builder/src/components/deploy/DeployModal.svelte @@ -0,0 +1,110 @@ + + + + + + + The changes you have made will be published to the production version of the application. + + diff --git a/packages/builder/src/components/deploy/RevertModal.svelte b/packages/builder/src/components/deploy/RevertModal.svelte new file mode 100644 index 0000000000..7eaac42bbd --- /dev/null +++ b/packages/builder/src/components/deploy/RevertModal.svelte @@ -0,0 +1,35 @@ + + + + + + + The changes you have made will be deleted and the application reverted back to its production state. + + diff --git a/packages/builder/src/components/start/AppCard.svelte b/packages/builder/src/components/start/AppCard.svelte index 174ac585d4..7415e2568e 100644 --- a/packages/builder/src/components/start/AppCard.svelte +++ b/packages/builder/src/components/start/AppCard.svelte @@ -41,7 +41,7 @@ {/if} {#if app.lockedBy && app.lockedBy?.email === $auth.user?.email} - releaseLock(app._id)} icon="LockOpen"> + releaseLock(app.appId)} icon="LockOpen"> Release Lock {/if} diff --git a/packages/builder/src/components/start/AppRow.svelte b/packages/builder/src/components/start/AppRow.svelte index 693c717ab5..1a4ec1a152 100644 --- a/packages/builder/src/components/start/AppRow.svelte +++ b/packages/builder/src/components/start/AppRow.svelte @@ -50,7 +50,7 @@ deleteApp(app)} icon="Delete">Delete {/if} {#if app.lockedBy && app.lockedBy?.email === $auth.user?.email} - releaseLock(app._id)} icon="LockOpen"> + releaseLock(app.appId)} icon="LockOpen"> Release Lock {/if} diff --git a/packages/builder/src/components/start/CreateAppModal.svelte b/packages/builder/src/components/start/CreateAppModal.svelte index 44859fbb17..8d2ec56655 100644 --- a/packages/builder/src/components/start/CreateAppModal.svelte +++ b/packages/builder/src/components/start/CreateAppModal.svelte @@ -96,7 +96,7 @@ // Select Correct Application/DB in prep for creating user const applicationPkg = await get( - `/api/applications/${appJson._id}/appPackage` + `/api/applications/${appJson.instance._id}/appPackage` ) const pkg = await applicationPkg.json() if (applicationPkg.ok) { @@ -112,7 +112,7 @@ } const userResp = await api.post(`/api/users/metadata/self`, user) await userResp.json() - $goto(`/builder/app/${appJson._id}`) + $goto(`/builder/app/${appJson.instance._id}`) } catch (error) { console.error(error) notifications.error(error) diff --git a/packages/builder/src/pages/builder/app/[application]/_layout.svelte b/packages/builder/src/pages/builder/app/[application]/_layout.svelte index 98846b3db7..ba4181c6cc 100644 --- a/packages/builder/src/pages/builder/app/[application]/_layout.svelte +++ b/packages/builder/src/pages/builder/app/[application]/_layout.svelte @@ -1,10 +1,12 @@ - -
- Rocket flying through sky -
- It's time to shine! - -
-
- - feedbackModal.hide()} /> - - - - diff --git a/packages/builder/src/pages/builder/portal/apps/index.svelte b/packages/builder/src/pages/builder/portal/apps/index.svelte index c7c8d10062..0136c9cab2 100644 --- a/packages/builder/src/pages/builder/portal/apps/index.svelte +++ b/packages/builder/src/pages/builder/portal/apps/index.svelte @@ -18,6 +18,7 @@ import analytics from "analytics" import { onMount } from "svelte" import { apps } from "stores/portal" + import { auth } from "stores/backend" import download from "downloadjs" import { goto } from "@roxi/routify" import ConfirmDialog from "components/common/ConfirmDialog.svelte" @@ -61,6 +62,11 @@ } const openApp = app => { + if (app.lockedBy && app.lockedBy?.email === $auth.user?.email) { + notifications.error(`App locked by ${app.lockedBy.email}. Please allow lock to expire or have them unlock this app.`) + return + } + if (appStatus === AppStatus.DEV) { $goto(`../../app/${app.appId}`) } else { diff --git a/packages/server/src/api/index.js b/packages/server/src/api/index.js index 31559d2e2f..332b917a76 100644 --- a/packages/server/src/api/index.js +++ b/packages/server/src/api/index.js @@ -37,7 +37,6 @@ router }) ) .use(currentApp) -// .use(development) // error handling middleware router.use(async (ctx, next) => { From e51afc7451894d874290ecf532e61f4699afe964 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 17 May 2021 14:28:41 +0100 Subject: [PATCH 4/5] Updating roles API further so find API works too. --- packages/worker/src/api/controllers/admin/roles.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/worker/src/api/controllers/admin/roles.js b/packages/worker/src/api/controllers/admin/roles.js index b515a507b2..74b8fd973c 100644 --- a/packages/worker/src/api/controllers/admin/roles.js +++ b/packages/worker/src/api/controllers/admin/roles.js @@ -1,5 +1,6 @@ const { getAllRoles } = require("@budibase/auth/roles") -const { getAllApps, getDeployedAppID } = require("@budibase/auth/db") +const { getAllApps, getDeployedAppID, DocumentTypes } = require("@budibase/auth/db") +const CouchDB = require("../../../db") exports.fetch = async ctx => { // always use the dev apps as they'll be most up to date (true) @@ -25,7 +26,12 @@ exports.fetch = async ctx => { exports.find = async ctx => { const appId = ctx.params.appId + const db = new CouchDB(appId) + const app = await db.get(DocumentTypes.APP_METADATA) ctx.body = { roles: await getAllRoles(appId), + name: app.name, + version: app.version, + url: app.url, } } From 30f6238d45c3719f453cff5454eb6f702da4964d Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 17 May 2021 14:52:49 +0100 Subject: [PATCH 5/5] don't use the _id prop of the app metadata. --- packages/worker/src/api/controllers/admin/roles.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/worker/src/api/controllers/admin/roles.js b/packages/worker/src/api/controllers/admin/roles.js index 74b8fd973c..8ef45d3765 100644 --- a/packages/worker/src/api/controllers/admin/roles.js +++ b/packages/worker/src/api/controllers/admin/roles.js @@ -8,12 +8,12 @@ exports.fetch = async ctx => { const promises = [] for (let app of apps) { // use dev app IDs - promises.push(getAllRoles(app._id)) + promises.push(getAllRoles(app.appId)) } const roles = await Promise.all(promises) const response = {} for (let app of apps) { - const deployedAppId = getDeployedAppID(app._id) + const deployedAppId = getDeployedAppID(app.appId) response[deployedAppId] = { roles: roles.shift(), name: app.name,