feat(enterprise): auto-join newly registered accounts to the default workspace#32308
feat(enterprise): auto-join newly registered accounts to the default workspace#32308
Conversation
Summary of ChangesHello @lin-snow, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request implements a new feature for enterprise users that automatically adds new accounts to the default workspace upon registration. This integration aims to streamline the user experience by ensuring new users are immediately part of the configured enterprise workspace. The implementation includes error handling to prevent failures from disrupting the signup process. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable feature for enterprise customers by automatically adding new users to a default workspace. A security audit confirmed no vulnerabilities of medium, high, or critical severity, noting secure coding practices such as input validation for account_id, secure data handling for API communication, and a 'soft-fail' resilience design. However, the primary concern is the absence of unit tests for the new logic, specifically for the new service calls and the enterprise_service.py itself, which is crucial for robustness and maintainability.
There was a problem hiding this comment.
Pull request overview
Adds an enterprise-only, best-effort hook during account creation/registration to ensure newly created accounts are added to the enterprise “default workspace” via the enterprise inner API.
Changes:
- Introduces
EnterpriseService.join_default_workspace()and atry_join_default_workspace()wrapper that soft-fails and logs. - Invokes
try_join_default_workspace()after successful account creation in both email-code and OAuth/SSO registration paths.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
api/services/enterprise/enterprise_service.py |
Adds the default-workspace join API call, result model, and best-effort wrapper with logging. |
api/services/account_service.py |
Calls the best-effort default-workspace join after account creation/commit in key registration flows. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
addaa32 to
d6abc7f
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
QuantumGhost
left a comment
There was a problem hiding this comment.
I suggest add some unit tests for the correspond changes to account_service.py
d6abc7f to
c45b04a
Compare
c45b04a to
6e8b049
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Pyrefly Diffbase → PR2771c2771
< --> services/account_service.py:1104:13
---
> --> services/account_service.py:1110:13
2773c2773
< 1104 | tenant.role = ta.role
---
> 1110 | tenant.role = ta.role
|
Pyrefly Diffbase → PR2771c2771
< --> services/account_service.py:1104:13
---
> --> services/account_service.py:1110:13
2773c2773
< 1104 | tenant.role = ta.role
---
> 1110 | tenant.role = ta.role
|
1 similar comment
Pyrefly Diffbase → PR2771c2771
< --> services/account_service.py:1104:13
---
> --> services/account_service.py:1110:13
2773c2773
< 1104 | tenant.role = ta.role
---
> 1110 | tenant.role = ta.role
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…e for enterprise users Added functionality to attempt adding accounts to the default workspace during account registration and creation processes. This includes a new method in the enterprise service to handle the workspace joining logic, ensuring it does not block user registration on failure.
…andling Implemented better error handling during account addition to the default workspace for enterprise users, ensuring smoother user registration experience even when workspace joining fails.
Enhanced the BaseRequest class to include optional timeout and raise_for_status parameters for improved request handling. Updated the EnterpriseService to utilize these new options during account addition to the default workspace, ensuring better control over request behavior. Additionally, modified unit tests to reflect these changes.
Updated the account and registration services to conditionally attempt joining the default workspace based on the ENTERPRISE_ENABLED configuration. Enhanced the enterprise service to enforce required fields in the response payload, ensuring robust error handling. Added unit tests to verify the behavior for both enabled and disabled enterprise scenarios.
Updated the BaseRequest class to conditionally include the timeout parameter when making requests with httpx. This change preserves the library's default timeout behavior by only passing the timeout argument when it is explicitly set, enhancing request management and flexibility.
…counts Refactored the account and registration services to utilize an asynchronous method for joining the default workspace during account creation. This change enhances performance by allowing the registration process to proceed without waiting for the workspace joining operation to complete. Updated unit tests to cover the new asynchronous behavior and ensure proper logging of any exceptions that occur during the process.
Implemented a shutdown hook to ensure proper cleanup of the module-level executor used for workspace joining. This includes a best-effort cleanup method that cancels queued tasks and waits for currently running tasks to complete, enhancing the reliability of the service during process termination. Updated error handling to log any issues encountered during shutdown.
Updated the account and registration services to use a synchronous method for joining the default workspace during account creation. This change simplifies the implementation by removing the asynchronous wrapper and related executor, while ensuring that the registration process remains efficient. Adjusted unit tests to reflect the updated method usage.
Updated the condition for checking if enterprise features are enabled by removing the redundant getattr call. This change streamlines the code and improves readability while maintaining the functionality of adding accounts to the default workspace for enterprise users.
Modified the workspace_id field to use Field with an alias for better clarity and updated the model configuration to enable population by name. These changes enhance the model's usability and maintainability.
Removed the redundant getattr call for checking enterprise feature enablement, simplifying the condition for adding accounts to the default workspace. This change enhances code readability while preserving existing functionality.
Implemented a model validator to ensure that the workspace_id is non-empty when the joined field is set to True. This change enhances data integrity by preventing invalid states in the DefaultWorkspaceJoinResult model. Added a corresponding unit test to verify this validation behavior.
f2fe1c9 to
e5700bf
Compare
Pyrefly Diffbase → PR2771c2771
< --> services/account_service.py:1104:13
---
> --> services/account_service.py:1110:13
2773c2773
< 1104 | tenant.role = ta.role
---
> 1110 | tenant.role = ta.role
|
1 similar comment
Pyrefly Diffbase → PR2771c2771
< --> services/account_service.py:1104:13
---
> --> services/account_service.py:1110:13
2773c2773
< 1104 | tenant.role = ta.role
---
> 1110 | tenant.role = ta.role
|
Pyrefly Diffbase → PR2771c2771
< --> services/account_service.py:1104:13
---
> --> services/account_service.py:1110:13
2773c2773
< 1104 | tenant.role = ta.role
---
> 1110 | tenant.role = ta.role
|
1 similar comment
Pyrefly Diffbase → PR2771c2771
< --> services/account_service.py:1104:13
---
> --> services/account_service.py:1110:13
2773c2773
< 1104 | tenant.role = ta.role
---
> 1110 | tenant.role = ta.role
|
Important
Fixes #<issue number>.Fixes #32307
Summary
This PR adds an enterprise-only, best-effort integration to ensure newly created accounts are members of the enterprise configured default workspace.
POST /default-workspace/memberswith body{ "account_id": "<uuid>" }ENTERPRISE_ENABLED=true1s) and treats non-2xx responses as failuresaccount_idas UUID before sending the requestRegisterService.register)AccountService.create_account_and_tenant)Screenshots
Checklist
make lintandmake type-check(backend) andcd web && npx lint-staged(frontend) to appease the lint gods