From efc691f238e116d4db6b815dfe397e58520e1820 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 5 Jan 2022 18:26:39 +0000 Subject: [PATCH] Fixing issue #3915 so that when using the short hand URL for apps you will be redirected correctly if not logged in, allows all users to make use of it and updating the builder to send the user to the short form factor URL if not in cloud. --- .../src/components/start/AppCard.svelte | 126 ------------------ .../src/pages/builder/apps/index.svelte | 10 +- .../pages/builder/portal/apps/index.svelte | 10 +- packages/worker/src/api/controllers/app.js | 23 +++- 4 files changed, 32 insertions(+), 137 deletions(-) delete mode 100644 packages/builder/src/components/start/AppCard.svelte diff --git a/packages/builder/src/components/start/AppCard.svelte b/packages/builder/src/components/start/AppCard.svelte deleted file mode 100644 index 670ef16b60..0000000000 --- a/packages/builder/src/components/start/AppCard.svelte +++ /dev/null @@ -1,126 +0,0 @@ - - -
- -
-
- {#if app.lockedBy} - - {/if} -
editApp(app)}> - - {app.name} - -
- - - {#if app.deployed} - viewApp(app)} icon="GlobeOutline"> - View published app - - {/if} - {#if app.lockedYou} - releaseLock(app)} icon="LockOpen"> - Release lock - - {/if} - exportApp(app)} icon="Download"> - Export - - {#if app.deployed} - unpublishApp(app)} icon="GlobeRemove"> - Unpublish - - {/if} - {#if !app.deployed} - updateApp(app)} icon="Edit">Edit - deleteApp(app)} icon="Delete"> - Delete - - {/if} - -
-
- - {#if app.updatedAt} - {processStringSync("Updated {{ duration time 'millisecond' }} ago", { - time: new Date().getTime() - new Date(app.updatedAt).getTime(), - })} - {:else} - Never updated - {/if} - - - {#if app.deployed}Published{:else}Unpublished{/if} - -
- -
- - diff --git a/packages/builder/src/pages/builder/apps/index.svelte b/packages/builder/src/pages/builder/apps/index.svelte index 1639e3390f..aafc28cd92 100644 --- a/packages/builder/src/pages/builder/apps/index.svelte +++ b/packages/builder/src/pages/builder/apps/index.svelte @@ -12,7 +12,7 @@ Modal, } from "@budibase/bbui" import { onMount } from "svelte" - import { apps, organisation, auth } from "stores/portal" + import { apps, organisation, auth, admin } from "stores/portal" import { goto } from "@roxi/routify" import { AppStatus } from "constants" import { gradient } from "actions" @@ -34,12 +34,16 @@ const publishedAppsOnly = app => app.status === AppStatus.DEPLOYED $: publishedApps = $apps.filter(publishedAppsOnly) - + $: isCloud = $admin.cloud $: userApps = $auth.user?.builder?.global ? publishedApps : publishedApps.filter(app => Object.keys($auth.user?.roles).includes(app.prodId) ) + + function getUrl(app) { + return !isCloud ? `/app/${encodeURIComponent(app.name)}` : `/${app.prodId}` + } {#if $auth.user && loaded} @@ -93,7 +97,7 @@
{#each userApps as app, idx (app.appId)} - +
{app.name} diff --git a/packages/builder/src/pages/builder/portal/apps/index.svelte b/packages/builder/src/pages/builder/portal/apps/index.svelte index 336489be8d..c85ad79d45 100644 --- a/packages/builder/src/pages/builder/portal/apps/index.svelte +++ b/packages/builder/src/pages/builder/portal/apps/index.svelte @@ -47,6 +47,7 @@ $: filteredApps = enrichedApps.filter(app => app?.name?.toLowerCase().includes(searchTerm.toLowerCase()) ) + $: isCloud = $admin.cloud const enrichApps = (apps, user, sortBy) => { const enrichedApps = apps.map(app => ({ @@ -158,8 +159,13 @@ } const viewApp = app => { - const id = app.deployed ? app.prodId : app.devId - window.open(`/${id}`, "_blank") + if (!isCloud && app.deployed) { + // special case to use the short form name if self hosted + window.open(`/app/${encodeURIComponent(app.name)}`) + } else { + const id = app.deployed ? app.prodId : app.devId + window.open(`/${id}`, "_blank") + } } const editApp = app => { diff --git a/packages/worker/src/api/controllers/app.js b/packages/worker/src/api/controllers/app.js index 8f0d4f402f..fa03c09c55 100644 --- a/packages/worker/src/api/controllers/app.js +++ b/packages/worker/src/api/controllers/app.js @@ -1,18 +1,29 @@ -const { getAllApps } = require("@budibase/auth/db") +const { + getAllApps, + getDeployedAppID, + isProdAppID, +} = require("@budibase/auth/db") const CouchDB = require("../../db") const URL_REGEX_SLASH = /\/|\\/g exports.getApps = async ctx => { - const apps = await getAllApps(CouchDB, { dev: true }) + const apps = await getAllApps(CouchDB, { all: true }) const body = {} for (let app of apps) { let url = app.url || encodeURI(`${app.name}`) url = `/${url.replace(URL_REGEX_SLASH, "")}` - body[url] = { - appId: app.appId, - name: app.name, - url, + const appId = app.appId, + isProd = isProdAppID(app.appId) + if (!body[url]) { + body[url] = { + appId: getDeployedAppID(appId), + name: app.name, + url, + deployed: isProd, + } + } else { + body[url].deployed = isProd || body[url].deployed } } ctx.body = body