Skip to content

Commit 679ce06

Browse files
authored
fix: re-add auth_scopes to each google connection (#1404)
## Description - Since the backend doesn't know which service it shoul initiate: google-drive, google-calendar, google-gmail and on... We recovered this ability in the code. ## Linear Ticket ## What type of PR is this? (check all applicable) - [ ] 💡 (feat) - A new feature (non-breaking change which adds functionality) - [ ] 🔄 (refactor) - Code Refactoring - A code change that neither fixes a bug nor adds a feature - [ ] 🐞 (fix) - Bug Fix (non-breaking change which fixes an issue) - [ ] 🏎 (perf) - Optimization - [ ] 📄 (docs) - Documentation - Documentation only changes - [ ] 📄 (test) - Tests - Adding missing tests or correcting existing tests - [ ] ⚙️ (ci) - Continuous Integrations - Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs) - [ ] ☑️ (chore) - Chores - Other changes that don't modify src or test files - [ ] ↩️ (revert) - Reverts - Reverts a previous commit(s). <!-- For a timely review/response, please avoid force-pushing additional commits if your PR already received reviews or comments. Before submitting a Pull Request, please ensure you've done the following: - 👷‍♀️ Create small PRs. In most cases this will be possible. - ✅ Provide tests for your changes. - 📝 Use descriptive commit messages (as described below). - 📗 Update any related documentation and include any relevant screenshots. Commit Message Structure (all lower-case): <type>(optional ticket number): <description> [optional body] -->
1 parent 4e011ca commit 679ce06

File tree

7 files changed

+58
-24
lines changed

7 files changed

+58
-24
lines changed

src/components/organisms/connections/integrations/google/add.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { SelectOption } from "@interfaces/components";
1010
import { Integrations, defaultGoogleConnectionName, isGoogleIntegration } from "@src/enums/components";
1111
import { useConnectionForm } from "@src/hooks";
1212
import { getDefaultAuthType } from "@src/utilities";
13-
import { googleIntegrationSchema, oauthSchema } from "@validations";
13+
import { googleJsonIntegrationSchema, googleOauthSchema } from "@validations";
1414

1515
import { Select } from "@components/molecules";
1616

@@ -35,7 +35,7 @@ export const GoogleIntegrationAddForm = ({
3535
reset,
3636
setValidationSchema,
3737
setValue,
38-
} = useConnectionForm(googleIntegrationSchema, "create");
38+
} = useConnectionForm(googleJsonIntegrationSchema, "create");
3939

4040
const integrationKeyFromType = Object.entries(Integrations).find(([, value]) => value === type)?.[0] as
4141
| keyof typeof Integrations
@@ -65,11 +65,11 @@ export const GoogleIntegrationAddForm = ({
6565
if (connectionType.value === ConnectionAuthType.Oauth && isGoogleIntegration(type as Integrations)) {
6666
setValue("auth_type", ConnectionAuthType.Oauth);
6767
setValue("auth_scopes", type);
68-
setValidationSchema(oauthSchema);
68+
setValidationSchema(googleOauthSchema);
6969
return;
7070
}
7171
setValue("auth_type", ConnectionAuthType.Json);
72-
setValidationSchema(googleIntegrationSchema);
72+
setValidationSchema(googleJsonIntegrationSchema);
7373

7474
// eslint-disable-next-line react-hooks/exhaustive-deps
7575
}, [connectionType, type]);
@@ -82,7 +82,7 @@ export const GoogleIntegrationAddForm = ({
8282
}, [connectionId]);
8383

8484
useEffect(() => {
85-
reset({ json: "" });
85+
reset({ json: "", auth_scopes: type as keyof typeof Integrations });
8686
// eslint-disable-next-line react-hooks/exhaustive-deps
8787
}, [type]);
8888

src/components/organisms/connections/integrations/google/edit.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from "react";
33
import { selectIntegrationGoogle } from "@constants/lists/connections";
44
import { ConnectionAuthType } from "@enums";
55
import { GoogleIntegrationType } from "@src/types";
6-
import { googleIntegrationSchema, oauthSchema } from "@validations";
6+
import { googleJsonIntegrationSchema, oauthSchema } from "@validations";
77

88
import { IntegrationEditForm } from "@components/organisms/connections/integrations";
99

@@ -15,7 +15,7 @@ export const GoogleIntegrationEditForm = ({
1515
<IntegrationEditForm
1616
integrationType={googleIntegrationApplication}
1717
schemas={{
18-
[ConnectionAuthType.JsonKey]: googleIntegrationSchema,
18+
[ConnectionAuthType.JsonKey]: googleJsonIntegrationSchema,
1919
[ConnectionAuthType.Oauth]: oauthSchema,
2020
}}
2121
selectOptions={selectIntegrationGoogle}

src/components/organisms/connections/integrations/googlecalendar/add.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { SelectOption } from "@interfaces/components";
1010
import { Integrations, defaultGoogleConnectionName } from "@src/enums/components";
1111
import { useConnectionForm } from "@src/hooks";
1212
import { getDefaultAuthType } from "@src/utilities";
13-
import { googleCalendarIntegrationSchema, googleIntegrationSchema, oauthSchema } from "@validations";
13+
import { googleCalendarIntegrationSchema, googleJsonIntegrationSchema, googleOauthSchema } from "@validations";
1414

1515
import { Select } from "@components/molecules";
1616

@@ -64,14 +64,15 @@ export const GoogleCalendarIntegrationAddForm = ({
6464
}
6565

6666
if (connectionType.value === ConnectionAuthType.Oauth) {
67+
setValidationSchema(googleOauthSchema);
6768
setValue("auth_type", ConnectionAuthType.Oauth);
69+
6870
setValue("auth_scopes", type);
69-
setValidationSchema(oauthSchema);
7071

7172
return;
7273
}
7374
setValue("auth_type", ConnectionAuthType.Json);
74-
setValidationSchema(googleIntegrationSchema);
75+
setValidationSchema(googleJsonIntegrationSchema);
7576

7677
// eslint-disable-next-line react-hooks/exhaustive-deps
7778
}, [connectionType, type]);
@@ -84,7 +85,7 @@ export const GoogleCalendarIntegrationAddForm = ({
8485
}, [connectionId]);
8586

8687
useEffect(() => {
87-
reset({ json: "" });
88+
reset({ json: "", auth_scopes: type as keyof typeof Integrations });
8889
// eslint-disable-next-line react-hooks/exhaustive-deps
8990
}, [type]);
9091

src/components/organisms/connections/integrations/googleforms/add.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { SelectOption } from "@interfaces/components";
1010
import { Integrations, defaultGoogleConnectionName } from "@src/enums/components";
1111
import { useConnectionForm } from "@src/hooks";
1212
import { getDefaultAuthType } from "@src/utilities";
13-
import { googleFormsIntegrationSchema, oauthSchema } from "@validations";
13+
import { googleFormsIntegrationSchema, googleJsonIntegrationSchema, googleOauthSchema } from "@validations";
1414

1515
import { Select } from "@components/molecules";
1616

@@ -64,14 +64,15 @@ export const GoogleFormsIntegrationAddForm = ({
6464
}
6565

6666
if (connectionType.value === ConnectionAuthType.Oauth) {
67+
setValidationSchema(googleOauthSchema);
6768
setValue("auth_type", ConnectionAuthType.Oauth);
69+
6870
setValue("auth_scopes", type);
69-
setValidationSchema(oauthSchema);
7071

7172
return;
7273
}
7374
setValue("auth_type", ConnectionAuthType.Json);
74-
setValidationSchema(googleFormsIntegrationSchema);
75+
setValidationSchema(googleJsonIntegrationSchema);
7576

7677
// eslint-disable-next-line react-hooks/exhaustive-deps
7778
}, [connectionType, type]);
@@ -84,7 +85,7 @@ export const GoogleFormsIntegrationAddForm = ({
8485
}, [connectionId]);
8586

8687
useEffect(() => {
87-
reset({ json: "" });
88+
reset({ json: "", auth_scopes: type as keyof typeof Integrations });
8889
// eslint-disable-next-line react-hooks/exhaustive-deps
8990
}, [type]);
9091

src/hooks/useConnectionForm.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ export const useConnectionForm = (validationSchema: ZodSchema, mode: FormMode, a
316316
);
317317

318318
if (error) {
319+
setConnectionInProgress(false);
319320
addToast({
320321
message: tErrors("connectionNotCreated"),
321322
type: "error",
@@ -361,7 +362,7 @@ export const useConnectionForm = (validationSchema: ZodSchema, mode: FormMode, a
361362

362363
const handleOAuth = async (oauthConnectionId: string, integrationName: keyof typeof Integrations) => {
363364
const oauthType = ConnectionAuthType.OauthDefault;
364-
365+
const connectionData = getValues();
365366
try {
366367
setConnectionInProgress(true);
367368
await VariablesService.setByConnectiontId(oauthConnectionId!, {
@@ -374,7 +375,13 @@ export const useConnectionForm = (validationSchema: ZodSchema, mode: FormMode, a
374375
integrationName && isMicrosofIntegration(integrationName as Integrations)
375376
? defaultMicrosoftConnectionName
376377
: integrationName;
377-
const OauthUrl = `${apiBaseUrl}/${formattedIntegrationName}/save?cid=${oauthConnectionId}&origin=web&auth_type=${oauthType}`;
378+
379+
const urlParams = getSpecificParams(
380+
connectionData,
381+
integrationDataKeys[integrationName.toString() as keyof typeof integrationDataKeys]
382+
);
383+
384+
const OauthUrl = `${apiBaseUrl}/${formattedIntegrationName}/save?cid=${oauthConnectionId}&origin=web&auth_type=${oauthType}&${urlParams}`;
378385

379386
openPopup(OauthUrl, "Authorize");
380387
startCheckingStatus(oauthConnectionId);

src/validations/connection.schema.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,45 @@ export const githubPrivateAuthIntegrationSchema = z.object({
2424
auth_type: z.literal(ConnectionAuthType.OauthPrivate).default(ConnectionAuthType.OauthPrivate),
2525
});
2626

27-
export const googleIntegrationSchema = z.object({
28-
json: z.string().min(1, "Json Key is required"),
27+
export const googleOauthSchema = z.object({
28+
auth_scopes: z
29+
.literal(Integrations.gmail)
30+
.or(z.literal(Integrations.calendar))
31+
.or(z.literal(Integrations.forms))
32+
.or(z.literal(Integrations.sheets))
33+
.or(z.literal(Integrations.drive))
34+
.or(z.literal(Integrations.youtube)),
35+
auth_type: z.literal(ConnectionAuthType.Oauth).default(ConnectionAuthType.Oauth),
36+
});
37+
38+
export const googleJsonIntegrationSchema = z.object({
39+
json: z.string().min(1, "Json Key is required").optional(),
40+
auth_scopes: z
41+
.literal(Integrations.gmail)
42+
.or(z.literal(Integrations.sheets))
43+
.or(z.literal(Integrations.drive))
44+
.or(z.literal(Integrations.youtube)),
2945
auth_type: z.literal(ConnectionAuthType.JsonKey).default(ConnectionAuthType.JsonKey),
3046
});
3147

3248
export const googleCalendarIntegrationSchema = z.object({
33-
json: z.string().min(1, "Json Key is required"),
49+
json: z.string().min(1, "Json Key is required").optional(),
3450
cal_id: z.string().optional(),
35-
auth_type: z.literal(ConnectionAuthType.JsonKey).default(ConnectionAuthType.JsonKey),
51+
auth_scopes: z.literal(`google${Integrations.calendar}`).default(`google${Integrations.calendar}`),
52+
auth_type: z
53+
.literal(ConnectionAuthType.JsonKey)
54+
.or(z.literal(ConnectionAuthType.Oauth))
55+
.default(ConnectionAuthType.Oauth),
3656
});
3757

3858
export const googleFormsIntegrationSchema = z.object({
39-
json: z.string().min(1, "Json Key is required"),
59+
json: z.string().min(1, "Json Key is required").optional(),
4060
form_id: z.string().optional(),
41-
auth_type: z.literal(ConnectionAuthType.JsonKey).default(ConnectionAuthType.JsonKey),
61+
auth_scopes: z.literal(`google${Integrations.forms}`).default(`google${Integrations.forms}`),
62+
auth_type: z
63+
.literal(ConnectionAuthType.JsonKey)
64+
.or(z.literal(ConnectionAuthType.Oauth))
65+
.default(ConnectionAuthType.Oauth),
4266
});
4367

4468
export const connectionSchema = z.object({

src/validations/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export {
22
githubIntegrationSchema,
3-
googleIntegrationSchema,
3+
googleJsonIntegrationSchema,
44
connectionSchema,
55
slackIntegrationSchema,
66
slackPrivateAuthIntegrationSchema,
@@ -33,6 +33,7 @@ export {
3333
redditPrivateAuthIntegrationSchema,
3434
pipedriveIntegrationSchema,
3535
notionApiKeyIntegrationSchema,
36+
googleOauthSchema,
3637
} from "@validations/connection.schema";
3738
export { codeAssetsSchema } from "@validations/coseAndAssets.schema";
3839
export { validateManualRun } from "@validations/manualRun.schema";

0 commit comments

Comments
 (0)