Conversation
* feat: restrict account_id in GET /api/chats to ORG/RECOUP keys - Make account_id query parameter optional in /api/chats - Personal API keys can no longer specify account_id (403 error) - Org keys can only filter by account_id for org members - Recoup admin keys can filter by any account_id - Personal keys: Returns only their own chats - Org keys: Returns all org member chats - Recoup admin: Returns all chats Uses snake_case naming (account_id, artist_id, org_id) to match API docs. This matches the authorization pattern used in /api/pulses. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: org key without account_id now returns all org member chats The rooms table has no FK from account_id to accounts, so the join approach was silently returning empty results. Changed to fetch org member account IDs via getAccountOrganizations first, then filter rooms. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughThis PR refactors chat retrieval request handling by introducing comprehensive request validation and authorization logic supporting three key types (personal, organization, and Recoup admin). It replaces direct query validation with a layered approach that validates authentication, checks organizational membership, and builds appropriate database query parameters using an updated Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Handler as getChatsHandler
participant ValidateReq as validateGetChatsRequest
participant BuildParams as buildGetChatsParams
participant Auth as validateAuthContext
participant OrgService as getAccountOrganizations
participant DB as selectRooms
Client->>Handler: GET /api/chats?account_id=...
Handler->>ValidateReq: validateGetChatsRequest(request)
ValidateReq->>Auth: validateAuthContext(request)
Auth-->>ValidateReq: {account_id, org_id, ...}
alt Personal Key (no org_id)
ValidateReq->>BuildParams: buildGetChatsParams({account_id, org_id: null, target_account_id})
BuildParams-->>ValidateReq: {params: {account_ids: [account_id]}, error: null}
else Organization Key
ValidateReq->>BuildParams: buildGetChatsParams({account_id, org_id, target_account_id})
BuildParams->>OrgService: getAccountOrganizations(org_id)
OrgService-->>BuildParams: [member_ids...]
BuildParams-->>ValidateReq: {params: {account_ids: [members]}, error: null}
else Recoup Admin Key
ValidateReq->>BuildParams: buildGetChatsParams({account_id, org_id: RECOUP_ORG_ID})
BuildParams-->>ValidateReq: {params: {artist_id}, error: null}
end
ValidateReq-->>Handler: SelectRoomsParams | NextResponse
Handler->>DB: selectRooms(params)
DB-->>Handler: Room[] | null
Handler-->>Client: JSON response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Braintrust eval reportCatalog Opportunity Analysis Evaluation (HEAD-1769701381)
Catalog Songs Count Evaluation (HEAD-1769701381)
First Week Album Sales Evaluation (HEAD-1769701381)
Memory & Storage Tools Evaluation (HEAD-1769701381)
Monthly Listeners Tracking Evaluation (HEAD-1769701381)
Search Web Tool Evaluation (HEAD-1769701381)
Social Scraping Evaluation (HEAD-1769701381)
Spotify Followers Evaluation (HEAD-1769701381)
Spotify Tools Evaluation (HEAD-1769701381)
TikTok Analytics Questions Evaluation (HEAD-1769701381)
|
Merge test branch into main after PR #171
Summary by CodeRabbit
Release Notes
Tests
New Features
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.