From 498eedaf1979306fb7d32aa17888ca0e339ac803 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 29 May 2023 11:45:40 +0200 Subject: [PATCH 1/8] Remove confirm button while setting up google datasource --- .../modals/GoogleDatasourceConfigModal.svelte | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte index 0783a9fe53..bc6afe82c5 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte @@ -22,6 +22,7 @@ title={`Connect to ${IntegrationNames[datasource.type]}`} cancelText="Back" size="L" + showConfirmButton={false} > {#if isGoogleConfigured === true} From c89708cda352c08736424320edb2a6cdee44b516 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 29 May 2023 11:45:58 +0200 Subject: [PATCH 2/8] Google wizard on the same page --- .../modals/GoogleDatasourceConfigModal.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte index bc6afe82c5..4d82ad187f 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte @@ -33,7 +33,7 @@ ]} integration. - save(datasource, true)} /> + save(datasource, true)} samePage /> {:else if isGoogleConfigured === false} Google authentication is not enabled, please complete Google SSO From 3a6a3eb8a5b716247ce35da53e492d5fa58ea57f Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 31 May 2023 10:32:11 +0200 Subject: [PATCH 3/8] Store tokens in cache and amend redirect --- .../middleware/passport/datasource/google.ts | 35 ++++++++----------- .../_components/GoogleButton.svelte | 14 +------- .../modals/GoogleDatasourceConfigModal.svelte | 3 +- .../worker/src/api/controllers/global/auth.ts | 1 - 4 files changed, 16 insertions(+), 37 deletions(-) diff --git a/packages/backend-core/src/middleware/passport/datasource/google.ts b/packages/backend-core/src/middleware/passport/datasource/google.ts index 6fd4e9ff32..3e8306c296 100644 --- a/packages/backend-core/src/middleware/passport/datasource/google.ts +++ b/packages/backend-core/src/middleware/passport/datasource/google.ts @@ -1,10 +1,10 @@ import * as google from "../sso/google" import { Cookie } from "../../../constants" import { clearCookie, getCookie } from "../../../utils" -import { doWithDB } from "../../../db" import * as configs from "../../../configs" -import { BBContext, Database, SSOProfile } from "@budibase/types" +import { BBContext, SSOProfile } from "@budibase/types" import { ssoSaveUserNoOp } from "../sso/sso" +import { cache, utils } from "../../../" const GoogleStrategy = require("passport-google-oauth").OAuth2Strategy type Passport = { @@ -36,8 +36,8 @@ export async function preAuth( ssoSaveUserNoOp ) - if (!ctx.query.appId || !ctx.query.datasourceId) { - ctx.throw(400, "appId and datasourceId query params not present.") + if (!ctx.query.appId) { + ctx.throw(400, "appId query param not present.") } return passport.authenticate(strategy, { @@ -69,7 +69,7 @@ export async function postAuth( ( accessToken: string, refreshToken: string, - profile: SSOProfile, + _profile: SSOProfile, done: Function ) => { clearCookie(ctx, Cookie.DatasourceAuth) @@ -79,23 +79,16 @@ export async function postAuth( { successRedirect: "/", failureRedirect: "/error" }, async (err: any, tokens: string[]) => { const baseUrl = `/builder/app/${authStateCookie.appId}/data` - // update the DB for the datasource with all the user info - await doWithDB(authStateCookie.appId, async (db: Database) => { - let datasource - try { - datasource = await db.get(authStateCookie.datasourceId) - } catch (err: any) { - if (err.status === 404) { - ctx.redirect(baseUrl) - } + + const id = utils.newid() + await cache.store( + `datasource:creation:${authStateCookie.appId}:google:${id}`, + { + tokens, } - if (!datasource.config) { - datasource.config = {} - } - datasource.config.auth = { type: "google", ...tokens } - await db.put(datasource) - ctx.redirect(`${baseUrl}/datasource/${authStateCookie.datasourceId}`) - }) + ) + + ctx.redirect(`${baseUrl}/new?type=google&action=continue&id=${id}`) } )(ctx, next) } diff --git a/packages/builder/src/components/backend/DatasourceNavigator/_components/GoogleButton.svelte b/packages/builder/src/components/backend/DatasourceNavigator/_components/GoogleButton.svelte index b7d70d88b7..ceb8fd7f4b 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/_components/GoogleButton.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/_components/GoogleButton.svelte @@ -3,8 +3,6 @@ import { store } from "builderStore" import { auth } from "stores/portal" - export let preAuthStep - export let datasource export let disabled export let samePage @@ -15,18 +13,8 @@ class:disabled {disabled} on:click={async () => { - let ds = datasource let appId = $store.appId - if (!ds) { - const resp = await preAuthStep() - if (resp.datasource && resp.appId) { - ds = resp.datasource - appId = resp.appId - } else { - ds = resp - } - } - const url = `/api/global/auth/${tenantId}/datasource/google?datasourceId=${ds._id}&appId=${appId}` + const url = `/api/global/auth/${tenantId}/datasource/google?appId=${appId}` if (samePage) { window.location = url } else { diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte index 4d82ad187f..6388cfb7b5 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte @@ -3,7 +3,6 @@ import { IntegrationNames } from "constants/backend" import cloneDeep from "lodash/cloneDeepWith" import GoogleButton from "../_components/GoogleButton.svelte" - import { saveDatasource as save } from "builderStore/datasource" import { organisation } from "stores/portal" import { onMount } from "svelte" @@ -33,7 +32,7 @@ ]} integration. - save(datasource, true)} samePage /> + {:else if isGoogleConfigured === false} Google authentication is not enabled, please complete Google SSO diff --git a/packages/worker/src/api/controllers/global/auth.ts b/packages/worker/src/api/controllers/global/auth.ts index c8f75b3610..131601c6ad 100644 --- a/packages/worker/src/api/controllers/global/auth.ts +++ b/packages/worker/src/api/controllers/global/auth.ts @@ -140,7 +140,6 @@ export const datasourcePreAuth = async (ctx: any, next: any) => { { provider, appId: ctx.query.appId, - datasourceId: ctx.query.datasourceId, }, Cookie.DatasourceAuth ) From d4ba73f331273accf8363b0404dca8de346de832 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 31 May 2023 11:24:06 +0200 Subject: [PATCH 4/8] Open continue --- .../middleware/passport/datasource/google.ts | 2 +- .../modals/GoogleDatasourceConfigModal.svelte | 50 ++++++++++++------- .../builder/app/[application]/data/new.svelte | 22 ++++++-- 3 files changed, 51 insertions(+), 23 deletions(-) diff --git a/packages/backend-core/src/middleware/passport/datasource/google.ts b/packages/backend-core/src/middleware/passport/datasource/google.ts index 3e8306c296..7f5e7f0d90 100644 --- a/packages/backend-core/src/middleware/passport/datasource/google.ts +++ b/packages/backend-core/src/middleware/passport/datasource/google.ts @@ -88,7 +88,7 @@ export async function postAuth( } ) - ctx.redirect(`${baseUrl}/new?type=google&action=continue&id=${id}`) + ctx.redirect(`${baseUrl}/new?action=google_continue&id=${id}`) } )(ctx, next) } diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte index 6388cfb7b5..79fb0f6b5b 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte @@ -1,43 +1,55 @@ - - {#if isGoogleConfigured === true} - + {#if step === GoogleDatasouceConfigStep.AUTH} + + {#if isGoogleConfigured === true} + + Authenticate with your google account to use the {integrationName} integration. + + + {:else if isGoogleConfigured === false} Authenticate with your google account to use the {IntegrationNames[ - datasource.type - ]} integration.Google authentication is not enabled, please complete Google SSO + configuration. + Configure Google SSO + {/if} + {/if} + {#if step === GoogleDatasouceConfigStep.SET_URL} + + Add the URL of the sheet you want to connect - - {:else if isGoogleConfigured === false} - Google authentication is not enabled, please complete Google SSO - configuration. - Configure Google SSO {/if} diff --git a/packages/builder/src/pages/builder/app/[application]/data/new.svelte b/packages/builder/src/pages/builder/app/[application]/data/new.svelte index fedaf013da..ed2e7f360d 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/new.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/new.svelte @@ -17,6 +17,7 @@ import IntegrationIcon from "components/backend/DatasourceNavigator/IntegrationIcon.svelte" import ICONS from "components/backend/DatasourceNavigator/icons/index.js" import FontAwesomeIcon from "components/common/FontAwesomeIcon.svelte" + import { onMount } from "svelte" let internalTableModal let externalDatasourceModal @@ -24,6 +25,7 @@ let integration = null let disabled = false let promptUpload = false + let continueGoogleSetup $: hasData = $datasources.list.length > 1 || $tables.list.length > 1 $: hasDefaultData = @@ -135,15 +137,29 @@ } $: fetchIntegrations() + + onMount(() => { + const urlParams = new URLSearchParams(window.location.search) + const action = urlParams.get("action") + if (action === "google_continue") { + continueGoogleSetup = true + externalDatasourceModal.show() + } + }) - - {#if integration?.auth?.type === "google"} - + { + continueGoogleSetup = false + }} +> + {#if integration?.auth?.type === "google" || continueGoogleSetup} + {:else} {/if} From 1e238ce69376987e13db2ac1fabfe281a0d7df52 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 31 May 2023 12:26:01 +0200 Subject: [PATCH 5/8] Validate google sheets url --- .../modals/GoogleDatasourceConfigModal.svelte | 40 +++++++++++++++++-- .../builder/app/[application]/data/new.svelte | 33 +++++++++------ .../server/src/integrations/googlesheets.ts | 2 +- 3 files changed, 57 insertions(+), 18 deletions(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte index 79fb0f6b5b..a0b0902480 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte @@ -4,9 +4,15 @@ import GoogleButton from "../_components/GoogleButton.svelte" import { organisation } from "stores/portal" import { onMount } from "svelte" + import { validateDatasourceConfig } from "builderStore/datasource" + import cloneDeep from "lodash/cloneDeepWith" + import IntegrationConfigForm from "../TableIntegrationMenu/IntegrationConfigForm.svelte" + export let integration export let continueSetup = false + let datasource = cloneDeep(integration) + $: isGoogleConfigured = !!$organisation.googleDatasourceConfigured onMount(async () => { @@ -22,13 +28,32 @@ let step = continueSetup ? GoogleDatasouceConfigStep.SET_URL : GoogleDatasouceConfigStep.AUTH + + let isValid + + const modalConfig = { + [GoogleDatasouceConfigStep.AUTH]: {}, + [GoogleDatasouceConfigStep.SET_URL]: { + confirmButtonText: "Connect", + onConfirm: async () => { + const resp = await validateDatasourceConfig(datasource) + if (!resp.connected) { + displayError(`Unable to connect - ${resp.error}`) + } + + return false + }, + }, + } {#if step === GoogleDatasouceConfigStep.AUTH} @@ -48,8 +73,15 @@ {/if} {/if} {#if step === GoogleDatasouceConfigStep.SET_URL} - - Add the URL of the sheet you want to connect + + Add the URL of the sheet you want to connect. + + (isValid = e.detail)} + /> {/if} diff --git a/packages/builder/src/pages/builder/app/[application]/data/new.svelte b/packages/builder/src/pages/builder/app/[application]/data/new.svelte index ed2e7f360d..536859d4f9 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/new.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/new.svelte @@ -131,21 +131,25 @@ return integrationsArray } - const fetchIntegrations = async () => { - const unsortedIntegrations = await API.getIntegrations() - integrations = sortIntegrations(unsortedIntegrations) - } - - $: fetchIntegrations() - + let isGoogleContinueAction onMount(() => { const urlParams = new URLSearchParams(window.location.search) const action = urlParams.get("action") - if (action === "google_continue") { - continueGoogleSetup = true - externalDatasourceModal.show() - } + + isGoogleContinueAction = action === "google_continue" }) + + const fetchIntegrations = async () => { + const unsortedIntegrations = await API.getIntegrations() + integrations = sortIntegrations(unsortedIntegrations) + console.log(integrations[IntegrationTypes.GOOGLE_SHEETS]) + + if (isGoogleContinueAction) { + handleIntegrationSelect(IntegrationTypes.GOOGLE_SHEETS) + } + } + + $: fetchIntegrations() @@ -158,8 +162,11 @@ continueGoogleSetup = false }} > - {#if integration?.auth?.type === "google" || continueGoogleSetup} - + {#if integration?.auth?.type === "google"} + {:else} {/if} diff --git a/packages/server/src/integrations/googlesheets.ts b/packages/server/src/integrations/googlesheets.ts index 8863aa0b3a..2598f6db62 100644 --- a/packages/server/src/integrations/googlesheets.ts +++ b/packages/server/src/integrations/googlesheets.ts @@ -72,7 +72,7 @@ const SCHEMA: Integration = { }, datasource: { spreadsheetId: { - display: "Google Sheet URL", + display: "Spreadsheet URL", type: DatasourceFieldType.STRING, required: true, }, From 25c921e3406eb653f3acf21fc5a6878bc945a05c Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 31 May 2023 13:00:33 +0200 Subject: [PATCH 6/8] Validate url --- .../src/middleware/passport/datasource/google.ts | 2 +- .../modals/GoogleDatasourceConfigModal.svelte | 15 +++++++++++---- .../builder/app/[application]/data/new.svelte | 13 +++++-------- packages/server/src/api/controllers/datasource.ts | 3 ++- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/packages/backend-core/src/middleware/passport/datasource/google.ts b/packages/backend-core/src/middleware/passport/datasource/google.ts index 7f5e7f0d90..2f91e01d9a 100644 --- a/packages/backend-core/src/middleware/passport/datasource/google.ts +++ b/packages/backend-core/src/middleware/passport/datasource/google.ts @@ -88,7 +88,7 @@ export async function postAuth( } ) - ctx.redirect(`${baseUrl}/new?action=google_continue&id=${id}`) + ctx.redirect(`${baseUrl}/new?continue_google_setup=${id}`) } )(ctx, next) } diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte index a0b0902480..f93f7b29da 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte @@ -1,5 +1,11 @@