From fa30769ddb351d09a47166ac2ba9754eb4215dff Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 28 Mar 2023 14:58:22 +0100 Subject: [PATCH 01/33] fix auto columns in sample data --- packages/server/src/api/controllers/table/utils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/server/src/api/controllers/table/utils.ts b/packages/server/src/api/controllers/table/utils.ts index 7c5c81939a..755fef1f37 100644 --- a/packages/server/src/api/controllers/table/utils.ts +++ b/packages/server/src/api/controllers/table/utils.ts @@ -109,6 +109,7 @@ export function importToRows(data: any, table: any, user: any = {}) { noAutoRelationships: true, }) row = processed.row + table = processed.table let fieldName: any let schema: any From 0a6c6a9d1b792d3cc14877fe55b43e47c96279ef Mon Sep 17 00:00:00 2001 From: Budibase Release Bot <> Date: Wed, 29 Mar 2023 11:43:04 +0000 Subject: [PATCH 02/33] Update pro version to 2.4.41 --- packages/server/package.json | 2 +- packages/server/yarn.lock | 30 +++++++++++++++--------------- packages/worker/package.json | 2 +- packages/worker/yarn.lock | 30 +++++++++++++++--------------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/packages/server/package.json b/packages/server/package.json index d671b5c02a..00615f385c 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -45,7 +45,7 @@ "@apidevtools/swagger-parser": "10.0.3", "@budibase/backend-core": "^2.4.41", "@budibase/client": "^2.4.41", - "@budibase/pro": "2.4.40", + "@budibase/pro": "2.4.41", "@budibase/shared-core": "^2.4.41", "@budibase/string-templates": "^2.4.41", "@budibase/types": "^2.4.41", diff --git a/packages/server/yarn.lock b/packages/server/yarn.lock index c803d67672..af04a8bc06 100644 --- a/packages/server/yarn.lock +++ b/packages/server/yarn.lock @@ -1278,14 +1278,14 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@budibase/backend-core@2.4.40": - version "2.4.40" - resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.4.40.tgz#770158f360bcb30251aa2e50b0df40052e8ae3ce" - integrity sha512-ISN5100YjUwaJV5FJGr/4jccbottPhcp9CVBVxw90r0qKtlLVkG3zMRKJ9brSo3qx0Q8H3f1n7MrII3xoRyk3A== +"@budibase/backend-core@2.4.41": + version "2.4.41" + resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.4.41.tgz#2c99d9382f92ca3d5b884ea01c67f615c37c4837" + integrity sha512-ffVc0O5+CPACLAzN7pLvzCuccbGrhdUnbC7N4zxjQOPpczhmzUFCDOy/UAN0go2/oKMHs2SzCwiMunf3Y+cBFA== dependencies: "@budibase/nano" "10.1.2" "@budibase/pouchdb-replication-stream" "1.2.10" - "@budibase/types" "^2.4.40" + "@budibase/types" "^2.4.41" "@shopify/jest-koa-mocks" "5.0.1" "@techpass/passport-openidconnect" "0.3.2" aws-cloudfront-sign "2.2.0" @@ -1417,14 +1417,14 @@ pouchdb-promise "^6.0.4" through2 "^2.0.0" -"@budibase/pro@2.4.40": - version "2.4.40" - resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.4.40.tgz#2c1812fe35344ce8edf1401f2d8e4f289066c841" - integrity sha512-6ZXEv2J/AdaOAa2i/2XVDdCbgn2V//MN9LHx1/tr6ixcP/nCnBXjnBXrYqLrXsHcB6IiFXJwjOtirSrn3eXyuA== +"@budibase/pro@2.4.41": + version "2.4.41" + resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.4.41.tgz#4b4d395f38a8a2a86a3275a43f9270b7edfd5788" + integrity sha512-DBebpbYUsTchDvitdnTXuQGYjhUyZl7pPFKokvvlgI8Pu0YK4eXtbiMMbd2BVH7wwuJL5o3tUN+pii4IqmXofw== dependencies: - "@budibase/backend-core" "2.4.40" + "@budibase/backend-core" "2.4.41" "@budibase/string-templates" "2.3.20" - "@budibase/types" "2.4.40" + "@budibase/types" "2.4.41" "@koa/router" "8.0.8" bull "4.10.1" joi "17.6.0" @@ -1463,10 +1463,10 @@ lodash "^4.17.20" vm2 "^3.9.4" -"@budibase/types@2.4.40", "@budibase/types@^2.4.40": - version "2.4.40" - resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.4.40.tgz#12d02240e6d31f47a91eb93c971f0f835da6f950" - integrity sha512-3rk626nhpeH88l4WzU7bjG4fo8SDELSEuko7Jb+DmZdEGxrP+5NVCyNTswndXa7oSuvmg/Wg17W/aatCBNCkxA== +"@budibase/types@2.4.41", "@budibase/types@^2.4.41": + version "2.4.41" + resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.4.41.tgz#582328dd0037b4b0ad30d39e6524eac256e7320a" + integrity sha512-N3Jp46UH2wZ66iOUcSID1Nh8f+hVApytn7vgTT2mOiRwyXzWSxJQFjv9TUh8A8lLV6Qe/rLQVcp/GIQyyIFtDw== "@bull-board/api@3.7.0": version "3.7.0" diff --git a/packages/worker/package.json b/packages/worker/package.json index 7759015679..cbb93c8170 100644 --- a/packages/worker/package.json +++ b/packages/worker/package.json @@ -37,7 +37,7 @@ "license": "GPL-3.0", "dependencies": { "@budibase/backend-core": "^2.4.41", - "@budibase/pro": "2.4.40", + "@budibase/pro": "2.4.41", "@budibase/string-templates": "^2.4.41", "@budibase/types": "^2.4.41", "@koa/router": "8.0.8", diff --git a/packages/worker/yarn.lock b/packages/worker/yarn.lock index 3e46a1117b..bb51443833 100644 --- a/packages/worker/yarn.lock +++ b/packages/worker/yarn.lock @@ -475,14 +475,14 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@budibase/backend-core@2.4.40": - version "2.4.40" - resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.4.40.tgz#770158f360bcb30251aa2e50b0df40052e8ae3ce" - integrity sha512-ISN5100YjUwaJV5FJGr/4jccbottPhcp9CVBVxw90r0qKtlLVkG3zMRKJ9brSo3qx0Q8H3f1n7MrII3xoRyk3A== +"@budibase/backend-core@2.4.41": + version "2.4.41" + resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.4.41.tgz#2c99d9382f92ca3d5b884ea01c67f615c37c4837" + integrity sha512-ffVc0O5+CPACLAzN7pLvzCuccbGrhdUnbC7N4zxjQOPpczhmzUFCDOy/UAN0go2/oKMHs2SzCwiMunf3Y+cBFA== dependencies: "@budibase/nano" "10.1.2" "@budibase/pouchdb-replication-stream" "1.2.10" - "@budibase/types" "^2.4.40" + "@budibase/types" "^2.4.41" "@shopify/jest-koa-mocks" "5.0.1" "@techpass/passport-openidconnect" "0.3.2" aws-cloudfront-sign "2.2.0" @@ -564,14 +564,14 @@ pouchdb-promise "^6.0.4" through2 "^2.0.0" -"@budibase/pro@2.4.40": - version "2.4.40" - resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.4.40.tgz#2c1812fe35344ce8edf1401f2d8e4f289066c841" - integrity sha512-6ZXEv2J/AdaOAa2i/2XVDdCbgn2V//MN9LHx1/tr6ixcP/nCnBXjnBXrYqLrXsHcB6IiFXJwjOtirSrn3eXyuA== +"@budibase/pro@2.4.41": + version "2.4.41" + resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.4.41.tgz#4b4d395f38a8a2a86a3275a43f9270b7edfd5788" + integrity sha512-DBebpbYUsTchDvitdnTXuQGYjhUyZl7pPFKokvvlgI8Pu0YK4eXtbiMMbd2BVH7wwuJL5o3tUN+pii4IqmXofw== dependencies: - "@budibase/backend-core" "2.4.40" + "@budibase/backend-core" "2.4.41" "@budibase/string-templates" "2.3.20" - "@budibase/types" "2.4.40" + "@budibase/types" "2.4.41" "@koa/router" "8.0.8" bull "4.10.1" joi "17.6.0" @@ -592,10 +592,10 @@ lodash "^4.17.20" vm2 "^3.9.4" -"@budibase/types@2.4.40", "@budibase/types@^2.4.40": - version "2.4.40" - resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.4.40.tgz#12d02240e6d31f47a91eb93c971f0f835da6f950" - integrity sha512-3rk626nhpeH88l4WzU7bjG4fo8SDELSEuko7Jb+DmZdEGxrP+5NVCyNTswndXa7oSuvmg/Wg17W/aatCBNCkxA== +"@budibase/types@2.4.41", "@budibase/types@^2.4.41": + version "2.4.41" + resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.4.41.tgz#582328dd0037b4b0ad30d39e6524eac256e7320a" + integrity sha512-N3Jp46UH2wZ66iOUcSID1Nh8f+hVApytn7vgTT2mOiRwyXzWSxJQFjv9TUh8A8lLV6Qe/rLQVcp/GIQyyIFtDw== "@cspotcode/source-map-support@^0.8.0": version "0.8.1" From e25429632b9d9e306f9e3b5d6287936c725d9882 Mon Sep 17 00:00:00 2001 From: adrinr Date: Wed, 29 Mar 2023 15:35:55 +0100 Subject: [PATCH 03/33] Remove users that should not be there anymore when syncGlobalUsers --- packages/server/src/sdk/users/utils.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/server/src/sdk/users/utils.ts b/packages/server/src/sdk/users/utils.ts index 5c369754a1..82a46acfac 100644 --- a/packages/server/src/sdk/users/utils.ts +++ b/packages/server/src/sdk/users/utils.ts @@ -6,25 +6,33 @@ import { InternalTables, } from "../../db/utils" import { isEqual } from "lodash" +import { ContextUser, UserMetadata } from "@budibase/types" -export function combineMetadataAndUser(user: any, metadata: any) { +export function combineMetadataAndUser( + user: ContextUser, + metadata: UserMetadata | UserMetadata[] +) { + const metadataId = generateUserMetadataID(user._id!) + const found = Array.isArray(metadata) + ? metadata.find(doc => doc._id === metadataId) + : metadata // skip users with no access if ( user.roleId == null || user.roleId === rolesCore.BUILTIN_ROLE_IDS.PUBLIC ) { + // If it exists and it should not, we must remove it + if (found) { + return { ...found, _deleted: true } + } return null } delete user._rev - const metadataId = generateUserMetadataID(user._id) const newDoc = { ...user, _id: metadataId, tableId: InternalTables.USER_METADATA, } - const found = Array.isArray(metadata) - ? metadata.find(doc => doc._id === metadataId) - : metadata // copy rev over for the purposes of equality check if (found) { newDoc._rev = found._rev @@ -58,7 +66,7 @@ export async function syncGlobalUsers() { ]) const toWrite = [] for (let user of users) { - const combined = await combineMetadataAndUser(user, metadata) + const combined = combineMetadataAndUser(user, metadata) if (combined) { toWrite.push(combined) } From b368c143087a8d8068212cd2368c001eeb3be023 Mon Sep 17 00:00:00 2001 From: adrinr Date: Wed, 29 Mar 2023 16:18:32 +0100 Subject: [PATCH 04/33] Add unit tests to test new users --- .../server/src/sdk/users/tests/utils.spec.ts | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 packages/server/src/sdk/users/tests/utils.spec.ts diff --git a/packages/server/src/sdk/users/tests/utils.spec.ts b/packages/server/src/sdk/users/tests/utils.spec.ts new file mode 100644 index 0000000000..3178978c46 --- /dev/null +++ b/packages/server/src/sdk/users/tests/utils.spec.ts @@ -0,0 +1,49 @@ +import { db } from "@budibase/backend-core" +import TestConfiguration from "../../../tests/utilities/TestConfiguration" +import { rawUserMetadata, syncGlobalUsers } from "../utils" + +describe("syncGlobalUsers", () => { + const config = new TestConfiguration() + + beforeAll(async () => { + await config.init() + }) + + afterAll(config.end) + + it("the default user is synced", async () => { + await config.doInContext(config.appId, async () => { + await syncGlobalUsers() + + const metadata = await rawUserMetadata() + expect(metadata).toHaveLength(1) + expect(metadata).toEqual([ + expect.objectContaining({ + _id: db.generateUserMetadataID(config.user._id), + }), + ]) + }) + }) + + it("app users are synced", async () => { + await config.doInContext(config.appId, async () => { + const user1 = await config.createUser() + const user2 = await config.createUser() + + await syncGlobalUsers() + + const metadata = await rawUserMetadata() + expect(metadata).toHaveLength(3) + expect(metadata).toContainEqual( + expect.objectContaining({ + _id: db.generateUserMetadataID(user1._id), + }) + ) + expect(metadata).toContainEqual( + expect.objectContaining({ + _id: db.generateUserMetadataID(user2._id), + }) + ) + }) + }) +}) From 8783f0123d51f0b95490151004c59458eb33d2fe Mon Sep 17 00:00:00 2001 From: adrinr Date: Wed, 29 Mar 2023 16:42:31 +0100 Subject: [PATCH 05/33] Add tests for admins vs app users --- .../server/src/sdk/users/tests/utils.spec.ts | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/server/src/sdk/users/tests/utils.spec.ts b/packages/server/src/sdk/users/tests/utils.spec.ts index 3178978c46..8eba6db5b6 100644 --- a/packages/server/src/sdk/users/tests/utils.spec.ts +++ b/packages/server/src/sdk/users/tests/utils.spec.ts @@ -5,7 +5,7 @@ import { rawUserMetadata, syncGlobalUsers } from "../utils" describe("syncGlobalUsers", () => { const config = new TestConfiguration() - beforeAll(async () => { + beforeEach(async () => { await config.init() }) @@ -25,11 +25,10 @@ describe("syncGlobalUsers", () => { }) }) - it("app users are synced", async () => { + it("admin and builders users are synced", async () => { + const user1 = await config.createUser({ admin: true }) + const user2 = await config.createUser({ admin: false, builder: true }) await config.doInContext(config.appId, async () => { - const user1 = await config.createUser() - const user2 = await config.createUser() - await syncGlobalUsers() const metadata = await rawUserMetadata() @@ -46,4 +45,19 @@ describe("syncGlobalUsers", () => { ) }) }) + + it("app users are not synced if not specified", async () => { + const user = await config.createUser({ admin: false, builder: false }) + await config.doInContext(config.appId, async () => { + await syncGlobalUsers() + + const metadata = await rawUserMetadata() + expect(metadata).toHaveLength(1) + expect(metadata).not.toContainEqual( + expect.objectContaining({ + _id: db.generateUserMetadataID(user._id), + }) + ) + }) + }) }) From 4cb6b99982e6f651d4a9380954f323cf1ee96518 Mon Sep 17 00:00:00 2001 From: adrinr Date: Wed, 29 Mar 2023 16:42:55 +0100 Subject: [PATCH 06/33] Types --- packages/server/src/tests/utilities/TestConfiguration.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/server/src/tests/utilities/TestConfiguration.ts b/packages/server/src/tests/utilities/TestConfiguration.ts index cf337c689f..3e0ea331b8 100644 --- a/packages/server/src/tests/utilities/TestConfiguration.ts +++ b/packages/server/src/tests/utilities/TestConfiguration.ts @@ -47,6 +47,7 @@ import { SourceName, Table, SearchFilters, + UserRoles, } from "@budibase/types" type DefaultUserValues = { @@ -277,7 +278,7 @@ class TestConfiguration { email?: string builder?: boolean admin?: boolean - roles?: any + roles?: UserRoles } = {} ) { let { id, firstName, lastName, email, builder, admin, roles } = user From efff31e181c1b4afb48b58c031b8225451d6ad6a Mon Sep 17 00:00:00 2001 From: adrinr Date: Wed, 29 Mar 2023 17:02:56 +0100 Subject: [PATCH 07/33] Test user groups --- .../tests/utilities/structures/index.ts | 1 + .../tests/utilities/structures/userGroups.ts | 10 +++++ .../server/src/sdk/users/tests/utils.spec.ts | 39 ++++++++++++++++++- 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 packages/backend-core/tests/utilities/structures/userGroups.ts diff --git a/packages/backend-core/tests/utilities/structures/index.ts b/packages/backend-core/tests/utilities/structures/index.ts index ca77f476d0..ff2e5b147f 100644 --- a/packages/backend-core/tests/utilities/structures/index.ts +++ b/packages/backend-core/tests/utilities/structures/index.ts @@ -8,4 +8,5 @@ export * as plugins from "./plugins" export * as sso from "./sso" export * as tenant from "./tenants" export * as users from "./users" +export * as userGroups from "./userGroups" export { generator } from "./generator" diff --git a/packages/backend-core/tests/utilities/structures/userGroups.ts b/packages/backend-core/tests/utilities/structures/userGroups.ts new file mode 100644 index 0000000000..4dc870a00a --- /dev/null +++ b/packages/backend-core/tests/utilities/structures/userGroups.ts @@ -0,0 +1,10 @@ +import { UserGroup } from "@budibase/types" +import { generator } from "./generator" + +export function userGroup(): UserGroup { + return { + name: generator.word(), + icon: generator.word(), + color: generator.word(), + } +} diff --git a/packages/server/src/sdk/users/tests/utils.spec.ts b/packages/server/src/sdk/users/tests/utils.spec.ts index 8eba6db5b6..97381a2628 100644 --- a/packages/server/src/sdk/users/tests/utils.spec.ts +++ b/packages/server/src/sdk/users/tests/utils.spec.ts @@ -1,4 +1,7 @@ -import { db } from "@budibase/backend-core" +import { db, roles } from "@budibase/backend-core" +import { structures } from "@budibase/backend-core/tests" +import { sdk as proSdk } from "@budibase/pro" + import TestConfiguration from "../../../tests/utilities/TestConfiguration" import { rawUserMetadata, syncGlobalUsers } from "../utils" @@ -60,4 +63,38 @@ describe("syncGlobalUsers", () => { ) }) }) + + it("app users are removed when removed from the tenant", async () => { + await config.doInTenant(async () => { + const group = await proSdk.groups.save(structures.userGroups.userGroup()) + const user1 = await config.createUser({ admin: false, builder: false }) + const user2 = await config.createUser({ admin: false, builder: false }) + await proSdk.groups.addUsers(group.id, [user1._id, user2._id]) + + await config.doInContext(config.appId, async () => { + await syncGlobalUsers() + expect(await rawUserMetadata()).toHaveLength(1) + + await proSdk.groups.updateGroupApps(group.id, { + appsToAdd: [ + { appId: config.prodAppId!, roleId: roles.BUILTIN_ROLE_IDS.BASIC }, + ], + }) + await syncGlobalUsers() + + const metadata = await rawUserMetadata() + expect(metadata).toHaveLength(3) + expect(metadata).toContainEqual( + expect.objectContaining({ + _id: db.generateUserMetadataID(user1._id), + }) + ) + expect(metadata).toContainEqual( + expect.objectContaining({ + _id: db.generateUserMetadataID(user2._id), + }) + ) + }) + }) + }) }) From 301ad598ada0e94d05e678d56ba74c933e21c51a Mon Sep 17 00:00:00 2001 From: adrinr Date: Wed, 29 Mar 2023 17:05:32 +0100 Subject: [PATCH 08/33] Test user group deletion --- .../server/src/sdk/users/tests/utils.spec.ts | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/server/src/sdk/users/tests/utils.spec.ts b/packages/server/src/sdk/users/tests/utils.spec.ts index 97381a2628..69f1bdf9e6 100644 --- a/packages/server/src/sdk/users/tests/utils.spec.ts +++ b/packages/server/src/sdk/users/tests/utils.spec.ts @@ -64,7 +64,7 @@ describe("syncGlobalUsers", () => { }) }) - it("app users are removed when removed from the tenant", async () => { + it("app users are added when group is assigned to app", async () => { await config.doInTenant(async () => { const group = await proSdk.groups.save(structures.userGroups.userGroup()) const user1 = await config.createUser({ admin: false, builder: false }) @@ -97,4 +97,31 @@ describe("syncGlobalUsers", () => { }) }) }) + + it("app users are removed when user removed from user group", async () => { + await config.doInTenant(async () => { + const group = await proSdk.groups.save(structures.userGroups.userGroup()) + const user1 = await config.createUser({ admin: false, builder: false }) + const user2 = await config.createUser({ admin: false, builder: false }) + await proSdk.groups.updateGroupApps(group.id, { + appsToAdd: [ + { appId: config.prodAppId!, roleId: roles.BUILTIN_ROLE_IDS.BASIC }, + ], + }) + await proSdk.groups.addUsers(group.id, [user1._id, user2._id]) + + await config.doInContext(config.appId, async () => { + await syncGlobalUsers() + expect(await rawUserMetadata()).toHaveLength(3) + + await proSdk.groups.updateGroupApps(group.id, { + appsToRemove: [{ appId: config.prodAppId! }], + }) + await syncGlobalUsers() + + const metadata = await rawUserMetadata() + expect(metadata).toHaveLength(1) + }) + }) + }) }) From 32c78ec9bfcec40ddea60a08bb27dee11251a30c Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 29 Mar 2023 19:58:24 +0100 Subject: [PATCH 09/33] This makes it so that Googlesheets works correctly as part of onboarding in the Cloud, in self host the googlesheets onboarding option has been hidden as it is too complex to get the user to setup the correct integrations with their google account while doing the first time onboarding to an app. --- packages/backend-core/src/configs/configs.ts | 18 +++---- .../middleware/passport/datasource/google.ts | 15 ++++-- .../_components/GoogleButton.svelte | 16 +++++- .../_components/DatasourceConfigPanel.svelte | 17 ++++-- .../portal/apps/onboarding/index.svelte | 52 +++++++++++++++---- .../server/src/integrations/googlesheets.ts | 4 ++ .../shared-core/src/{ => helpers}/helpers.ts | 0 packages/shared-core/src/helpers/index.ts | 2 + .../shared-core/src/helpers/integrations.ts | 5 ++ 9 files changed, 100 insertions(+), 29 deletions(-) rename packages/shared-core/src/{ => helpers}/helpers.ts (100%) create mode 100644 packages/shared-core/src/helpers/index.ts create mode 100644 packages/shared-core/src/helpers/integrations.ts diff --git a/packages/backend-core/src/configs/configs.ts b/packages/backend-core/src/configs/configs.ts index 305a074152..79fd409308 100644 --- a/packages/backend-core/src/configs/configs.ts +++ b/packages/backend-core/src/configs/configs.ts @@ -162,10 +162,7 @@ export async function getGoogleConfig(): Promise< export async function getGoogleDatasourceConfig(): Promise< GoogleInnerConfig | undefined > { - if (!env.isDev() && !env.SELF_HOSTED) { - // always use the env vars in cloud - return getDefaultGoogleConfig() - } + return getDefaultGoogleConfig() // prefer the config in self-host let config = await getGoogleConfig() @@ -179,13 +176,14 @@ export async function getGoogleDatasourceConfig(): Promise< } export function getDefaultGoogleConfig(): GoogleInnerConfig | undefined { - if (environment.GOOGLE_CLIENT_ID && environment.GOOGLE_CLIENT_SECRET) { - return { - clientID: environment.GOOGLE_CLIENT_ID!, - clientSecret: environment.GOOGLE_CLIENT_SECRET!, - activated: true, - } + //if (environment.GOOGLE_CLIENT_ID && environment.GOOGLE_CLIENT_SECRET) { + return { + clientID: + "77746844610-62k43m9b4so4gcmf6ibs7p3l7jv81rug.apps.googleusercontent.com", + clientSecret: "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", + activated: true, } + //} } // OIDC diff --git a/packages/backend-core/src/middleware/passport/datasource/google.ts b/packages/backend-core/src/middleware/passport/datasource/google.ts index 32451cb8d2..d67bc45f84 100644 --- a/packages/backend-core/src/middleware/passport/datasource/google.ts +++ b/packages/backend-core/src/middleware/passport/datasource/google.ts @@ -13,6 +13,7 @@ type Passport = { async function fetchGoogleCreds() { let config = await configs.getGoogleDatasourceConfig() + console.log(config) if (!config) { throw new Error("No google configuration found") @@ -78,17 +79,23 @@ 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) => { - const datasource = await db.get(authStateCookie.datasourceId) + let datasource + try { + datasource = await db.get(authStateCookie.datasourceId) + } catch (err: any) { + if (err.status === 404) { + ctx.redirect(baseUrl) + } + } if (!datasource.config) { datasource.config = {} } datasource.config.auth = { type: "google", ...tokens } await db.put(datasource) - ctx.redirect( - `/builder/app/${authStateCookie.appId}/data/datasource/${authStateCookie.datasourceId}` - ) + ctx.redirect(`${baseUrl}/datasource/${authStateCookie.datasourceId}`) }) } )(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 4622bd7b19..efe5158398 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/_components/GoogleButton.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/_components/GoogleButton.svelte @@ -5,18 +5,26 @@ export let preAuthStep export let datasource + export let disabled $: tenantId = $auth.tenantId