Skip to content

Merge test to main - #124

Merged
sweetmantech merged 2 commits into
mainfrom
test
Jan 16, 2026
Merged

Merge test to main#124
sweetmantech merged 2 commits into
mainfrom
test

Conversation

@sweetmantech

@sweetmantechsweetmantech commented Jan 16, 2026

Copy link
Copy Markdown
Contributor

Merge test branch changes to main

Summary by CodeRabbit

  • New Features
    • Added optional organization ID parameter to chat requests for enhanced multi-organization support
    • Implemented access validation to ensure users can only submit chat requests for organizations they belong to, returning an error if access is denied

✏️ Tip: You can customize this high-level summary in your review settings.

sweetmantechand others added 2 commits January 15, 2026 20:52
- Add organizationId field to chatRequestSchema
- Create validateOrganizationAccess function to check if an account
can operate on behalf of an organization (either IS the org or is a member)
- Validate organizationId in validateChatRequest and use it to override
orgId when user is authorized
- Return 403 error when user is not a member of the specified org
- Add comprehensive tests for all scenarios
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…-apichat-accept-organizationid-with-auth-validation
feat(api): accept organizationId in chat requests with auth validation
@vercel

vercelBot commented Jan 16, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentReviewUpdated (UTC)
recoup-apiBuildingBuildingPreviewJan 16, 2026 1:58am

@sweetmantech
sweetmantech merged commit 88ecb4d into mainJan 16, 2026
1 of 3 checks passed
@coderabbitai

coderabbitaiBot commented Jan 16, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

A new organization access validation module is introduced to verify that accounts have access to specified organizations. This validation is integrated into chat request handling via an optional organizationId parameter, with comprehensive test coverage added across validation and chat test suites.

Changes

Cohort / File(s)Summary
Organization Access Validation Module
lib/organizations/validateOrganizationAccess.ts
New module exporting ValidateOrganizationAccessParams interface and validateOrganizationAccess() async function that validates account membership via direct ownership check or getAccountOrganizations() query.
Organization Access Validation Tests
lib/organizations/__tests__/validateOrganizationAccess.test.ts
Unit test suite covering ownership validation, membership checks via mocked getAccountOrganizations, and input validation edge cases (empty IDs).
Chat Request Validation
lib/chat/validateChatRequest.ts
Adds optional organizationId to request schema; imports and invokes validateOrganizationAccess to verify access, returning 403 on denial or setting orgId on success.
Chat Validation Tests
lib/chat/__tests__/validateChatRequest.test.ts
Introduces organizationId override test group validating schema acceptance, member verification for bearer token and API key auth, override behavior, rejection for non-members, and fallback scenarios.
Chat Handler Test Mocks
lib/chat/__tests__/handleChatGenerate.test.ts, lib/chat/__tests__/handleChatStream.test.ts, lib/chat/__tests__/integration/chatEndToEnd.test.ts
Each adds mock for validateOrganizationAccess to test scaffolding for organization access control.

Sequence Diagram

sequenceDiagram
participant Client
participant ValidateChatRequest as Chat Request Validator
participant ValidateOrgAccess as Organization Access Validator
participant Database as Membership DB
Client->>ValidateChatRequest: POST chat request (with organizationId)
activate ValidateChatRequest
ValidateChatRequest->>ValidateOrgAccess: validateOrganizationAccess(accountId, organizationId)
activate ValidateOrgAccess
alt Direct Ownership
ValidateOrgAccess->>ValidateOrgAccess: Check if accountId equals organizationId
ValidateOrgAccess-->>ValidateChatRequest: return true
else Membership Check
ValidateOrgAccess->>Database: getAccountOrganizations(accountId, organizationId)
activate Database
Database-->>ValidateOrgAccess: return memberships array
deactivate Database
ValidateOrgAccess->>ValidateOrgAccess: Check if non-empty
ValidateOrgAccess-->>ValidateChatRequest: return boolean
end
deactivate ValidateOrgAccess
alt Access Granted
ValidateChatRequest->>ValidateChatRequest: Set orgId to organizationId
ValidateChatRequest-->>Client: Continue chat validation
else Access Denied
ValidateChatRequest-->>Client: 403 Forbidden
end
deactivate ValidateChatRequest
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through org gates with care,
Checking if your access is truly there,
No shortcuts taken, each member verified,
Chat flows safely, properly authorized!
Hop-hop-validate, that's the way!

✨ Finishing touches
  • 📝 Generate docstrings


📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 15f29a1 and abe9c7f.

📒 Files selected for processing (7)
  • lib/chat/__tests__/handleChatGenerate.test.ts
  • lib/chat/__tests__/handleChatStream.test.ts
  • lib/chat/__tests__/integration/chatEndToEnd.test.ts
  • lib/chat/__tests__/validateChatRequest.test.ts
  • lib/chat/validateChatRequest.ts
  • lib/organizations/__tests__/validateOrganizationAccess.test.ts
  • lib/organizations/validateOrganizationAccess.ts

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@sweetmantech