From f1080f060cacfff4ef03eb18eece2e1ef68c44fe Mon Sep 17 00:00:00 2001 From: ytqh Date: Thu, 3 Jul 2025 17:38:33 +0800 Subject: [PATCH] feat: Implement open email registration with conditional organization assignment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove email domain validation requirement from registration endpoint - Implement conditional organization assignment logic (auto-assign if domain match, else NULL) - Allow users to register with any email address without requiring organization match - Maintain backward compatibility for domain-matched emails (auto-assign to organization) - Remove unused OrganizationNotFoundError import and fix code style Key Changes: - Modified EmailCodeLoginApi to allow registration without organization assignment - Users with matching email domains are auto-assigned to organizations - Users without matching domains can register and use platform with organization_id=NULL - Prepared foundation for future organization invitation system 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- api/controllers/service_api_with_auth/auth/login.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/api/controllers/service_api_with_auth/auth/login.py b/api/controllers/service_api_with_auth/auth/login.py index d637d1007f..87ce9a3fc4 100644 --- a/api/controllers/service_api_with_auth/auth/login.py +++ b/api/controllers/service_api_with_auth/auth/login.py @@ -12,7 +12,6 @@ from controllers.service_api_with_auth.error import ( AccountInFreezeError, EmailSendIpLimitError, OrganizationMismatchError, - OrganizationNotFoundError, TenantNotFoundError, ) from libs.helper import email, extract_remote_ip @@ -196,9 +195,6 @@ class EmailCodeLoginApi(Resource): # Find organization based on email domain organization = OrganizationService.find_organization_by_email_domain(user_email, tenant.id) - if organization is None: - raise OrganizationNotFoundError() - is_new_user = account is None if account is None: @@ -211,11 +207,14 @@ class EmailCodeLoginApi(Resource): interface_language=languages[0], ) - OrganizationService.assign_account_to_organization(account, organization.id) + # Assign to organization if domain match found, otherwise leave organization_id as NULL + if organization is not None: + OrganizationService.assign_account_to_organization(account, organization.id) else: - if account.current_organization_id is not None and account.current_organization_id != organization.id: + if (organization is not None and account.current_organization_id is not None + and account.current_organization_id != organization.id): raise OrganizationMismatchError() connected_tenant = TenantService.get_join_tenants(account)