Fix Google API Availability and a edge case#18150
Conversation
Greptile SummaryFixes Google API availability detection to handle edge case where Google returns generic "Precondition check failed." error instead of specific "service not enabled" message. Adds validation to prevent connection when user has access to neither Gmail nor Calendar. Changes:
Key improvement: Users now get clear error message directing them to contact workspace administrator instead of silently failing or showing confusing error states. Confidence Score: 4/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[User connects Google account] --> B[Check scopes validity]
B -->|Invalid scopes| C[Throw INSUFFICIENT_SCOPES]
B -->|Valid scopes| D[Check Gmail & Calendar availability]
D --> E[checkMessagingAvailability]
D --> F[checkCalendarAvailability]
E -->|API Call| G{Gmail API Response}
F -->|API Call| H{Calendar API Response}
G -->|Success| I[isMessagingAvailable = true]
G -->|Service not enabled| J[isMessagingAvailable = false]
G -->|Precondition check failed| J
G -->|Other error| K[Throw error]
H -->|Success| L[isCalendarAvailable = true]
H -->|Service not enabled| M[isCalendarAvailable = false]
H -->|Precondition check failed| M
H -->|Other error| N[Throw error]
I --> O{Both unavailable?}
J --> O
L --> O
M --> O
K --> P[Error thrown]
N --> P
O -->|Yes| Q[Throw INSUFFICIENT_SCOPES with workspace admin message]
O -->|No| R[Create/update connected account]
R --> S[Set up available channels]
Last reviewed commit: 1b4e49c |
...nty-server/src/engine/core-modules/auth/services/google-apis-service-availability.service.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/twenty-server/src/engine/core-modules/auth/services/google-apis-service-availability.service.ts">
<violation number="1" location="packages/twenty-server/src/engine/core-modules/auth/services/google-apis-service-availability.service.ts:136">
P2: The message is lowercased before the contains check, but the search string is capitalized. This makes the precondition check detection always false. Use a lowercase search string to match the normalized text.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
...nty-server/src/engine/core-modules/auth/services/google-apis-service-availability.service.ts
Outdated
Show resolved
Hide resolved
...nty-server/src/engine/core-modules/auth/services/google-apis-service-availability.service.ts
Outdated
Show resolved
Hide resolved
|
🚀 Preview Environment Ready! Your preview environment is available at: http://bore.pub:35981 This environment will automatically shut down when the PR is closed or after 5 hours. |
…oogle-apis-service-availability.service.ts Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
|
Thanks @neo773 for your contribution! |

First run shows a real customer account, and the second run is my account with all the permissions.
Simulated edge case if user has access to neither