sim
sim copied to clipboard
feat(permissions): extend hook to detect missing scopes to return those scopes for upgrade, update credential selector subblock
Summary
- extend hook to detect missing scopes to return those scopes for upgrade
- update credential selector subblock
Type of Change
- [x] New feature
Testing
Tested manually
Checklist
- [x] Code follows project style guidelines
- [x] Self-reviewed my changes
- [x] Tests added/updated and passing
- [x] No new warnings introduced
- [x] I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)
The latest updates on your projects. Learn more about Vercel for GitHub.
@greptile
Greptile Overview
Greptile Summary
Extended OAuth scope management to detect and prompt users to upgrade credentials when additional permissions are required, with UI improvements to clearly communicate missing scopes.
Key Changes
- Added
getMissingRequiredScopes()andneedsUpgradeForRequiredScopes()helper functions to detect when a credential lacks required OAuth scopes - Enhanced credential selector components to display an amber warning banner when additional permissions are needed, with an "Update access" button
- Updated
OAuthRequiredModalto highlight newly required scopes with a "New" badge - Improved scope parsing to handle both space and comma-separated scope strings in API response
- Changed
credentialIdvalidation from UUID-only to generic string (matching database schema whereaccount.idis text type) - Added
scopeHintsto OAuth provider configs for better service detection from scope lists - Removed unnecessary
gmail.readonlyscope from Gmail block configurations (keeping only required scopes per operation) - Expanded scope lists for Jira, Slack, and Reddit to match their current API requirements
Implementation Quality
The implementation is well-structured with proper separation of concerns. The new utility functions are reusable and the UI feedback is clear and user-friendly.
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- The changes are well-implemented, follow existing patterns, and improve the OAuth credential management UX. The credentialId validation change correctly aligns with the database schema. Scope detection logic is sound and the UI improvements provide clear user feedback.
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| apps/sim/hooks/use-oauth-scope-status.ts | 5/5 | Added utility functions to compute missing required scopes and determine if a credential needs an upgrade |
| apps/sim/lib/oauth/oauth.ts | 4/5 | Enhanced scope management with scopeHints for service detection, improved getServiceIdFromScopes logic, and added extensive scopes for Jira, Slack, and Reddit |
| apps/sim/app/api/auth/oauth/credentials/route.ts | 5/5 | Changed credentialId validation from UUID to generic string (min 1, max 255) and improved scope parsing to handle comma-separated values |
| apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel-new/components/editor/components/sub-block/components/credential-selector/credential-selector.tsx | 5/5 | Integrated missing scope detection to show warning banner when additional permissions required, passes canonical scopes and newScopes to OAuth modal |
Sequence Diagram
sequenceDiagram
participant User
participant CredentialSelector
participant Hook as getMissingRequiredScopes
participant CredentialsAPI
participant Modal as OAuthRequiredModal
participant OAuthProvider
User->>CredentialSelector: Select credential
CredentialSelector->>Hook: Check missing scopes
Hook-->>CredentialSelector: Return missing scopes list
alt Missing scopes found
CredentialSelector->>CredentialSelector: Show permissions banner
User->>CredentialSelector: Click Update button
CredentialSelector->>Modal: Open modal
Modal->>Modal: Display scope list
User->>Modal: Click Connect
Modal->>OAuthProvider: Initiate flow
OAuthProvider-->>CredentialsAPI: Send authorization
CredentialsAPI->>CredentialsAPI: Parse and evaluate scopes
CredentialsAPI-->>CredentialSelector: Updated credential data
CredentialSelector->>Hook: Recheck scopes
Hook-->>CredentialSelector: No missing scopes
CredentialSelector->>CredentialSelector: Hide banner
end