Skip to content

feat(enterprise): auto-join newly registered accounts to the default workspace#32308

Merged
wylswz merged 13 commits intomainfrom
feat/default-workspace
Mar 1, 2026
Merged

feat(enterprise): auto-join newly registered accounts to the default workspace#32308
wylswz merged 13 commits intomainfrom
feat/default-workspace

Conversation

@lin-snow
Copy link
Copy Markdown
Contributor

@lin-snow lin-snow commented Feb 13, 2026

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: 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.

  • Calls Enterprise Inner API POST /default-workspace/members with body { "account_id": "<uuid>" }
  • Executes only when ENTERPRISE_ENABLED=true
  • Runs synchronously in the registration/account-creation path, but remains best-effort (errors are swallowed and logged as warnings; signup/login continues)
  • Uses a small request timeout (1s) and treats non-2xx responses as failures
  • Validates account_id as UUID before sending the request
  • Does not change the user’s current workspace (no workspace switch side effects)
  • Integrated into new-account creation paths:
    • OAuth/SSO new user (RegisterService.register)
    • Email-code new user (AccountService.create_account_and_tenant)
  • Adds unit tests covering:
    • Enterprise service request/response handling (including invalid payloads / failures)
    • Registration call sites invoking the integration when enterprise is enabled

Screenshots

Before After
... ...

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods

Copilot AI review requested due to automatic review settings February 13, 2026 08:14
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Feb 13, 2026
@lin-snow lin-snow self-assigned this Feb 13, 2026
@dosubot dosubot Bot added the 💪 enhancement New feature or request label Feb 13, 2026
@lin-snow lin-snow removed the size:M This PR changes 30-99 lines, ignoring generated files. label Feb 13, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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

  • Enterprise Integration: This PR introduces an enterprise-only feature that automatically adds newly created accounts to the default workspace.
  • Best-Effort Integration: The integration is designed to be 'best-effort,' meaning it soft-fails on errors, logging warnings without blocking signup or login.
  • Integration Points: The feature is integrated into registration paths for both OAuth/SSO and email-code new users.

🧠 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
  • api/services/account_service.py
    • The create_account_and_tenant function was modified to include a call to try_join_default_workspace after tenant creation.
    • The register function was modified to include a call to try_join_default_workspace after account registration.
  • api/services/enterprise/enterprise_service.py
    • Added try_join_default_workspace function to encapsulate the logic for joining the default workspace.
    • Added DefaultWorkspaceJoinResult model to represent the result of joining the default workspace.
    • Added join_default_workspace class method to EnterpriseService to call the enterprise inner API to add an account to the default workspace.
Activity
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread api/services/enterprise/enterprise_service.py
Comment thread api/services/account_service.py Outdated
Comment thread api/services/account_service.py Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 a try_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.

Comment thread api/services/enterprise/enterprise_service.py Outdated
Comment thread api/services/enterprise/enterprise_service.py
Comment thread api/services/account_service.py Outdated
@lin-snow lin-snow requested a review from laipz8200 as a code owner February 13, 2026 08:27
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Feb 13, 2026
GareArc
GareArc previously approved these changes Feb 13, 2026
Copy link
Copy Markdown
Contributor

@GareArc GareArc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Feb 13, 2026
@lin-snow lin-snow requested review from Copilot and removed request for GarfieldDai February 13, 2026 08:53
@lin-snow lin-snow force-pushed the feat/default-workspace branch from addaa32 to d6abc7f Compare February 13, 2026 09:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread api/services/enterprise/enterprise_service.py
Comment thread api/services/account_service.py Outdated
Copy link
Copy Markdown
Contributor

@QuantumGhost QuantumGhost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest add some unit tests for the correspond changes to account_service.py

@lin-snow lin-snow force-pushed the feat/default-workspace branch from d6abc7f to c45b04a Compare February 14, 2026 04:15
Copilot AI review requested due to automatic review settings February 14, 2026 05:08
@lin-snow lin-snow force-pushed the feat/default-workspace branch from c45b04a to 6e8b049 Compare February 14, 2026 05:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread api/services/enterprise/enterprise_service.py
@lin-snow lin-snow requested review from Copilot and removed request for laipz8200 February 14, 2026 06:08
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 1, 2026

Pyrefly Diff

base → PR
2771c2771
<     --> services/account_service.py:1104:13
---
>     --> services/account_service.py:1110:13
2773c2773
< 1104 |             tenant.role = ta.role
---
> 1110 |             tenant.role = ta.role

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 1, 2026

Pyrefly Diff

base → PR
2771c2771
<     --> 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
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 1, 2026

Pyrefly Diff

base → PR
2771c2771
<     --> services/account_service.py:1104:13
---
>     --> services/account_service.py:1110:13
2773c2773
< 1104 |             tenant.role = ta.role
---
> 1110 |             tenant.role = ta.role

@lin-snow lin-snow requested a review from wylswz March 1, 2026 08:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

lin-snow added 12 commits March 1, 2026 16:25
…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.
@lin-snow lin-snow force-pushed the feat/default-workspace branch from f2fe1c9 to e5700bf Compare March 1, 2026 08:25
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 1, 2026

Pyrefly Diff

base → PR
2771c2771
<     --> 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
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 1, 2026

Pyrefly Diff

base → PR
2771c2771
<     --> services/account_service.py:1104:13
---
>     --> services/account_service.py:1110:13
2773c2773
< 1104 |             tenant.role = ta.role
---
> 1110 |             tenant.role = ta.role

Copilot AI review requested due to automatic review settings March 1, 2026 08:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 1, 2026

Pyrefly Diff

base → PR
2771c2771
<     --> 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
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 1, 2026

Pyrefly Diff

base → PR
2771c2771
<     --> services/account_service.py:1104:13
---
>     --> services/account_service.py:1110:13
2773c2773
< 1104 |             tenant.role = ta.role
---
> 1110 |             tenant.role = ta.role

@lin-snow lin-snow requested review from GareArc and removed request for GareArc March 1, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💪 enhancement New feature or request lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto-join newly registered accounts to the default workspace

5 participants