feat: implement organization-based billing and user management#66
Conversation
- Added new billing-related models and routers for managing invoices, customers, and subscriptions. - Enhanced the billing system with Stripe integration, including new environment variables for Stripe keys. - Refactored existing billing logic to support a payment-first provisioning model. - Updated user management API endpoints to utilize consistent database session handling and improved organization. - Introduced new tests for billing functionalities and user profile management, ensuring comprehensive coverage of recent changes.
|
@claude please review this PR |
|
Claude finished @jfrench9's task —— View job PR Review Complete ✅I've completed a comprehensive review of this organization-based billing implementation. This is a significant architectural change with 100 files modified. Here's my detailed feedback: Critical Issues 🚨1. Data Migration Risk:
|
There was a problem hiding this comment.
💡 Codex Review
robosystems/robosystems/middleware/billing/enforcement.py
Lines 14 to 32 in 56964fc
After moving billing customers to be keyed by organization, check_can_provision_graph still calls BillingCustomer.get_or_create(user_id, session) with the caller’s user id. The model now declares org_id as the foreign key, so this call attempts to create a billing customer row for a non‑existent org and will raise an integrity error (or associate provisioning decisions with an invalid org) as soon as a user without a matching org id invokes the middleware. To enforce org‑level limits correctly, the function needs to resolve the user’s organization and pass the org id into get_or_create.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Added new environment variables for organization graph features in `.env.example`, including `ORG_GRAPHS_DEFAULT_LIMIT` and `ORG_MEMBER_INVITATIONS_ENABLED`. - Updated the `justfile` to rename the `test-code-quality` task to `test-code` for clarity. - Modified the `tasks.json` in VSCode to reflect the updated task name. - Implemented logic in `env.py` to handle the new `ORG_MEMBER_INVITATIONS_ENABLED` variable. - Added security event logging for missing and invalid Stripe webhook signatures in `webhooks.py`. - Updated the `invite_member` endpoint in `members.py` to include feature toggles and detailed TODOs for future implementation of member invitations.
- Updated the `check_can_provision_graph` function to retrieve the user's organization and check billing at the organization level. - Enhanced the `AuthResponse` model to include organization information upon user registration. - Renamed the `create_phantom_org_for_user` method to `create_personal_org_for_user` and updated its documentation to clarify the organization creation process during user registration. - Improved error handling and logging in the Stripe webhook processing functions to ensure better traceability and rollback capabilities. - Updated the registration endpoint documentation to reflect the automatic creation of a personal organization for new users.
|
@claude can you review the latest changes? A graph may not have an org id because a shared repository is not owned by an org |
|
Claude finished @jfrench9's task —— View job Updated Review - Latest Changes ✅I've reviewed the latest commits (51622ed, 18e92e7, 56964fc) addressing several critical issues from my previous review. Great progress! Summary of Changes Since Last ReviewThe latest commit (51622ed) made significant improvements:
Re-evaluation: Nullable
|
- Replaced `secrets.token_urlsafe` with `generate_prefixed_ulid` for consistent and time-ordered ID generation across billing and IAM models. - Updated the `Org` model to include soft-delete functionality, allowing organizations to be marked as deleted without data loss. - Enhanced the `get_by_id` and `get_all` methods to support optional inclusion of soft-deleted organizations. - Added documentation for new methods and improved existing docstrings for clarity.
- Introduced a new `deleted_at` column in the billing subscriptions invoices table to support soft-delete functionality. - Replaced default ID generation methods with `generate_prefixed_ulid` across various IAM models for consistent and time-ordered ID generation. - Updated the `id` fields in `GraphCredits`, `GraphFile`, `GraphSchema`, `GraphTable`, `GraphUsage`, and `UserRepositoryCredits` models to utilize the new ID generation method.
- Updated the `get_by_email` method to normalize input emails for direct indexed lookups, improving query performance. - Ensured that user emails are stored in lowercase during creation and updated through the `create` and `update` methods, maintaining consistency across the application. - Enhanced docstring for `get_by_email` to clarify email normalization process.
…nd functionality - Added demo scripts for SEC and accounting processes to the justfile for better usability. - Updated linting commands in the justfile to use a more flexible syntax. - Removed the `flower` dependency from `pyproject.toml` and `uv.lock` to streamline development tools. - Adjusted VSCode tasks to align with the updated linting command structure. - Enhanced test descriptions for clarity and improved consistency in ID generation tests.
Summary
This PR implements a comprehensive organization-based billing and user management system, transitioning from individual user billing to organization-level billing structures. The changes introduce multi-tenant capabilities with proper organization hierarchy and billing controls.
Key Accomplishments
🏢 Organization Management
💳 Billing System Overhaul
🔄 Data Model Migration
user_graph→graph_usergraph_usage_tracking→graph_usagetier_config→graph_tier🛡️ Access Control Updates
📊 Usage & Analytics
Breaking Changes
Testing Notes
Infrastructure Considerations
🤖 Generated with Claude Code
Branch Info:
feature/org-billingmainCo-Authored-By: Claude noreply@anthropic.com