From 0e6a888e8f993b043b064d1770910e83bf95bbda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keviin=20=C3=85berg=20Kultalahti?= Date: Tue, 4 May 2021 16:05:53 +0200 Subject: [PATCH 01/32] allow navigation to other URLs than /builder --- hosting/envoy.dev.yaml.hbs | 6 +-- packages/builder/index.html | 2 +- packages/builder/src/pages/index.svelte | 1 + .../builder/src/pages/portal/_layout.svelte | 1 + .../builder/src/pages/portal/index.svelte | 1 + packages/builder/vite.config.js | 2 +- packages/server/yarn.lock | 53 +------------------ 7 files changed, 7 insertions(+), 59 deletions(-) create mode 100644 packages/builder/src/pages/index.svelte create mode 100644 packages/builder/src/pages/portal/_layout.svelte create mode 100644 packages/builder/src/pages/portal/index.svelte diff --git a/hosting/envoy.dev.yaml.hbs b/hosting/envoy.dev.yaml.hbs index a4e2a97118..9c924b995b 100644 --- a/hosting/envoy.dev.yaml.hbs +++ b/hosting/envoy.dev.yaml.hbs @@ -38,7 +38,7 @@ static_resources: route: cluster: server-dev - - match: { prefix: "/builder/" } + - match: { prefix: "/" } route: cluster: builder-dev @@ -46,10 +46,6 @@ static_resources: route: cluster: builder-dev prefix_rewrite: "/builder/" - - # special case in dev to redirect no path to builder - - match: { path: "/" } - redirect: { path_redirect: "/builder/" } # minio is on the default route because this works # best, minio + AWS SDK doesn't handle path proxy diff --git a/packages/builder/index.html b/packages/builder/index.html index d6f19a2d43..de8f8a6beb 100644 --- a/packages/builder/index.html +++ b/packages/builder/index.html @@ -3,7 +3,7 @@ - Budibase Builder + Budibase diff --git a/packages/builder/src/pages/index.svelte b/packages/builder/src/pages/index.svelte new file mode 100644 index 0000000000..bb0361f273 --- /dev/null +++ b/packages/builder/src/pages/index.svelte @@ -0,0 +1 @@ +Index route diff --git a/packages/builder/src/pages/portal/_layout.svelte b/packages/builder/src/pages/portal/_layout.svelte new file mode 100644 index 0000000000..bf7e89904e --- /dev/null +++ b/packages/builder/src/pages/portal/_layout.svelte @@ -0,0 +1 @@ +asdasd diff --git a/packages/builder/src/pages/portal/index.svelte b/packages/builder/src/pages/portal/index.svelte new file mode 100644 index 0000000000..f672f3e491 --- /dev/null +++ b/packages/builder/src/pages/portal/index.svelte @@ -0,0 +1 @@ +Top top! diff --git a/packages/builder/vite.config.js b/packages/builder/vite.config.js index db02790ffd..b67aae0a2e 100644 --- a/packages/builder/vite.config.js +++ b/packages/builder/vite.config.js @@ -6,7 +6,7 @@ import path from "path" export default ({ mode }) => { const isProduction = mode === "production" return { - base: "/builder/", + base: "/", build: { minify: isProduction, outDir: "../server/builder", diff --git a/packages/server/yarn.lock b/packages/server/yarn.lock index 61bb1aac1d..da88ffcdf5 100644 --- a/packages/server/yarn.lock +++ b/packages/server/yarn.lock @@ -5198,22 +5198,6 @@ jsonschema@1.4.0: resolved "https://registry.yarnpkg.com/jsonschema/-/jsonschema-1.4.0.tgz#1afa34c4bc22190d8e42271ec17ac8b3404f87b2" integrity sha512-/YgW6pRMr6M7C+4o8kS+B/2myEpHCrxO4PEWnqJNBFMjn7EWXqlQ4tGwL6xTHeRplwuZmcAncdvfOad1nT2yMw== -jsonwebtoken@8.5.1: - version "8.5.1" - resolved "https://registry.yarnpkg.com/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz#00e71e0b8df54c2121a1f26137df2280673bcc0d" - integrity sha512-XjwVfRS6jTMsqYs0EsuJ4LGxXV14zQybNd4L2r0UvbVnSF9Af8x7p5MzbJ90Ioz/9TI41/hTCvznF/loiSzn8w== - dependencies: - jws "^3.2.2" - lodash.includes "^4.3.0" - lodash.isboolean "^3.0.3" - lodash.isinteger "^4.0.4" - lodash.isnumber "^3.0.3" - lodash.isplainobject "^4.0.6" - lodash.isstring "^4.0.1" - lodash.once "^4.0.0" - ms "^2.1.1" - semver "^5.6.0" - jsprim@^1.2.2: version "1.4.1" resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.1.tgz#313e66bc1e5cc06e438bc1b7499c2e5c56acb6a2" @@ -5253,7 +5237,7 @@ jwa@^1.4.1: ecdsa-sig-formatter "1.0.11" safe-buffer "^5.0.1" -jws@3.x.x, jws@^3.2.2: +jws@3.x.x: version "3.2.2" resolved "https://registry.yarnpkg.com/jws/-/jws-3.2.2.tgz#001099f3639468c9414000e99995fa52fb478304" integrity sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA== @@ -5650,41 +5634,11 @@ lodash.debounce@^4.0.8: resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af" integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168= -lodash.includes@^4.3.0: - version "4.3.0" - resolved "https://registry.yarnpkg.com/lodash.includes/-/lodash.includes-4.3.0.tgz#60bb98a87cb923c68ca1e51325483314849f553f" - integrity sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8= - -lodash.isboolean@^3.0.3: - version "3.0.3" - resolved "https://registry.yarnpkg.com/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz#6c2e171db2a257cd96802fd43b01b20d5f5870f6" - integrity sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY= - lodash.isequal@^4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0" integrity sha1-QVxEePK8wwEgwizhDtMib30+GOA= -lodash.isinteger@^4.0.4: - version "4.0.4" - resolved "https://registry.yarnpkg.com/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz#619c0af3d03f8b04c31f5882840b77b11cd68343" - integrity sha1-YZwK89A/iwTDH1iChAt3sRzWg0M= - -lodash.isnumber@^3.0.3: - version "3.0.3" - resolved "https://registry.yarnpkg.com/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz#3ce76810c5928d03352301ac287317f11c0b1ffc" - integrity sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w= - -lodash.isplainobject@^4.0.6: - version "4.0.6" - resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb" - integrity sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs= - -lodash.isstring@^4.0.1: - version "4.0.1" - resolved "https://registry.yarnpkg.com/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451" - integrity sha1-1SfftUVuynzJu5XV2ur4i6VKVFE= - lodash.keys@^4.2.0: version "4.2.0" resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-4.2.0.tgz#a08602ac12e4fb83f91fc1fb7a360a4d9ba35205" @@ -5700,11 +5654,6 @@ lodash.omit@^4.5.0: resolved "https://registry.yarnpkg.com/lodash.omit/-/lodash.omit-4.5.0.tgz#6eb19ae5a1ee1dd9df0b969e66ce0b7fa30b5e60" integrity sha1-brGa5aHuHdnfC5aeZs4Lf6MLXmA= -lodash.once@^4.0.0: - version "4.1.1" - resolved "https://registry.yarnpkg.com/lodash.once/-/lodash.once-4.1.1.tgz#0dd3971213c7c56df880977d504c88fb471a97ac" - integrity sha1-DdOXEhPHxW34gJd9UEyI+0cal6w= - lodash.pick@^4.0.0: version "4.4.0" resolved "https://registry.yarnpkg.com/lodash.pick/-/lodash.pick-4.4.0.tgz#52f05610fff9ded422611441ed1fc123a03001b3" From cb02c9bf58463e7d3157d32c21cae9cf3533bf7a Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 4 May 2021 17:31:06 +0100 Subject: [PATCH 02/32] google oauth UI --- packages/auth/src/db/utils.js | 19 ++-- packages/builder/src/builderStore/index.js | 2 + .../builder/src/builderStore/store/admin.js | 47 ++++++++++ .../builder/src/pages/builder/_layout.svelte | 11 ++- .../src/pages/builder/oauth/index.svelte | 91 +++++++++++++++++++ .../pages/builder/oauth/logos/Google.svelte | 38 ++++++++ .../src/api/controllers/admin/configs.js | 11 +-- .../worker/src/api/controllers/admin/email.js | 2 +- .../worker/src/api/routes/admin/configs.js | 3 + 9 files changed, 202 insertions(+), 22 deletions(-) create mode 100644 packages/builder/src/builderStore/store/admin.js create mode 100644 packages/builder/src/pages/builder/oauth/index.svelte create mode 100644 packages/builder/src/pages/builder/oauth/logos/Google.svelte diff --git a/packages/auth/src/db/utils.js b/packages/auth/src/db/utils.js index 105e038907..18b44dadf5 100644 --- a/packages/auth/src/db/utils.js +++ b/packages/auth/src/db/utils.js @@ -132,29 +132,30 @@ const determineScopedConfig = async function (db, { type, user, group }) { } ) ) - const configs = response.rows.map(row => { + + function determineScore(row) { const config = row.doc // Config is specific to a user and a group if (config._id.includes(generateConfigID({ type, user, group }))) { - config.score = 4 + return 4 } else if (config._id.includes(generateConfigID({ type, user }))) { // Config is specific to a user only - config.score = 3 + return 3 } else if (config._id.includes(generateConfigID({ type, group }))) { // Config is specific to a group only - config.score = 2 + return 2 } else if (config._id.includes(generateConfigID({ type }))) { // Config is specific to a type only - config.score = 1 + return 1 } - return config - }) + return 0 + } // Find the config with the most granular scope based on context - const scopedConfig = configs.sort((a, b) => b.score - a.score)[0] + const scopedConfig = response.rows.sort((a, b) => determineScore(a) - determineScore(b))[0] - return scopedConfig + return scopedConfig.doc } exports.generateConfigID = generateConfigID diff --git a/packages/builder/src/builderStore/index.js b/packages/builder/src/builderStore/index.js index 6fecda84c0..bd849c834f 100644 --- a/packages/builder/src/builderStore/index.js +++ b/packages/builder/src/builderStore/index.js @@ -2,6 +2,7 @@ import { getFrontendStore } from "./store/frontend" import { getAutomationStore } from "./store/automation" import { getHostingStore } from "./store/hosting" import { getThemeStore } from "./store/theme" +import { getAdminStore } from "./store/admin" import { derived, writable } from "svelte/store" import analytics from "analytics" import { FrontendTypes, LAYOUT_NAMES } from "../constants" @@ -11,6 +12,7 @@ export const store = getFrontendStore() export const automationStore = getAutomationStore() export const themeStore = getThemeStore() export const hostingStore = getHostingStore() +export const adminPanelStore = getAdminStore() export const currentAsset = derived(store, $store => { const type = $store.currentFrontEndType diff --git a/packages/builder/src/builderStore/store/admin.js b/packages/builder/src/builderStore/store/admin.js new file mode 100644 index 0000000000..69fe81c91a --- /dev/null +++ b/packages/builder/src/builderStore/store/admin.js @@ -0,0 +1,47 @@ +import { writable } from "svelte/store" +import api, { get } from "../api" + +const INITIAL_ADMIN_STATE = { + oauth: [] +} + +export const getAdminStore = () => { + const store = writable({ ...INITIAL_ADMIN_STATE }) + store.actions = { + fetch: async () => { + const responses = await Promise.all([ + api.get("/api/hosting/"), + api.get("/api/hosting/urls"), + ]) + const [info, urls] = await Promise.all(responses.map(resp => resp.json())) + store.update(state => { + state.hostingInfo = info + state.appUrl = urls.app + return state + }) + return info + }, + save: async hostingInfo => { + const response = await api.post("/api/hosting", hostingInfo) + const revision = (await response.json()).rev + store.update(state => { + state.hostingInfo = { + ...hostingInfo, + _rev: revision, + } + return state + }) + }, + fetchDeployedApps: async () => { + let deployments = await (await get("/api/hosting/apps")).json() + store.update(state => { + state.deployedApps = deployments + state.deployedAppNames = Object.values(deployments).map(app => app.name) + state.deployedAppUrls = Object.values(deployments).map(app => app.url) + return state + }) + return deployments + }, + } + return store +} diff --git a/packages/builder/src/pages/builder/_layout.svelte b/packages/builder/src/pages/builder/_layout.svelte index c01de46334..d762a7beac 100644 --- a/packages/builder/src/pages/builder/_layout.svelte +++ b/packages/builder/src/pages/builder/_layout.svelte @@ -16,11 +16,14 @@ {#if $auth.user}
- +