diff --git a/packages/builder/cypress/integration/renameAnApplication.spec.js b/packages/builder/cypress/integration/renameAnApplication.spec.js index b9da64989b..95a152c017 100644 --- a/packages/builder/cypress/integration/renameAnApplication.spec.js +++ b/packages/builder/cypress/integration/renameAnApplication.spec.js @@ -11,7 +11,8 @@ it("should rename an unpublished application", () => { renameApp(appRename) cy.searchForApplication(appRename) cy.get(".appGrid").find(".wrapper").should("have.length", 1) - }) + cy.deleteApp(appRename) +}) xit("Should rename a published application", () => { // It is not possible to rename a published application diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index 82e3c45a1f..ca758e46d0 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -43,24 +43,26 @@ Cypress.Commands.add("createApp", name => { }) }) -Cypress.Commands.add("deleteApp", () => { +Cypress.Commands.add("deleteApp", appName => { cy.visit(`localhost:${Cypress.env("PORT")}/builder`) cy.wait(1000) cy.request(`localhost:${Cypress.env("PORT")}/api/applications?status=all`) .its("body") .then(val => { - console.log(val) if (val.length > 0) { cy.get(".title > :nth-child(3) > .spectrum-Icon").click() cy.contains("Delete").click() - cy.get(".spectrum-Button--warning").click() + cy.get(".spectrum-Modal").within(() => { + cy.get("input").type(appName) + cy.get(".spectrum-Button--warning").click() + }) } }) }) Cypress.Commands.add("createTestApp", () => { const appName = "Cypress Tests" - cy.deleteApp() + cy.deleteApp(appName) cy.createApp(appName, "This app is used for Cypress testing.") }) diff --git a/packages/builder/src/components/common/ConfirmDialog.svelte b/packages/builder/src/components/common/ConfirmDialog.svelte index cf2bf989b9..ece20fe102 100644 --- a/packages/builder/src/components/common/ConfirmDialog.svelte +++ b/packages/builder/src/components/common/ConfirmDialog.svelte @@ -8,6 +8,7 @@ export let onOk = undefined export let onCancel = undefined export let warning = true + export let disabled let modal @@ -26,6 +27,7 @@ confirmText={okText} {cancelText} {warning} + {disabled} > {body} diff --git a/packages/builder/src/components/deploy/RevertModal.svelte b/packages/builder/src/components/deploy/RevertModal.svelte index 7f4decebee..bc2ad0d0aa 100644 --- a/packages/builder/src/components/deploy/RevertModal.svelte +++ b/packages/builder/src/components/deploy/RevertModal.svelte @@ -1,9 +1,16 @@ diff --git a/packages/builder/src/components/start/CreateAppModal.svelte b/packages/builder/src/components/start/CreateAppModal.svelte index 1db5e46261..68845e075b 100644 --- a/packages/builder/src/components/start/CreateAppModal.svelte +++ b/packages/builder/src/components/start/CreateAppModal.svelte @@ -157,6 +157,11 @@ } return title } + + async function onCancel() { + template = null + await auth.setInitInfo({}) + } {#if showTemplateSelection} @@ -186,7 +191,7 @@ title={getModalTitle()} confirmText={template?.fromFile ? "Import app" : "Create app"} onConfirm={createNewApp} - onCancel={inline ? () => (template = null) : null} + onCancel={inline ? onCancel : null} cancelText={inline ? "Back" : undefined} showCloseIcon={!inline} disabled={!valid} diff --git a/packages/builder/src/pages/builder/_layout.svelte b/packages/builder/src/pages/builder/_layout.svelte index 179131107f..bf55be5534 100644 --- a/packages/builder/src/pages/builder/_layout.svelte +++ b/packages/builder/src/pages/builder/_layout.svelte @@ -28,9 +28,13 @@ } if (user && user.tenantId) { - // no tenant in the url - send to account portal to fix this if (!urlTenantId) { - window.location.href = $admin.accountPortalUrl + // redirect to correct tenantId subdomain + if (!window.location.host.includes("localhost")) { + let redirectUrl = window.location.href + redirectUrl = redirectUrl.replace("://", `://${user.tenantId}.`) + window.location.href = redirectUrl + } return } diff --git a/packages/builder/src/pages/builder/portal/apps/index.svelte b/packages/builder/src/pages/builder/portal/apps/index.svelte index 2c8cbb1097..53ad661f72 100644 --- a/packages/builder/src/pages/builder/portal/apps/index.svelte +++ b/packages/builder/src/pages/builder/portal/apps/index.svelte @@ -6,6 +6,7 @@ ActionButton, ActionGroup, ButtonGroup, + Input, Select, Modal, Page, @@ -36,6 +37,7 @@ let loaded = false let searchTerm = "" let cloud = $admin.cloud + let appName = "" $: enrichedApps = enrichApps($apps, $auth.user, sortBy) $: filteredApps = enrichedApps.filter(app => @@ -296,8 +298,12 @@ title="Confirm deletion" okText="Delete app" onOk={confirmDeleteApp} + disabled={appName !== selectedApp?.name} > Are you sure you want to delete the app {selectedApp?.name}? + +

Please enter the app name below to confirm.

+ { + store.initInfo = info + return store + }) + return info + } + + async function getInitInfo() { + const response = await api.get(`/api/global/auth/init`) + const json = response.json() + auth.update(store => { + store.initInfo = json + return store + }) + return json + } + return { subscribe: store.subscribe, - setOrganisation: setOrganisation, - getInitInfo: async () => { - const response = await api.get(`/api/global/auth/init`) - return await response.json() - }, - setInitInfo: async info => { - await api.post(`/api/global/auth/init`, info) - }, + setOrganisation, + getInitInfo, + setInitInfo, checkQueryString: async () => { const urlParams = new URLSearchParams(window.location.search) if (urlParams.has("tenantId")) { @@ -129,6 +143,7 @@ export function createAuthStore() { throw "Unable to create logout" } await response.json() + await setInitInfo({}) setUser(null) }, updateSelf: async fields => { diff --git a/packages/server/src/api/controllers/application.js b/packages/server/src/api/controllers/application.js index f27efff29e..4ea308a790 100644 --- a/packages/server/src/api/controllers/application.js +++ b/packages/server/src/api/controllers/application.js @@ -323,7 +323,7 @@ exports.delete = async ctx => { ctx.body = result } -exports.sync = async ctx => { +exports.sync = async (ctx, next) => { const appId = ctx.params.appId if (!isDevAppID(appId)) { ctx.throw(400, "This action cannot be performed for production apps") @@ -336,10 +336,11 @@ exports.sync = async ctx => { if (info.error) throw info.error } catch (err) { // the database doesn't exist. Don't replicate + ctx.status = 200 ctx.body = { message: "App sync not required, app not deployed.", } - return + return next() } const replication = new Replication({